@@ -3,6 +3,10 @@ name: Release Preview
33on :
44 workflow_call :
55
6+ env :
7+ SEMANTIC_RELEASE_VERSION : ' 24.2.0'
8+ NODE_VERSION : ' 20.11.0'
9+
610jobs :
711 preview :
812 name : Preview Release
@@ -18,21 +22,10 @@ jobs:
1822 fetch-depth : 0
1923 ref : ${{ github.event.pull_request.head.ref }}
2024
21- - name : Setup branch for semantic-release
22- run : |
23- # Explicitly checkout to the PR branch by name
24- git checkout -B ${{ github.event.pull_request.head.ref }}
25-
2625 - name : Setup Node.js
2726 uses : actions/setup-node@v4
2827 with :
29- node-version : ' lts/*'
30-
31- - name : Setup preview config
32- run : |
33- # Update preview config with the PR branch name
34- sed -i.bak "s|BRANCH_PLACEHOLDER|${{ github.event.pull_request.head.ref }}|g" .preview-releaserc.json
35- rm .preview-releaserc.json.bak
28+ node-version : ${{ env.NODE_VERSION }}
3629
3730 - name : Run semantic-release (dry-run)
3831 id : semantic
@@ -53,18 +46,17 @@ jobs:
5346 export GITHUB_REF="refs/heads/${{ github.event.pull_request.head.ref }}"
5447 export GITHUB_REF_NAME="${{ github.event.pull_request.head.ref }}"
5548
56- # Temporarily use preview config
57- mv .releaserc.json .releaserc.json.main
58- cp .preview-releaserc.json .releaserc.json
59-
60- # Run semantic-release with inline package installation (same as your local command)
61- OUTPUT=$(npx --package semantic-release --package @semantic-release/exec --package conventional-changelog-conventionalcommits semantic-release 2>&1 || true)
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)
6258 echo "$OUTPUT"
6359
64- # Restore original config
65- rm .releaserc.json
66- mv .releaserc.json.main .releaserc.json
67-
6860 # Extract version information
6961 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 "")
7062 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 "")
@@ -100,78 +92,27 @@ jobs:
10092
10193 - name : Comment on PR
10294 if : github.event_name == 'pull_request'
103- uses : actions/github-script@v7
95+ uses : mshick/add-pr-comment@v2
10496 with :
105- script : |
106- const newVersion = '${{ steps.semantic.outputs.new_version }}';
107- const releaseType = '${{ steps.semantic.outputs.release_type }}';
97+ message-id : release-preview
98+ message : |
99+ ## Release Preview
108100
109- const releaseNotes = `${{ steps.semantic.outputs.release_notes }}`;
110-
111- let body;
112- if (newVersion) {
113- body = `## Release Preview
114-
115- **Version:** \`v${newVersion}\`
116- **Release Type:** \`${releaseType}\`
101+ ${{ steps.semantic.outputs.new_version && format('**Version:** `v{0}`
102+ **Release Type:** `{1}`
117103 **Status:** Release will be published when merged to main
118104
119105 ---
120106
121- ### Release Notes
107+ ### Release Notes
122108
123- ${releaseNotes }
109+ {2 }
124110
125111 ---
126112
127- *This preview is generated by semantic-release dry-run mode*`;
128- }
129- else {
130- body = `## Release Preview
131-
132- **Status:** No release will be published
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
133114 **Reason:** No relevant changes detected
134115
135116 ---
136117
137- <details>
138- <summary> View full semantic-release log</summary>
139-
140- \`\`\`
141- ${{ steps.semantic.outputs.full_output }}
142- \`\`\`
143- </details>
144-
145- ---
146-
147- *This preview is generated by semantic-release dry-run mode*`;
148- }
149-
150- // Find existing comment
151- const { data: comments } = await github.rest.issues.listComments({
152- owner: context.repo.owner,
153- repo: context.repo.repo,
154- issue_number: context.issue.number,
155- });
156-
157- const botComment = comments.find(comment =>
158- comment.user.type === 'Bot' &&
159- comment.body.includes('Release Preview')
160- );
161-
162- // Update or create comment
163- if (botComment) {
164- await github.rest.issues.updateComment({
165- owner: context.repo.owner,
166- repo: context.repo.repo,
167- comment_id: botComment.id,
168- body: body
169- });
170- } else {
171- await github.rest.issues.createComment({
172- owner: context.repo.owner,
173- repo: context.repo.repo,
174- issue_number: context.issue.number,
175- body: body
176- });
177- }
118+ *This preview is generated by semantic-release dry-run mode*' }}
0 commit comments