Create GitHub Release #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create GitHub Release | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate tag source | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TAG_NAME="${GITHUB_REF_NAME}" | |
| TAG_COMMIT="${GITHUB_SHA}" | |
| if [[ "${TAG_NAME}" =~ -(alpha|beta|rc) ]]; then | |
| echo "Pre-release tag detected: ${TAG_NAME}" | |
| if git merge-base --is-ancestor "${TAG_COMMIT}" origin/develop; then | |
| echo 'Tag commit is reachable from develop.' | |
| else | |
| echo 'Tag commit is NOT reachable from develop.' >&2 | |
| exit 1 | |
| fi | |
| else | |
| echo "Stable tag detected: ${TAG_NAME}" | |
| if git merge-base --is-ancestor "${TAG_COMMIT}" origin/main; then | |
| echo 'Tag commit is reachable from main.' | |
| else | |
| echo 'Tag commit is NOT reachable from main.' >&2 | |
| exit 1 | |
| fi | |
| fi | |
| - name: Create GitHub release | |
| shell: pwsh | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $tagName = $env:GITHUB_REF_NAME | |
| $versionName = $tagName.TrimStart('v') | |
| $notesPath = Join-Path -Path $env:RUNNER_TEMP -ChildPath 'release-notes.md' | |
| $changelog = Get-Content -Path (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'CHANGELOG.md') -Raw | |
| $escapedVersion = [regex]::Escape($versionName) | |
| $pattern = "(?ms)^##\s+.*?Version\s+$escapedVersion\s*$\r?\n(?<body>.*?)(?=^##\s+|\z)" | |
| $match = [regex]::Match($changelog, $pattern) | |
| if ($match.Success) { | |
| $notes = $match.Groups['body'].Value.Trim() | |
| Set-Content -Path $notesPath -Value $notes -Encoding UTF8 | |
| } | |
| $preReleaseFlag = @() | |
| if ($tagName -match '-(alpha|beta|rc)') { | |
| $preReleaseFlag = @('--prerelease') | |
| } | |
| if (gh release view $tagName *> $null) { | |
| gh release delete $tagName --yes | |
| } | |
| if ((Test-Path -Path $notesPath) -and -not [string]::IsNullOrWhiteSpace((Get-Content -Path $notesPath -Raw))) { | |
| gh release create $tagName @preReleaseFlag --title $tagName --notes-file $notesPath | |
| } else { | |
| gh release create $tagName @preReleaseFlag --title $tagName --generate-notes | |
| } |