|
| 1 | +name: Tag the new Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +permissions: |
| 10 | + actions: write |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + tag_and_release: |
| 15 | + name: Tag and release |
| 16 | + if: | |
| 17 | + github.event.pull_request.merged == true |
| 18 | + && contains(github.event.pull_request.labels.*.name, 'type : release') |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 10 |
| 21 | + steps: |
| 22 | + - name: Extract release version from head branch |
| 23 | + id: extract_version |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + head_ref="${{ github.event.pull_request.head.ref }}" |
| 27 | + if [[ ! "$head_ref" =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then |
| 28 | + echo "Head ref '$head_ref' does not match release/X.Y.Z pattern" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + version="${BASH_REMATCH[1]}" |
| 32 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 33 | + echo "Extracted version: $version" |
| 34 | +
|
| 35 | + - name: Checkout main at merge commit |
| 36 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # actions/checkout@v6.0.2 |
| 37 | + with: |
| 38 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Ensure tag does not already exist |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + tag="${{ steps.extract_version.outputs.version }}" |
| 45 | + if git rev-parse "refs/tags/$tag" >/dev/null 2>&1; then |
| 46 | + echo "Tag $tag already exists — refusing to overwrite" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Create and push tag |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + tag="${{ steps.extract_version.outputs.version }}" |
| 54 | + git config --local user.email "action@github.com" |
| 55 | + git config --local user.name "GitHub Action" |
| 56 | + git tag -a "$tag" -m "Release $tag" |
| 57 | + git push origin "$tag" |
| 58 | +
|
| 59 | + - name: Create GitHub Release |
| 60 | + env: |
| 61 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + tag="${{ steps.extract_version.outputs.version }}" |
| 65 | + gh release create "$tag" \ |
| 66 | + --target "${{ github.event.pull_request.merge_commit_sha }}" \ |
| 67 | + --title "$tag" \ |
| 68 | + --generate-notes |
0 commit comments