Skip to content

chore: adds comment to PRs with release version #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 10, 2025
Merged
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
133 changes: 133 additions & 0 deletions .github/workflows/pr-semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Orb Agent - PR Semantic Release Check
on:
pull_request:
branches: [ release ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}
APP_NAME: orb-agent

permissions:
contents: read
pull-requests: write

jobs:
semantic-release-dry-run:
name: Semantic Release Dry Run
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

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

- name: Write package.json
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 #v1.3
with:
path: ./package.json
write-mode: overwrite
contents: |
{
"name": "${{ env.APP_NAME }}",
"version": "1.0.0",
"devDependencies": {
"semantic-release-export-data": "^1.0.1",
"@semantic-release/changelog": "^6.0.3"
}
}

- name: Write .releaserc.json
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 #v1.3
with:
path: ./.releaserc.json
write-mode: overwrite
contents: |
{
"branches": "release_version_comment",
"repositoryUrl": "https://github.com/netboxlabs/orb-agent",
"debug": "true",
"tagFormat": "v${version}",
"plugins": [
["semantic-release-export-data"],
["@semantic-release/commit-analyzer", {
"releaseRules": [
{ "message": "*", "release": "patch"},
{ "message": "fix*", "release": "patch" },
{ "message": "feat*", "release": "minor" },
{ "message": "major*", "release": "major" }
]
}],
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "# Semantic Versioning Changelog"
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "release/**"
}
]
}
]
]
}

- name: Install dependencies
run: npm i

- name: Run semantic-release dry-run
id: semantic-release
run: npx semantic-release --debug --dry-run

- name: Comment PR with results
uses: actions/github-script@v7
with:
script: |
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});

const commitMessages = commits.map(commit => commit.commit.message).join('\n');

let comment = `## Semantic Release Dry Run Results 🔍\n\n`;

if (process.env.NEW_RELEASE_PUBLISHED === 'true') {
comment += `✅ **A new release would be published!**\n\n`;
comment += `**Version:** ${process.env.NEW_RELEASE_VERSION}\n\n`;
comment += `**Commit Messages:**\n\`\`\`\n${commitMessages}\n\`\`\`\n\n`;
comment += `This PR would trigger a ${process.env.NEW_RELEASE_TYPE || 'patch'} release.`;
} else {
comment += `ℹ️ **No new release would be published**\n\n`;
comment += `**Commit Messages:**\n\`\`\`\n${commitMessages}\n\`\`\`\n\n`;
comment += `No semantic changes detected that would trigger a release.`;
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
env:
NEW_RELEASE_PUBLISHED: ${{ steps.semantic-release.outputs.new-release-published }}
NEW_RELEASE_VERSION: ${{ steps.semantic-release.outputs.new-release-version }}
NEW_RELEASE_TYPE: ${{ steps.semantic-release.outputs.new-release-type }}