|
| 1 | +name: Release Preview |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +env: |
| 7 | + SEMANTIC_RELEASE_VERSION: '24.2.0' |
| 8 | + NODE_VERSION: '20.11.0' |
| 9 | + |
| 10 | +jobs: |
| 11 | + preview: |
| 12 | + name: Preview Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + ref: ${{ github.event.pull_request.head.ref }} |
| 24 | + |
| 25 | + - name: Setup Node.js |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: ${{ env.NODE_VERSION }} |
| 29 | + |
| 30 | + - name: Run semantic-release (dry-run) |
| 31 | + id: semantic |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + GIT_COMMITTER_NAME: "github-actions[bot]" |
| 35 | + GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com" |
| 36 | + GIT_AUTHOR_NAME: "github-actions[bot]" |
| 37 | + GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com" |
| 38 | + run: | |
| 39 | + # Unset GitHub Actions environment variables that interfere with semantic-release |
| 40 | + unset GITHUB_REF |
| 41 | + unset GITHUB_REF_NAME |
| 42 | + unset GITHUB_HEAD_REF |
| 43 | + unset GITHUB_BASE_REF |
| 44 | +
|
| 45 | + # Set them to what we want |
| 46 | + export GITHUB_REF="refs/heads/${{ github.event.pull_request.head.ref }}" |
| 47 | + export GITHUB_REF_NAME="${{ github.event.pull_request.head.ref }}" |
| 48 | +
|
| 49 | + # Run semantic-release with inline configuration using CLI options |
| 50 | + OUTPUT=$(npx --package semantic-release@${{ env.SEMANTIC_RELEASE_VERSION }} \ |
| 51 | + --package @semantic-release/exec \ |
| 52 | + --package conventional-changelog-conventionalcommits \ |
| 53 | + semantic-release \ |
| 54 | + --dry-run \ |
| 55 | + --no-ci \ |
| 56 | + --debug \ |
| 57 | + --branches ${{ github.event.pull_request.head.ref }} 2>&1 || true) |
| 58 | + echo "$OUTPUT" |
| 59 | +
|
| 60 | + # Extract version information |
| 61 | + NEW_VERSION=$(echo "$OUTPUT" | grep -Eo "The next release version is [0-9]+\.[0-9]+\.[0-9]+" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" || echo "") |
| 62 | + RELEASE_TYPE=$(echo "$OUTPUT" | grep -Eo "Analysis of [0-9]+ commits complete: [a-z]+ release" | grep -Eo "(major|minor|patch) release" | sed 's/ release//' || echo "") |
| 63 | +
|
| 64 | + # Extract release notes (everything after "Release note for version") |
| 65 | + RELEASE_NOTES=$(echo "$OUTPUT" | sed -n '/Release note for version/,$p' | tail -n +2 || echo "") |
| 66 | +
|
| 67 | + # Save to outputs |
| 68 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 69 | + echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + # Save release notes for comment |
| 72 | + echo "release_notes<<EOF" >> $GITHUB_OUTPUT |
| 73 | + echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT |
| 74 | + echo "EOF" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + - name: Display Preview |
| 77 | + run: | |
| 78 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 79 | + echo " RELEASE PREVIEW" |
| 80 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 81 | + echo "" |
| 82 | + if [ -n "${{ steps.semantic.outputs.new_version }}" ]; then |
| 83 | + echo "Version: v${{ steps.semantic.outputs.new_version }}" |
| 84 | + echo "Release Type: ${{ steps.semantic.outputs.release_type }}" |
| 85 | + echo "Status: Release will be published" |
| 86 | + else |
| 87 | + echo "Status: No release will be published" |
| 88 | + echo "Reason: No relevant changes detected" |
| 89 | + fi |
| 90 | + echo "" |
| 91 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 92 | +
|
| 93 | + - name: Comment on PR |
| 94 | + if: github.event_name == 'pull_request' |
| 95 | + uses: mshick/add-pr-comment@v2 |
| 96 | + with: |
| 97 | + message-id: release-preview |
| 98 | + message: | |
| 99 | + ## Release Preview |
| 100 | +
|
| 101 | + ${{ steps.semantic.outputs.new_version && format('**Version:** `v{0}` |
| 102 | + **Release Type:** `{1}` |
| 103 | + **Status:** Release will be published when merged to main |
| 104 | +
|
| 105 | + --- |
| 106 | +
|
| 107 | + ### Release Notes |
| 108 | +
|
| 109 | + {2} |
| 110 | +
|
| 111 | + --- |
| 112 | +
|
| 113 | + *This preview is generated by semantic-release dry-run mode*', steps.semantic.outputs.new_version, steps.semantic.outputs.release_type, steps.semantic.outputs.release_notes) || '**Status:** No release will be published |
| 114 | + **Reason:** No relevant changes detected |
| 115 | +
|
| 116 | + --- |
| 117 | +
|
| 118 | + *This preview is generated by semantic-release dry-run mode*' }} |
0 commit comments