Skip to content
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

ci: add workflow that comments changelog preview on PRs #493

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions .github/scripts/preview-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /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

extract_everything_between_tripledashes="/---/,/---/p"
drop_first_and_last_line='1d;$d'
echo "$dry_run_output" | sed -n "$extract_everything_between_tripledashes" | sed "$drop_first_and_last_line"
51 changes: 51 additions & 0 deletions .github/workflows/changelog-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
header: changelogPreview
message: |
This is a preview of the changelog of the next release:

${{ steps.changelog-preview.outputs.changelog }}

- name: Delete PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.changelog-preview.outputs.changelog == '' }}
with:
header: changelogPreview
delete: true
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"
}
}