-
Notifications
You must be signed in to change notification settings - Fork 88
feat: auto-release on tracked upstream version bump #446
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
Open
fzipi
wants to merge
1
commit into
main
Choose a base branch
from
feat/auto-release-on-upstream-bump
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| name: Auto-release on upstream version bump | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - docker-bake.hcl | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| check-version-bump: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| outputs: | ||
| bumped: ${{ steps.check.outputs.bumped }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Check for tracked upstream version bump | ||
| id: check | ||
| run: | | ||
| set -euo pipefail | ||
| BEFORE="${{ github.event.before }}" | ||
| if [ -z "${BEFORE//0/}" ]; then | ||
| echo "No previous commit to diff against; skipping." | ||
| echo "bumped=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| version_of() { | ||
| git show "$1:docker-bake.hcl" | awk -v var="$2" ' | ||
| $0 ~ "variable \"" var "\"" { found=1 } | ||
| found && /default *=/ { print; exit } | ||
| ' | ||
| } | ||
|
|
||
| bumped=false | ||
| for var in modsec2-version modsec3-version httpd-version nginx-version; do | ||
| old=$(version_of "$BEFORE" "$var") | ||
| new=$(version_of "${{ github.sha }}" "$var") | ||
| if [ "$old" != "$new" ]; then | ||
| echo "Version bump detected for $var: $old -> $new" | ||
| bumped=true | ||
| fi | ||
| done | ||
| echo "bumped=$bumped" >> "$GITHUB_OUTPUT" | ||
|
|
||
| tag-and-release: | ||
| needs: check-version-bump | ||
| if: needs.check-version-bump.outputs.bumped == 'true' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # actions/checkout@v5 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Create release tag and GitHub release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -euo pipefail | ||
| base="release/$(date -u +%Y%m%d)" | ||
| tag="$base" | ||
| suffix=1 | ||
| while gh api "repos/${{ github.repository }}/git/ref/tags/$tag" >/dev/null 2>&1; do | ||
| tag="${base}-${suffix}" | ||
| suffix=$((suffix + 1)) | ||
| done | ||
|
|
||
| gh release create "$tag" \ | ||
| --target "${{ github.sha }}" \ | ||
| --title "$tag" \ | ||
| --generate-notes | ||
|
|
||
| publish: | ||
| needs: tag-and-release | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| id-token: write | ||
| uses: ./.github/workflows/publish.yml | ||
| secrets: | ||
| dockerhub_user: ${{ secrets.dockerhub_user }} | ||
| dockerhub_token: ${{ secrets.dockerhub_token }} | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Race window in tag-existence check; no run-level concurrency control.
Two pushes to
maintouchingdocker-bake.hclin quick succession can trigger overlapping workflow runs. Bothtag-and-releasejobs would independently loop-checkgit/ref/tags/$tag, and since the existence check and thegh release createcall aren't atomic, both could pass the check for the same$tagbefore either creates it, causing one run to fail with a duplicate-tag error. Additionally, since only thegh apiexit code is checked, a transient non-404 failure (auth hiccup, rate limit, network blip) would be indistinguishable from "tag not found" and cause the script to proceed as if the name were free.Add a workflow-level
concurrencygroup to serialize runs onmain.🔒 Suggested fix
on: push: branches: [main] paths: - docker-bake.hcl +concurrency: + group: auto-release-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + permissions: {}🤖 Prompt for AI Agents