From d1e9bd0ac4c27cd05d38c9c3d7be087d1d8a4c3c Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Wed, 25 Nov 2026 10:42:21 +0000 Subject: [PATCH] Refactor release handling for better tag determination --- .github/workflows/gradle-release.yml | 21 ++++++++++----------- .github/workflows/maven-release.yml | 22 +++++++++++----------- .github/workflows/sbt-release.yml | 11 +++-------- README.md | 3 --- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/.github/workflows/gradle-release.yml b/.github/workflows/gradle-release.yml index fa61a36..22c05c8 100644 --- a/.github/workflows/gradle-release.yml +++ b/.github/workflows/gradle-release.yml @@ -28,12 +28,6 @@ on: type: string default: '' - fetch_all_commits: - description: 'Whether to fetch all commits. Default: false' - required: false - type: boolean - default: false - secrets: SONATYPE_USERNAME: required: true @@ -66,7 +60,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: '${{ env.FINAL_REF }}' - fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} + fetch-depth: 0 persist-credentials: false fetch-tags: true @@ -124,11 +118,16 @@ jobs: - name: Create the GH Release run: | - # Fetch latest two tags sorted by creation date - TAGS=$(git tag --sort=-creatordate | head -n 2) + # Fetch latest two tags merged into the target ref sorted by creation date + TAGS=$(git tag --sort=-creatordate --merged "${FINAL_REF}" | head -n 2) LATEST_TAG=$(echo "$TAGS" | sed -n '1p') PREVIOUS_TAG=$(echo "$TAGS" | sed -n '2p') - echo "Creating release notes between ${LATEST_TAG} and ${PREVIOUS_TAG}" - gh release create --target "${FINAL_REF}" --generate-notes --notes-start-tag "${PREVIOUS_TAG}" "${LATEST_TAG}" + if [ -n "${PREVIOUS_TAG}" ]; then + echo "Creating release notes between ${LATEST_TAG} and ${PREVIOUS_TAG}" + gh release create --target "${FINAL_REF}" --generate-notes --notes-start-tag "${PREVIOUS_TAG}" "${LATEST_TAG}" + else + echo "Creating release notes for ${LATEST_TAG}" + gh release create --target "${FINAL_REF}" --generate-notes "${LATEST_TAG}" + fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index b622af7..5d3596b 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -27,11 +27,6 @@ on: # We'll manually push it later default: 'mvn -B -V release:prepare release:perform -DlocalCheckout=true -DpushChanges=false -DcompletionGoals="spotless:apply"' - fetch_all_commits: - description: 'Whether to fetch all commits. Default: false' - required: false - type: boolean - default: false quarkus_jib_image: description: 'Whether to perform a Quarkus JIB image build and push. Default: false' required: false @@ -78,13 +73,13 @@ jobs: env: # Logic: Use the user input if provided, otherwise fall back to the repo's default branch - FINAL_REF: ${{ github.event.inputs.ref_to_release || github.event.repository.default_branch }} + FINAL_REF: ${{ inputs.ref_to_release || github.event.repository.default_branch }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: '${{ env.FINAL_REF }}' - fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} + fetch-depth: 0 persist-credentials: false fetch-tags: true @@ -145,12 +140,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create the GH Release run: | - # Fetch latest two tags sorted by creation date - TAGS=$(git tag --sort=-creatordate --merged "$FINAL_REF" | head -n 2) + # Fetch latest two tags merged into the target ref sorted by creation date + TAGS=$(git tag --sort=-creatordate --merged "${FINAL_REF}" | head -n 2) LATEST_TAG=$(echo "$TAGS" | sed -n '1p') PREVIOUS_TAG=$(echo "$TAGS" | sed -n '2p') - echo "Creating release notes between ${LATEST_TAG} and ${PREVIOUS_TAG}" - gh release create --target "${FINAL_REF}" --generate-notes --notes-start-tag "${PREVIOUS_TAG}" "${LATEST_TAG}" + if [ -n "${PREVIOUS_TAG}" ]; then + echo "Creating release notes between ${LATEST_TAG} and ${PREVIOUS_TAG}" + gh release create --target "${FINAL_REF}" --generate-notes --notes-start-tag "${PREVIOUS_TAG}" "${LATEST_TAG}" + else + echo "Creating release notes for ${LATEST_TAG}" + gh release create --target "${FINAL_REF}" --generate-notes "${LATEST_TAG}" + fi env: # Use the standard GITHUB_TOKEN or a Custom PAT if pushing to other repos GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/sbt-release.yml b/.github/workflows/sbt-release.yml index bd15386..9e57670 100644 --- a/.github/workflows/sbt-release.yml +++ b/.github/workflows/sbt-release.yml @@ -50,12 +50,6 @@ on: "MRRC" at "https://maven.repository.redhat.com/ga/" ) - fetch_all_commits: - description: "Whether to fetch all commits. Default: false" - required: false - type: boolean - default: false - secrets: SONATYPE_USERNAME: required: true @@ -87,7 +81,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: "${{ env.FINAL_REF }}" - fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} + fetch-depth: 0 persist-credentials: false fetch-tags: true @@ -152,7 +146,8 @@ jobs: - name: Create the GH Release run: | - TAGS=$(git tag --sort=-creatordate | head -n 2) + # Fetch latest two tags merged into the target ref sorted by creation date + TAGS=$(git tag --sort=-creatordate --merged "${FINAL_REF}" | head -n 2) LATEST_TAG=$(echo "$TAGS" | sed -n '1p') PREVIOUS_TAG=$(echo "$TAGS" | sed -n '2p') if [ -n "${PREVIOUS_TAG}" ]; then diff --git a/README.md b/README.md index a88b097..598e577 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,6 @@ Releases <= v0.0.24 are compatible with `jboss-parent` <= v53. v0.0.25 upward re * ref_to_release (default: `''`) * java_version (default: `21`) * release_command (default `mvn -B -V release:prepare release:perform -DlocalCheckout=true -DpushChanges=false`) - * fetch_all_commits (default: `false`) * jboss_parent_override: This is used to override variables from the jboss-parent (default `-Dcentral.serverId=central-publisher -Dcentral.autoPublish=false -DreleaseProfile=central-release -DsignTag=false`) - **Permissions**: `contents: write` @@ -287,7 +286,6 @@ environment variables. The publish task must also be wired into the Gradle relea * `ref_to_release` (default: `''`): Branch or commit to release * `java_version` (default: `17`) * `release_args` (default: `release`) - * `fetch_all_commits` (default: `false`) - **Secrets**: `SONATYPE_USERNAME`, `SONATYPE_PASSWORD`, `GPG_PRIVATE_KEY`, `GPG_PASSPHRASE` - **Permissions**: `contents: write` @@ -388,7 +386,6 @@ in `version.sbt` (the file updated by `sbt-release`). * `additional_release_args` (default: `''`): Extra `sbt-release` arguments, e.g. `skip-tests` * `java_version` (default: `8`) * `resolvers` (default: same as `sbt-ci.yml`) - * `fetch_all_commits` (default: `false`) - **Secrets**: `SONATYPE_USERNAME`, `SONATYPE_PASSWORD`, `GPG_PRIVATE_KEY`, `GPG_PASSPHRASE` - **Permissions**: `contents: write`