Skip to content

Commit

Permalink
feat: add workflow that comments changelog preview on PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Jun 18, 2024
1 parent 9cb5c20 commit 77580d8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/scripts/preview-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash

set -euo pipefail

if [ $# -eq 0 ]; then
echo "No arguments supplied. Use with '--token=<github token> --target-branch=<branch>'"
exit 1
fi

dry_run_output=$(npm run --silent release-please-dry-run -- "$@")

echo "$dry_run_output" | grep --silent "Would open 1 pull request" || exit 0

echo "$dry_run_output" | sed -n '/---/,/---/p' | sed '1d;$d'
43 changes: 43 additions & 0 deletions .github/workflows/changelog-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Changelog Preview

on:
pull_request:

jobs:
previewChangelog:
name: Preview Changelog
runs-on: ubuntu-latest
# if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*

- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}

- name: Install npm packages
run: npm ci

- name: Generate Changelog Preview
id: changelog-preview
run: |
changelog=$(npm run --silent release-please-changelog-preview -- --token=${{ secrets.GITHUB_TOKEN }} --target-branch=${{ github.head_ref || github.ref_name }})
echo "changelog<<EOF
$changelog
EOF" >> "$GITHUB_OUTPUT"
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.changelog-preview.outputs.changelog != '' }}
with:
skip_unchanged: true
message: |
This is a preview of the changelog of the next release:
${{ steps.changelog-preview.outputs.changelog }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"commitlint:last-commit": "commitlint --from=HEAD~1 --verbose",
"commitlint:merge-base": "commitlint --from=$(git merge-base HEAD main) --verbose",
"release-please-dry-run": "npx release-please release-pr --dry-run --config-file=release-please-config.json --manifest-file=.release-please-manifest.json --repo-url='https://github.com/GenSpectrum/LAPIS-SILO'"
"release-please-dry-run": "npx release-please release-pr --dry-run --config-file=release-please-config.json --manifest-file=.release-please-manifest.json --repo-url='https://github.com/GenSpectrum/LAPIS-SILO'",
"release-please-changelog-preview": ".github/scripts/preview-changelog.sh"
}
}

0 comments on commit 77580d8

Please sign in to comment.