From 77580d829bdb1d544f66db0abfe495e265a3e587 Mon Sep 17 00:00:00 2001 From: Fabian Engelniederhammer Date: Tue, 18 Jun 2024 22:55:25 +0200 Subject: [PATCH] feat: add workflow that comments changelog preview on PRs --- .github/scripts/preview-changelog.sh | 14 ++++++++ .github/workflows/changelog-preview.yml | 43 +++++++++++++++++++++++++ package.json | 3 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/preview-changelog.sh create mode 100644 .github/workflows/changelog-preview.yml diff --git a/.github/scripts/preview-changelog.sh b/.github/scripts/preview-changelog.sh new file mode 100755 index 000000000..272f35171 --- /dev/null +++ b/.github/scripts/preview-changelog.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +set -euo pipefail + +if [ $# -eq 0 ]; then + echo "No arguments supplied. Use with '--token= --target-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' diff --git a/.github/workflows/changelog-preview.yml b/.github/workflows/changelog-preview.yml new file mode 100644 index 000000000..fff517ad6 --- /dev/null +++ b/.github/workflows/changelog-preview.yml @@ -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<> "$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 }} diff --git a/package.json b/package.json index 25020a6b7..8bfc07714 100644 --- a/package.json +++ b/package.json @@ -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" } }