Skip to content

Commit

Permalink
chore: set up release preview comment
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Aug 14, 2024
1 parent 4f9e26b commit 2ae25af
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,83 @@ jobs:
run: npm run lint
- name: Run build
run: npm run build
release-preview:
name: Automated release preview
needs: [lint]
permissions:
issues: write
runs-on: ubuntu-latest
steps:
- name: 📀 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🖥️ Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: 🔗 Install Dependencies
shell: bash
run: npm install --no-fund --no-audit --ignore-scripts
- name: 🔬 Check semantic versioning
id: semantic-release
run: |
GITHUB_REF=${{ github.head_ref }}
npx semantic-release --no-ci --dry-run --plugins @semantic-release/commit-analyzer,@semantic-release/release-notes-generator --branches ${{ github.head_ref }} > output.txt
OUTPUT=$(cat output.txt | base64 -w 0)
echo "::set-output name=releaseNote::$OUTPUT"
- name: 📝 Report semantic versioning
uses: actions/github-script@v3
if: ${{ steps.semantic-release.outputs.releaseNote != '' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// build release note
const semanticReleaseOutput = Buffer.from('${{ steps.semantic-release.outputs.releaseNote }}', 'base64').toString('utf8');
const semanticReleaseLogMatch = /^[[0-9:\sAMPM]+\]\s\[semantic-release\].*$/;
const lines = semanticReleaseOutput.split('\n');
const lastSemanticReleaseLogIndex = [...lines]
.reverse()
.findIndex((line) => line.match(semanticReleaseLogMatch));
const releaseNoteIndex = lines.length - lastSemanticReleaseLogIndex;
const releaseNote = lines.slice(releaseNoteIndex);
let res = releaseNote.join('\n');
if (!releaseNote.length || !res) {
res = '### No release note would be generated.';
}
const SEMANTIC_RELEASE_BODY_HEADER = '## 📝 Semantic Release Report';
const body = [SEMANTIC_RELEASE_BODY_HEADER, res].join('\n');
// get last comment
const comments = await github.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// find comments to delete
const commentsToDelete = comments.data.filter((comment) =>
comment.body.startsWith(SEMANTIC_RELEASE_BODY_HEADER)
);
// delete comments
const prms = commentsToDelete.map((comment) =>
github.issues.deleteComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo
})
);
await Promise.all(prms);
// create new comment for release note
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});

0 comments on commit 2ae25af

Please sign in to comment.