Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: improve publish workflow #409

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ defaults:

concurrency:
# this expression gives us the name of the deployment environment. It works like a ternary operation (see https://github.com/actions/runner/issues/409#issuecomment-727565588)
group: ${{ !startsWith(github.ref, 'refs/tags/') && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
group: ${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
cancel-in-progress: true

jobs:
test:
uses: ./.github/workflows/run-tests.yml
if: startsWith(github.ref, 'refs/tags/')
if: github.ref_type == 'tag'

deploy:
needs: test
# !cancelled() is needed because if the whole workflow was cancelled, we don't want this job to run.
# (!startsWith(github.ref, 'refs/tags/') || needs.test.result == 'success') is needed because if `test` did run, we only want this to run if `test` succeeded.
if: (!cancelled() && (!startsWith(github.ref, 'refs/tags/') || needs.test.result == 'success'))
# (github.ref_type != 'tag' || needs.test.result == 'success') is needed because if `test` did run, we only want this to run if `test` succeeded.
if: (!cancelled() && (github.ref_type != 'tag' || needs.test.result == 'success'))
runs-on: ubuntu-latest
environment: ${{ !startsWith(github.ref, 'refs/tags/') && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
environment: ${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}

steps:
- name: Checkout
Expand Down Expand Up @@ -63,6 +63,9 @@ jobs:
- name: Write commit SHA to file
run: echo "${{ github.sha }}" >> static/sha.txt

- name: Write version to file
run: echo "${{ github.ref_name }}" >> static/version.txt

- name: Docker Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -85,6 +88,6 @@ jobs:
file: Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ !startsWith(github.ref, 'refs/tags/') && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
ghcr.io/${{ github.repository }}:${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:${{ github.sha }}
Loading