Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0486733
feat!: Updated terraform checks action adding preview release.
Dec 2, 2025
8ec5cf1
fix: checkout to head
Dec 2, 2025
0648c64
fix: using temperory Pr
Dec 2, 2025
c487808
fix: updated version.
Dec 2, 2025
2e74685
temp message
Dec 2, 2025
d4e04f3
removed git conf
Dec 2, 2025
2d82f83
fetch git remote
Dec 2, 2025
9e969c7
made few changes in terraform checks
Dec 2, 2025
39a5750
made workflow changes
Dec 2, 2025
71c8f79
made few changes in git workflow.
Dec 2, 2025
d4da3ba
test
Dec 2, 2025
f2b390d
feat!: Made changes in cross account
Dec 2, 2025
81394c5
test
Dec 2, 2025
58c27cb
test
Dec 2, 2025
f27c9b0
test
Dec 2, 2025
9ce4b1e
test
Dec 2, 2025
9f05799
test
Dec 2, 2025
9a87e36
test
Dec 2, 2025
01a2ba0
test
Dec 2, 2025
c59cf94
test.
Dec 2, 2025
d7012bc
updated release Preview.
Dec 3, 2025
e538e0e
updated release.yaml
Dec 3, 2025
8d60de0
made changes in preview release file
Dec 3, 2025
da76791
updated release added ref to main branch
Dec 3, 2025
44f2861
updated release preview file.
Dec 3, 2025
ceb7576
made changes in preview.yaml file.
Dec 3, 2025
3e4c75d
Made changes in release preview to check if semantic api response is …
Dec 3, 2025
789ac3c
test
Dec 3, 2025
3b878d8
test changes.
Dec 3, 2025
c9cf5fb
check git ref.
Dec 3, 2025
4777601
test semantic changes.
Dec 3, 2025
cd7a4fc
updated workflow.
Dec 3, 2025
d96675a
Updated terraform yaml file.
Dec 3, 2025
eca425b
Made changes for getting proper comments.
Dec 3, 2025
46576fd
updated Github actions preview release notes.
Dec 3, 2025
e167ceb
Cleared white spaces.
Dec 3, 2025
db62936
Made changes for preview-releaserc.json
Dec 3, 2025
61e6099
fix: Updated release-preview with removing unwanted displays.
Dec 3, 2025
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
177 changes: 177 additions & 0 deletions .github/workflows/release-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Release Preview

on:
workflow_call:

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

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

- name: Setup branch for semantic-release
run: |
# Explicitly checkout to the PR branch by name
git checkout -B ${{ github.event.pull_request.head.ref }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Setup preview config
run: |
# Update preview config with the PR branch name
sed -i.bak "s/BRANCH_PLACEHOLDER/${{ github.event.pull_request.head.ref }}/g" .preview-releaserc.json
rm .preview-releaserc.json.bak

- 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 }}"

# Temporarily use preview config
mv .releaserc.json .releaserc.json.main
cp .preview-releaserc.json .releaserc.json

# Run semantic-release with inline package installation (same as your local command)
OUTPUT=$(npx --package semantic-release --package @semantic-release/exec --package conventional-changelog-conventionalcommits semantic-release 2>&1 || true)
echo "$OUTPUT"

# Restore original config
rm .releaserc.json
mv .releaserc.json.main .releaserc.json

# 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: actions/github-script@v7
with:
script: |
const newVersion = '${{ steps.semantic.outputs.new_version }}';
const releaseType = '${{ steps.semantic.outputs.release_type }}';

const releaseNotes = `${{ steps.semantic.outputs.release_notes }}`;

let body;
if (newVersion) {
body = `## Release Preview

**Version:** \`v${newVersion}\`
**Release Type:** \`${releaseType}\`
**Status:** Release will be published when merged to main

---

### Release Notes

${releaseNotes}

---

*This preview is generated by semantic-release dry-run mode*`;
}
else {
body = `## Release Preview

**Status:** No release will be published
**Reason:** No relevant changes detected

---

<details>
<summary> View full semantic-release log</summary>

\`\`\`
${{ steps.semantic.outputs.full_output }}
\`\`\`
</details>

---

*This preview is generated by semantic-release dry-run mode*`;
}

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Release Preview')
);

// Update or create comment
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
8 changes: 8 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ on:
- main
- master
jobs:
releasePreview:
name: Release Preview
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
uses: ./.github/workflows/release-preview.yaml
permissions:
contents: write
pull-requests: write

preCommitCheck:
name: Terraform Checks
uses: ./.github/workflows/terraform-checks.yaml
Expand Down
11 changes: 11 additions & 0 deletions .preview-releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"branches": ["BRANCH_PLACEHOLDER"],
"debug": true,
"ci": false,
"dryRun": true,
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
2 changes: 1 addition & 1 deletion examples/cross-account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ route53:ChangeResourceRecordSets
route53:ListHostedZonesByName
route53:ListResourceRecordSets

And a trust policy allowing Account A to assume the role.
And a trust policy which allows Account A to assume the role.


## Example `tfvars` Configuration
Expand Down