Skip to content

Commit

Permalink
Add github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonzoRicardo committed Sep 21, 2020
1 parent 850b0dd commit 3433ecd
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 20 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version:
- '0.17'
- '0.17/alpine'
- '0.15'
- '0.15/alpine'
fail-fast: false
steps:
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v1

- name: Checkout
uses: actions/checkout@v2

- name: Prepare Docker build
id: prepare
run: |
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
BITCOIN_GOLD_VERSION=${{matrix.version}}
LATEST_BITCOIN_GOLD_MAJOR_VERSION=$(ls | grep 0 | sort -n | tail -n 1)
PUSH=false
REPO=uphold/bitcoin-gold
TAGS=()
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
PUSH=true
if [[ ${BITCOIN_GOLD_VERSION} == *"alpine"* ]]; then
TAGS+=("$REPO:$TAG-alpine")
else
TAGS+=("$REPO:$TAG")
fi
TAG_MAJOR_MINOR=$(echo $TAG | cut -c -4)
if [ $(version ${TAG_MAJOR_MINOR}) -ne $(version ${BITCOIN_GOLD_VERSION}) ]; then
echo "Skipping build of base image $BITCOIN_GOLD_VERSION/ as ${TAG} is targeted at ${TAG_MAJOR_MINOR}/"
exit 0
fi
else
TAGS=("$REPO:${BITCOIN_GOLD_VERSION/\//-}")
if [ $(version ${BITCOIN_GOLD_VERSION}) -ge $(version ${LATEST_BITCOIN_GOLD_MAJOR_VERSION}) ]; then
echo "Version $(version ${BITCOIN_GOLD_VERSION}) is greater than or equal to $(version ${LATEST_BITCOIN_GOLD_MAJOR_VERSION}), tagging as latest"
if [[ ${BITCOIN_GOLD_VERSION} != *"alpine"* ]]; then
TAGS+=("$REPO:latest")
else
TAGS+=("$REPO:alpine")
fi
fi
if [ $GITHUB_REF == "refs/heads/master" ]; then
PUSH=true
fi
fi
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=push::${PUSH}
echo ::set-output name=tags::${TAGS[@]}
echo ::set-env name=build::true
- if: env.build == 'true'
name: Login into Docker Hub
env:
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
run: |
docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}
- if: env.build == 'true'
name: Build Docker image
run: |
TAGS=(${{ steps.prepare.outputs.tags }})
echo "Build date: ${{ steps.prepare.outputs.build_date }}"
echo "Push: ${{ steps.prepare.outputs.push }}"
echo "Tags: ${{ steps.prepare.outputs.tags }}"
echo docker buildx build \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/
docker buildx build \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/
- if: env.build == 'true'
name: Clear Docker credentials
run: |
rm -f ${HOME}/.docker/config.json
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

0 comments on commit 3433ecd

Please sign in to comment.