Skip to content

Commit d7012bc

Browse files
author
rahul-infra
committed
updated release Preview.
1 parent c59cf94 commit d7012bc

File tree

3 files changed

+152
-44
lines changed

3 files changed

+152
-44
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Release Preview
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
preview:
8+
name: Preview Release
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 'lts/*'
25+
26+
- name: Install semantic-release
27+
run: |
28+
npm install -g semantic-release@18.0.0 \
29+
@semantic-release/commit-analyzer@9.0.2 \
30+
@semantic-release/release-notes-generator@10.0.3 \
31+
@semantic-release/github@8.0.7 \
32+
conventional-changelog-conventionalcommits@4.6.3
33+
34+
- name: Run semantic-release (dry-run)
35+
id: semantic
36+
run: |
37+
# Run semantic-release in dry-run mode and capture output
38+
OUTPUT=$(npx semantic-release --dry-run --no-ci 2>&1 || true)
39+
echo "$OUTPUT"
40+
41+
# Extract version information
42+
NEW_VERSION=$(echo "$OUTPUT" | grep -oP "The next release version is \K[0-9]+\.[0-9]+\.[0-9]+" || echo "")
43+
RELEASE_TYPE=$(echo "$OUTPUT" | grep -oP "Analysis of \d+ commits complete: \K\w+ release" | sed 's/ release//' || echo "")
44+
45+
# Save to outputs
46+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
47+
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
48+
49+
# Save full output for comment
50+
echo "full_output<<EOF" >> $GITHUB_OUTPUT
51+
echo "$OUTPUT" >> $GITHUB_OUTPUT
52+
echo "EOF" >> $GITHUB_OUTPUT
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Display Preview
57+
run: |
58+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
59+
echo " RELEASE PREVIEW"
60+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
61+
echo ""
62+
if [ -n "${{ steps.semantic.outputs.new_version }}" ]; then
63+
echo "Version: v${{ steps.semantic.outputs.new_version }}"
64+
echo "Release Type: ${{ steps.semantic.outputs.release_type }}"
65+
echo "Status: Release will be published"
66+
else
67+
echo "Status: No release will be published"
68+
echo "Reason: No relevant changes detected"
69+
fi
70+
echo ""
71+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
72+
73+
- name: Comment on PR
74+
if: github.event_name == 'pull_request'
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const newVersion = '${{ steps.semantic.outputs.new_version }}';
79+
const releaseType = '${{ steps.semantic.outputs.release_type }}';
80+
81+
let body;
82+
if (newVersion) {
83+
body = `## Release Preview
84+
85+
**Version:** \`v${newVersion}\`
86+
**Release Type:** \`${releaseType}\`
87+
**Status:** Release will be published when merged to main
88+
89+
<details>
90+
<summary> View semantic-release analysis</summary>
91+
92+
\`\`\`
93+
${{ steps.semantic.outputs.full_output }}
94+
\`\`\`
95+
</details>
96+
97+
---
98+
*This preview is generated by semantic-release dry-run mode*`;
99+
} else {
100+
body = `## Release Preview
101+
102+
**Status:** No release will be published
103+
**Reason:** No relevant changes detected
104+
105+
<details>
106+
<summary> View semantic-release analysis</summary>
107+
108+
\`\`\`
109+
${{ steps.semantic.outputs.full_output }}
110+
\`\`\`
111+
</details>
112+
113+
---
114+
*This preview is generated by semantic-release dry-run mode*`;
115+
}
116+
117+
// Find existing comment
118+
const { data: comments } = await github.rest.issues.listComments({
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
issue_number: context.issue.number,
122+
});
123+
124+
const botComment = comments.find(comment =>
125+
comment.user.type === 'Bot' &&
126+
comment.body.includes('Release Preview')
127+
);
128+
129+
// Update or create comment
130+
if (botComment) {
131+
await github.rest.issues.updateComment({
132+
owner: context.repo.owner,
133+
repo: context.repo.repo,
134+
comment_id: botComment.id,
135+
body: body
136+
});
137+
} else {
138+
await github.rest.issues.createComment({
139+
owner: context.repo.owner,
140+
repo: context.repo.repo,
141+
issue_number: context.issue.number,
142+
body: body
143+
});
144+
}

.github/workflows/terraform-checks.yaml

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,6 @@ env:
88
TFLINT_VERSION: v0.52.0
99

1010
jobs:
11-
versionPreview:
12-
name: Version Preview
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v5
17-
with:
18-
ref: ${{github.event.pull_request.head.ref }}
19-
fetch-depth: 0
20-
21-
- name: Temporarily merge PR branch
22-
if: ${{ github.event_name == 'pull_request' }}
23-
run: |
24-
git config --global user.name github-actions
25-
git config --global user.email github-actions@github.com
26-
git checkout main
27-
git checkout -b temp-merge-branch
28-
git merge --no-ff origin/${{ github.event.pull_request.head.ref }} --message "Test"
29-
30-
- name: Release
31-
id: semantic-release
32-
uses: cycjimmy/semantic-release-action@v6
33-
with:
34-
semantic_version: 18.0.0
35-
extra_plugins: |
36-
@semantic-release/changelog@6.0.0
37-
@semantic-release/git@10.0.0
38-
conventional-changelog-conventionalcommits@4.6.3
39-
dry_run: true
40-
ci: false
41-
branches: |
42-
[
43-
`${{ github.event.pull_request.head.ref }}`
44-
]
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47-
48-
49-
- name: Show version preview output
50-
if: ${{ github.event_name == 'pull_request' }}
51-
run: |
52-
echo "Version Preview: ${{ steps.semantic-release.outputs.new_release_version || 'No new version' }}"
53-
echo "Previous Version: ${{ steps.semantic-release.outputs.last_release_version || 'No previous version' }}"
54-
5511
test:
5612
name: Test
5713
runs-on: ubuntu-latest

.github/workflows/terraform.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ on:
1515
- main
1616
- master
1717
jobs:
18+
releasePreview:
19+
name: Release Preview
20+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
21+
uses: ./.github/workflows/release-preview.yaml
22+
permissions:
23+
contents: read
24+
pull-requests: write
25+
1826
preCommitCheck:
1927
name: Terraform Checks
2028
uses: ./.github/workflows/terraform-checks.yaml

0 commit comments

Comments
 (0)