Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/release-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Release Preview

on:
pull_request:
branches:
- main

env:
SEMANTIC_RELEASE_VERSION: '24.2.3'
NODE_VERSION: '20.11.0'

jobs:
preview:
name: Preview Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run semantic-release (dry-run)
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_COMMITTER_NAME: "github-actions[bot]"
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
GIT_AUTHOR_NAME: "github-actions[bot]"
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: |
# Unset GitHub Actions environment variables that interfere with semantic-release
unset GITHUB_REF
unset GITHUB_REF_NAME
unset GITHUB_HEAD_REF
unset GITHUB_BASE_REF

# Set them to what we want
export GITHUB_REF="refs/heads/${{ github.event.pull_request.head.ref }}"
export GITHUB_REF_NAME="${{ github.event.pull_request.head.ref }}"

# Run semantic-release with inline configuration using CLI options
# Add PR merge ref to allowed branches since GitHub Actions runs PRs on refs/pull/*/merge
OUTPUT=$(npx --package semantic-release@${{ env.SEMANTIC_RELEASE_VERSION }} \
--package @semantic-release/commit-analyzer \
--package @semantic-release/release-notes-generator \
--package @semantic-release/github \
semantic-release \
--dry-run \
--no-ci \
--debug \
--branches '${{ github.event.pull_request.head.ref }}' \
--branches 'refs/pull/${{ github.event.pull_request.number }}/merge' 2>&1 || true)
echo "$OUTPUT"

# Extract version information
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 "")
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 "")

# Extract release notes (everything after "Release note for version")
RELEASE_NOTES=$(echo "$OUTPUT" | sed -n '/Release note for version/,$p' | tail -n +2 || echo "")

# Save to outputs
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT

# Save release notes for comment
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Display Preview
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " RELEASE PREVIEW"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ -n "${{ steps.semantic.outputs.new_version }}" ]; then
echo "Version: v${{ steps.semantic.outputs.new_version }}"
echo "Release Type: ${{ steps.semantic.outputs.release_type }}"
echo "Status: Release will be published"
else
echo "Status: No release will be published"
echo "Reason: No relevant changes detected"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

- name: Comment on PR
if: github.event_name == 'pull_request'
uses: mshick/add-pr-comment@v2
with:
message-id: release-preview
message: |
## Release Preview

${{ steps.semantic.outputs.new_version && format('**Version:** `v{0}`
**Release Type:** `{1}`
**Status:** Release will be published when merged to main

---

### Release Notes
{2}
---

*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
**Reason:** No relevant changes detected

---

*This preview is generated by semantic-release dry-run mode*' }}
Loading