ci(release): split tag creation and release into separate workflows (#2614)
- Add `create-tag.yml`: creates annotated tag at a specified commit or latest main HEAD, with duplicate tag and commit validation - Simplify `release.yml`: only accepts existing tags, removes create_tag toggle, validates tag via GitHub API before checkout - Always checkout main branch (fetch-depth: 0 fetches full history), then create tag at the specified commit Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
279c496bb2
commit
023ca2e4c1
2 changed files with 72 additions and 24 deletions
60
.github/workflows/create-tag.yml
vendored
Normal file
60
.github/workflows/create-tag.yml
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
name: Create Tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: "Tag name (required, e.g. v0.2.0)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
commit:
|
||||||
|
description: "Target commit SHA (leave empty for latest main)"
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-tag:
|
||||||
|
name: Create Git Tag
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
ref: main
|
||||||
|
|
||||||
|
- name: Validate commit exists
|
||||||
|
if: ${{ inputs.commit != '' }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if ! git cat-file -t "${{ inputs.commit }}" &>/dev/null; then
|
||||||
|
echo "::error::Commit '${{ inputs.commit }}' does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check tag does not already exist
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
if gh api "repos/${{ github.repository }}/git/ref/tags/${{ inputs.tag }}" --silent 2>/dev/null; then
|
||||||
|
echo "::error::Tag '${{ inputs.tag }}' already exists."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create and push tag
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
TARGET="${{ inputs.commit || 'HEAD' }}"
|
||||||
|
COMMIT_SHA=$(git rev-parse "$TARGET")
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git tag -a "${{ inputs.tag }}" "$COMMIT_SHA" -m "Release ${{ inputs.tag }}"
|
||||||
|
git push origin "${{ inputs.tag }}"
|
||||||
|
echo "### Tag Created" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "- **Tag:** \`${{ inputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "- **Commit:** \`${COMMIT_SHA}\`" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "- **Branch:** \`$(git branch -r --contains "$COMMIT_SHA" | head -1 | xargs)\`" >> "$GITHUB_STEP_SUMMARY"
|
||||||
36
.github/workflows/release.yml
vendored
36
.github/workflows/release.yml
vendored
|
|
@ -1,10 +1,10 @@
|
||||||
name: Create Tag and Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tag:
|
tag:
|
||||||
description: "Release tag (required, e.g. v0.2.0)"
|
description: "Existing tag to release (e.g. v0.2.0)"
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
prerelease:
|
prerelease:
|
||||||
|
|
@ -24,35 +24,23 @@ on:
|
||||||
default: true
|
default: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
create-tag:
|
|
||||||
name: Create Git Tag
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Create and push tag
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
RELEASE_TAG: ${{ inputs.tag }}
|
|
||||||
run: |
|
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
git tag -a "$RELEASE_TAG" -m "Release $RELEASE_TAG"
|
|
||||||
git push origin "$RELEASE_TAG"
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
name: GoReleaser Release
|
name: GoReleaser Release
|
||||||
needs: create-tag
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
|
- name: Verify tag exists
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
if ! gh api "repos/${{ github.repository }}/git/ref/tags/${{ inputs.tag }}" --silent 2>/dev/null; then
|
||||||
|
echo "::error::Tag '${{ inputs.tag }}' does not exist. Create it first using the 'Create Tag' workflow."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Checkout tag
|
- name: Checkout tag
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue