Generated CLI #2725015085 (major) #5
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: Publish GitHub Release on PR Merge | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| publish-release: | |
| runs-on: ubuntu-latest | |
| if: >- | |
| github.event.pull_request.merged == true && | |
| startsWith(github.event.pull_request.head.ref, 'fireblocks-cli/generated/') | |
| steps: | |
| - name: Check for existing release | |
| id: existing | |
| env: | |
| # The gh commands below read both of these from the environment: GH_TOKEN for auth, | |
| # GH_REPO for which repo to act on. GH_REPO is required because this job has no | |
| # checkout, so gh has no git remote to infer it from, and gh ignores GITHUB_REPOSITORY. | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| marker="<!-- fireblocks-cli-generator:source-pr=${PR_NUMBER} -->" | |
| existing_url=$(gh release list --limit 20 --json tagName,url \ | |
| --jq '.[].tagName' | while read -r tag; do | |
| body=$(gh release view "$tag" --json body --jq '.body') | |
| if [[ "$body" == *"$marker"* ]]; then | |
| gh release view "$tag" --json url --jq '.url' | |
| break | |
| fi | |
| done) | |
| if [[ -n "$existing_url" ]]; then | |
| echo "Release for PR #${PR_NUMBER} was already published (found idempotency marker) - skipping." | |
| echo "Existing release: $existing_url" | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Calculate next version | |
| id: version | |
| if: steps.existing.outputs.skip == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| LAST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName') | |
| if [[ -z "$LAST_TAG" || "$LAST_TAG" == "null" ]]; then | |
| echo "ERROR: No existing release found. A release tag is required to calculate the next version." | |
| exit 1 | |
| fi | |
| echo "Found latest release: $LAST_TAG" | |
| V="${LAST_TAG#v}" | |
| MAJOR=$(echo "$V" | cut -d. -f1) | |
| MINOR=$(echo "$V" | cut -d. -f2) | |
| PATCH=$(echo "$V" | cut -d. -f3) | |
| if [[ "$PR_TITLE" =~ \(major\) ]]; then | |
| echo "Bumping MAJOR version" | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| elif [[ "$PR_TITLE" =~ \(minor\) ]]; then | |
| echo "Bumping MINOR version" | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| else | |
| echo "Bumping PATCH version" | |
| PATCH=$((PATCH + 1)) | |
| fi | |
| echo "version=v${MAJOR}.${MINOR}.${PATCH}" >> "$GITHUB_OUTPUT" | |
| - name: Create published release | |
| if: steps.existing.outputs.skip == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| PR_BODY: ${{ github.event.pull_request.body }} | |
| MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| marker="<!-- fireblocks-cli-generator:source-pr=${PR_NUMBER} -->" | |
| notes=$(printf '%s\n\n%s' "$PR_BODY" "$marker") | |
| echo "Creating published release: $VERSION (target: $MERGE_SHA)" | |
| gh release create "$VERSION" \ | |
| --target "$MERGE_SHA" \ | |
| --title "$VERSION" \ | |
| --notes "$notes" | |
| echo "Published release created successfully!" |