Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- main
tags:
- v*.*.*
pull_request:
workflow_dispatch:

Expand Down
54 changes: 43 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,55 @@
name: Release

on:
push:
tags:
- v*.*.*
workflow_run:
workflows:
- "CI"
types:
- completed

jobs:
validate-tag:
name: Check tag
runs-on: ubuntu-latest
outputs:
valid_tag: ${{ steps.validation.outputs.valid_tag }}
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && startsWith(github.event.workflow_run.head_branch, 'v') }}
steps:
- name: Check out the repository including tags
uses: actions/checkout@v5
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
fetch-tags: true
- name: Validate tag
id: validation
run: |
# Validation is necessary in the unlikely case that a branch matching the tag naming pattern is pushed
# and the CI workflow in that branch is modified to run upon a push to that branch
REF='${{ github.event.workflow_run.head_branch }}' # This can be a branch or tag name
if [[ "$REF" != v*.*.* ]]; then
echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
fi
# Validate that the tag exists
if ! git rev-parse -q --verify "refs/tags/$REF" >/dev/null; then
echo "There is no tag matching $REF - $REF is a branch"
echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
fi
# Validate that the tag is for the same commit that was pushed
TAG_SHA="$(git rev-parse "$REF^{commit}")"
COMMIT_SHA="${{ github.event.workflow_run.head_sha }}"
if [ "$TAG_SHA" != "$COMMIT_SHA" ]; then
echo "Tag SHA $TAG_SHA does not match pushed commit SHA $COMMIT_SHA"
Copy link
Contributor Author

@lokst lokst Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested (in another repository) that this successfully guards against the following case:

  1. A branch with the same name as an existing valid tag is created
  2. The "CI" workflow in that branch is modified to run upon a push to the branch (thus causing the CI workflow to be triggered on pushes to the branch)
Screenshot 2025-08-21 at 2 16 23 PM

echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
fi
echo "Tag $REF exists and is valid. Tag $TAG_SHA matches the pushed commit $COMMIT_SHA."
echo "valid_tag=true" >> "$GITHUB_OUTPUT"
publish:
name: Publish Client
needs: validate-tag
runs-on: ubuntu-latest
if: ${{ needs.validate-tag.outputs.valid_tag == 'true' && github.event.workflow_run.conclusion == 'success' }}
Copy link
Contributor Author

@lokst lokst Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test showing that the job will be skipped if the condition is not met

(Conducted in another repository)

Screenshot 2025-08-21 at 2 21 34 PM

A test showing a successful job run

A valid tag is pushed:

Screenshot 2025-08-21 at 2 25 36 PM

The tag is successfully validated:

Screenshot 2025-08-21 at 2 29 13 PM

The publish job is run:

Screenshot 2025-08-21 at 2 26 26 PM

steps:
- name: Wait for tests to succeed
uses: lewagon/[email protected]
with:
ref: 'refs/heads/main'
running-workflow-name: 'Publish Client'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
allowed-conclusions: success
- name: Checkout Code
uses: actions/checkout@v5
- name: Set up JVM
Expand Down