add docker build and publish step #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
name: Go | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
- name: Install ledger | ||
run: | | ||
sudo apt-get install -y ledger | ||
- name: Test | ||
run: go test -v ./... | ||
env: | ||
GITHUB_URL: ${{ secrets.GIT_URL }} | ||
GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }} | ||
- name: set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: build and publish image | ||
if: ${{ github.ref == 'refs/heads/master' }} | ||
env: | ||
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} | ||
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
GITHUB_SHA: ${{ github.sha}} | ||
GITHUB_REF: ${{ github.ref}} | ||
run: | | ||
Check failure on line 44 in .github/workflows/go.yml GitHub Actions / GoInvalid workflow file
|
||
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)" | ||
version=${ref}-${GITHUB_SHA:0:7}-$(date +%Y%m%dT%H:%M:%S) | ||
echo "GITHUB_REF=${GITHUB_REF}, GITHUB_SHA=${GITHUB_SHA}, GIT_BRANCH=${ref}" | ||
echo "version=${version}" | ||
echo ${DOCKER_HUB_TOKEN} | docker login -u ${DOCKER_HUB_TOKEN} --password-stdin | ||
docker buildx build --push \ | ||
--build-arg VERSION=${version} | ||
--platform linux/amd64,linux/arm/v7,linux/arm64 \ | ||
-t ${{DOCKER_HUB_USER}}/teledger:${ref} . |