Copilot commented on code in PR #15742:
URL: https://github.com/apache/grails-core/pull/15742#discussion_r3431850143
##########
.github/workflows/release-notes.yml:
##########
@@ -81,6 +81,52 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
+ # Seed an initial version for release branches that have no published
+ # release yet (e.g. 7.2.x before its first tag). release-drafter falls
+ # back to its default 0.1.0 when it finds no "last release", which on
+ # such a branch produces a misleading v0.1.0 draft. We detect that case
+ # and pass the branch's own MAJOR.MINOR.0 as the `version` input so the
+ # draft reads e.g. v7.2.0 instead.
+ #
+ # This is self-correcting: the moment the branch publishes ANY release,
+ # the lookup below finds it and we stop seeding, letting release-drafter
+ # resolve the next version normally (e.g. 7.2.0 -> 7.2.1). Branches that
+ # already have a release (7.0.x, 7.1.x, 8.0.x) get an empty seed, which
+ # release-drafter treats as "no override" - identical to current
+ # behaviour. Best-effort: any lookup failure also yields an empty seed.
+ - name: "🔢 Seed initial version for release-less branches"
+ id: seed
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ set -uo pipefail
+ BRANCH="${{ github.event.pull_request.base.ref || github.ref_name }}"
+ if [[ ! "$BRANCH" =~ ^([0-9]+)\.([0-9]+)\.x$ ]]; then
+ echo "Branch $BRANCH is not a release branch; no version seed."
+ echo "version=" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ SEED="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.0"
+ # Mirror release-drafter's "last release" lookup: a non-draft release
+ # whose target_commitish (with refs/heads/ stripped, as the action
+ # does) equals this branch and whose tag starts with the "v" prefix.
+ # Prereleases count, matching include-pre-releases: true.
+ matches="$(gh api --paginate
"repos/${GITHUB_REPOSITORY}/releases?per_page=100" \
+ --jq ".[] | select(.draft == false) | select((.target_commitish |
sub(\"^refs/heads/\"; \"\")) == \"${BRANCH}\") | select(.tag_name |
startswith(\"v\")) | .tag_name" 2>/dev/null)"
+ if [[ $? -ne 0 ]]; then
+ echo "::warning title=Version seed skipped::Could not list
releases for ${BRANCH}; leaving version unset (release-drafter default)."
+ echo "version=" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
Review Comment:
`gh api` failures are intended to be best-effort (fall back to empty seed),
but on GitHub Actions the `bash` runner typically runs with `-e` enabled by
default. In that case a non-zero exit from `gh api` in the command substitution
will abort the step before the subsequent `$?` check executes, turning
transient API issues into a hard workflow failure.
Wrap the `gh api` call in an `if ! ...; then` so the error is handled even
under `errexit`, and drop the separate `$?` check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]