create_release_command #34
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 | |
| on: | |
| repository_dispatch: | |
| types: [create_release_command] | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| commit_hash: ${{ steps.extract.outputs.commit_hash }} | |
| release_type: ${{ steps.extract.outputs.release_type }} | |
| message: ${{ steps.extract.outputs.message || steps.approval.outputs.message }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v6 | |
| - name: Extract metadata and validate parameters | |
| id: extract | |
| run: | | |
| source .github/scripts/utils.sh | |
| ISSUE="${{ github.event.client_payload.github.payload.issue.number }}" | |
| REPO="${{ github.repository }}" | |
| cache_issue_json "$ISSUE" "$REPO" | |
| ISSUE_JSON=$(get_issue_json_path) | |
| RELEASE_CANDIDATE_COMMENTS=$(jq -r '.comments[].body | select(test("<!-- release-candidate:"))' "$ISSUE_JSON") | |
| COMMENT=$(echo "$RELEASE_CANDIDATE_COMMENTS" | tail -n 1) | |
| SHA=$(echo "$COMMENT" | grep -oE 'commit=([a-f0-9]{7,40})' | cut -d= -f2) | |
| STATUS=$(echo "$COMMENT" | grep -oE 'status=([a-z]+)' | cut -d= -f2) | |
| if [ -z "$SHA" ]; then | |
| set_output "message" "❌ **Release candidate commit not found in comments**" | |
| exit 1 | |
| fi | |
| if [ "$STATUS" != "success" ]; then | |
| set_output "message" "❌ **Last release candidate deployment did not succeed**" | |
| exit 1 | |
| fi | |
| RELEASE_TYPE="${{ github.event.client_payload.slash_command.args.named.type }}" | |
| echo "Parsed release type: $RELEASE_TYPE" | |
| if [[ "$RELEASE_TYPE" != "patch" && "$RELEASE_TYPE" != "minor" && "$RELEASE_TYPE" != "major" ]]; then | |
| set_output "message" "❌ **Invalid release type: ${RELEASE_TYPE:-N/A}**" | |
| exit 1 | |
| fi | |
| set_output "commit_hash" "$SHA" | |
| set_output "release_type" "$RELEASE_TYPE" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Require release approval | |
| id: approval | |
| run: | | |
| source .github/scripts/utils.sh | |
| ISSUE_JSON=$(get_issue_json_path) | |
| APPROVED=$(jq -r '.comments[].body | select(test("(?i)release approved"))' "$ISSUE_JSON") | |
| if [ -z "$APPROVED" ]; then | |
| set_output "message" "❌ **Release not approved. Aborting.**" | |
| exit 1 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| release: | |
| needs: validate | |
| uses: ./.github/workflows/release.yml | |
| with: | |
| commit_hash: ${{ needs.validate.outputs.commit_hash }} | |
| release_type: ${{ needs.validate.outputs.release_type }} | |
| secrets: | |
| APP_ID: ${{ secrets.APP_ID }} | |
| APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} | |
| comment: | |
| name: Comment on Release Result | |
| needs: [validate, release] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v6 | |
| - name: Compose result title | |
| id: title | |
| run: | | |
| source .github/scripts/utils.sh | |
| STATUS="${{ needs.release.result }}" | |
| if [ "$STATUS" = "success" ]; then | |
| set_output "title" "✅ **Release succeeded**" | |
| else | |
| set_output "title" "❌ **Release failed**" | |
| fi | |
| - name: Post release result comment | |
| uses: peter-evans/create-or-update-comment@v5 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ github.event.client_payload.github.payload.issue.number }} | |
| body: | | |
| ${{ steps.title.outputs.title }} | |
| ${{ needs.validate.outputs.message }} | |
| **Release Type**: `${{ needs.validate.outputs.release_type || 'N/A' }}` | |
| **Version**: `${{ needs.release.outputs.version || 'N/A' }}` | |
| **Notes**: [View GitHub Release Notes](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.release.outputs.version }}) | |
| **Commit Hash**: `${{ needs.validate.outputs.commit_hash || 'N/A' }}` | |
| **Run**: [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| label_issues: | |
| name: Label Issues With Release Tag | |
| needs: [release] | |
| if: needs.release.result == 'success' | |
| uses: ./.github/workflows/label_issues_on_release.yml | |
| with: | |
| release_tag: ${{ needs.release.outputs.version }} |