Create Release #7
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 Release | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| on: | |
| workflow_run: | |
| workflows: | |
| - SDK CI | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.workflow_run.head_branch }} | |
| cancel-in-progress: true | |
| jobs: | |
| release: | |
| if: | | |
| (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') || | |
| (github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'main') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.workflow_run.head_sha }} | |
| - name: Resolve release source | |
| id: source | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Read release version | |
| id: version | |
| run: | | |
| version="$(tr -d '[:space:]' < VERSION)" | |
| version="${version#v}" | |
| if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$'; then | |
| echo "VERSION must contain a semantic version like 1.2.3 or 1.2.3-beta.1" | |
| exit 1 | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "tag=v$version" >> "$GITHUB_OUTPUT" | |
| - name: Check whether the release already exists | |
| id: existing | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if gh release view "${{ steps.version.outputs.tag }}" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Check whether the tag already exists | |
| id: tag | |
| run: | | |
| if git ls-remote --exit-code --tags origin "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create and push version tag | |
| if: steps.tag.outputs.exists != 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag "${{ steps.version.outputs.tag }}" "${{ steps.source.outputs.sha }}" | |
| git push origin "refs/tags/${{ steps.version.outputs.tag }}" | |
| - name: Create GitHub release | |
| if: steps.existing.outputs.exists != 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| for attempt in 1 2 3; do | |
| if gh release create "${{ steps.version.outputs.tag }}" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "TPS ${{ steps.version.outputs.tag }}" \ | |
| --verify-tag \ | |
| --generate-notes; then | |
| exit 0 | |
| fi | |
| if [ "$attempt" -eq 3 ]; then | |
| echo "Failed to create GitHub release after $attempt attempts." | |
| exit 1 | |
| fi | |
| echo "Release creation failed on attempt $attempt. Retrying..." | |
| sleep 5 | |
| done |