Use dedicated workflow for publishing

This commit is contained in:
eikendev 2021-07-19 00:47:21 +02:00
parent 28dd32f248
commit c2425b239c
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
2 changed files with 33 additions and 20 deletions

View file

@ -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

31
.github/workflows/publish.yml vendored Normal file
View file

@ -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