From c2425b239c52de80a73167cffb7bcc1885a8f492 Mon Sep 17 00:00:00 2001 From: eikendev Date: Mon, 19 Jul 2021 00:47:21 +0200 Subject: [PATCH] Use dedicated workflow for publishing --- .github/workflows/main.yml | 22 ++-------------------- .github/workflows/publish.yml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da6ad6a..88131f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,8 @@ name: Main on: [push, pull_request] jobs: - test_build_publish: - name: Test, build, and publish + test_build: + name: Test and build runs-on: ubuntu-latest steps: - name: Checkout code @@ -17,21 +17,3 @@ jobs: run: make test - name: Build image run: make build_image - - name: Get Branch # Needed to evaluate env.BRANCH. - if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name == 'push' }} # Otherwise will fail on pull requests. - run: | - echo "Getting branch name..." - raw=$(git branch -r --contains ${{ github.ref }}) - echo "raw: $raw" - branch=${raw##*/} - echo "branch: $branch" - echo "BRANCH=$branch" >> $GITHUB_ENV - - name: Login to Docker Hub - if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name == 'push' && env.BRANCH == 'master' }} # Only login for tagged commits pushed to master. - uses: docker/login-action@v1 - with: # Secrets are not exposed to pull request contexts. - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Publish image - if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name == 'push' && env.BRANCH == 'master' }} # Only publish for tagged commits pushed to master. - run: make push_image diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..46d173d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,31 @@ +name: Publish +on: + push: + branches: + - master +jobs: + test_build_publish: + name: Test, build, and publish + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Export GOBIN + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Install dependencies + run: make setup + - name: Run tests + run: make test + - name: Build image + run: make build_image + - name: Login to Docker Hub + if: ${{ startsWith(github.ref, 'refs/tags/v') }} # Only login for tagged commits. + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Publish image + if: ${{ startsWith(github.ref, 'refs/tags/v') }} # Only publish for tagged commits. + run: make push_image