|
| 1 | +name: Tag and Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version tag (e.g., v1.0.0)' |
| 8 | + required: true |
| 9 | + target_branch: |
| 10 | + description: 'Branch to tag (e.g., release)' |
| 11 | + default: release |
| 12 | + required: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + tag_and_release: |
| 16 | + name: Tag and Release |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 22 | + |
| 23 | + - name: Check if tag already exists |
| 24 | + id: check_tag |
| 25 | + run: | |
| 26 | + if git rev-parse "refs/tags/${{ github.event.inputs.version }}" >/dev/null 2>&1; then |
| 27 | + echo "Tag already exists" |
| 28 | + echo "tag_exists=true" >> "$GITHUB_OUTPUT" |
| 29 | + fi |
| 30 | +
|
| 31 | + - name: Abort if tag exists |
| 32 | + if: steps.check_tag.outputs.tag_exists == 'true' |
| 33 | + run: exit 1 |
| 34 | + |
| 35 | + - name: Create and push tag |
| 36 | + run: | |
| 37 | + git config user.name "github-actions[bot]" |
| 38 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 39 | + git fetch origin ${{ github.event.inputs.target_branch }} |
| 40 | + git checkout ${{ github.event.inputs.target_branch }} |
| 41 | + git tag ${{ github.event.inputs.version }} |
| 42 | + git push origin ${{ github.event.inputs.version }} |
| 43 | +
|
| 44 | + - name: Create GitHub Release |
| 45 | + uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0 |
| 46 | + with: |
| 47 | + tag: ${{ github.event.inputs.version }} |
| 48 | + name: ${{ github.event.inputs.version }} |
| 49 | + body: "Automated release of version ${{ github.event.inputs.version }}" |
| 50 | + draft: false |
| 51 | + prerelease: false |
| 52 | + generateReleaseNotes: true |
| 53 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments