Skip to content
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
17 changes: 12 additions & 5 deletions .github/workflows/test_check-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ jobs:
run: npm run typecheck
- name: Unit tests
run: npm test
# Fails if dist/ is out of date with the source or the dependencies, for
# example after a dependency bump without a rebuild.
- name: Check that the bundle is up to date
run: |
npm run build
if ! git diff --exit-code -- dist || [[ -n "$(git status --porcelain -- dist)" ]]; then
git status --short -- dist
echo "::error::check-changelog/dist is out of date. Run npm run build in check-changelog and commit the result."
exit 1
fi
- name: Fixture repository tests
run: test/fixtures.sh

Expand Down Expand Up @@ -104,7 +114,7 @@ jobs:
# End to end against a merged ocap-kernel pull request whose pre-merge head
# changed a public package and added a changelog entry linking it. The action
# only checks out the repository it runs in, so this checks out ocap-kernel
# the same way and runs the script directly.
# the same way and runs the bundled script directly.
ocap-kernel:
name: ocap-kernel PR (pr-number ${{ matrix.pr-number }})
runs-on: ubuntu-latest
Expand Down Expand Up @@ -132,15 +142,12 @@ jobs:
with:
node-version: 24.x
package-manager-cache: false
- name: Install check dependencies
working-directory: actions-repo/check-changelog
run: npm ci --ignore-scripts --omit=dev --no-audit --no-fund
- name: Run script
id: script
continue-on-error: true
env:
PR_NUMBER: ${{ matrix.pr-number }}
run: node actions-repo/check-changelog/scripts/check-changelog.ts target-repo main "$PR_NUMBER"
run: node actions-repo/check-changelog/dist/check-changelog.js target-repo main "$PR_NUMBER"
- name: Assert outcome
env:
OUTCOME: ${{ steps.script.outcome }}
Expand Down
44 changes: 33 additions & 11 deletions check-changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ added) starting with `}` that follows a `"devDependencies":` line, and to start

## Differences from upstream

- The check script runs from `${{ github.action_path }}` with Node.js 24's built-in type
stripping and `npm ci --ignore-scripts --omit=dev`, instead of checking out `github-tools` and
running `yarn` and `ts-node`. The `github-tools-repository` and `github-tools-ref` inputs are
removed.
- The check script runs from `${{ github.action_path }}` as a committed bundle,
`dist/check-changelog.js`, with nothing installed at run time, instead of checking out
`github-tools` and running `yarn` and `ts-node`. The `github-tools-repository` and
`github-tools-ref` inputs are removed.
- The `head-ref` and `repo` inputs are removed. Callers passed `head-ref: ${{ github.head_ref }}`
with `repo: ${{ github.repository }}`, and for a pull request from a fork `github.head_ref` is
the fork's branch name, so the action checked out a branch of that name from the base
Expand Down Expand Up @@ -123,10 +123,24 @@ added) starting with `}` that follows a `"devDependencies":` line, and to start
refused package `package.json` is logged and the package is treated as public, as for one that
can't be parsed.

## Implementation

The check script is `scripts/check-changelog.ts`. The action runs `dist/check-changelog.js`, an
unminified esbuild bundle of the script and the code it uses from its dependencies: `semver` and
`@metamask/auto-changelog`'s `parseChangelog` (`dist/parse-changelog.js` and the modules it
imports). The build resolves `@metamask/auto-changelog` to that module instead of the package's
index, so the bundle contains none of the package's CLI dependencies (`@yarnpkg/core`, Octokit,
execa, yargs). Nothing is installed at run time; all dependencies are devDependencies, used only
to build, typecheck and test. The bundled packages' licenses are in `dist/LICENSES.txt`, written
by the same build. The build fails if the bundle imports anything but `node:` built-ins at run
time: esbuild leaves an import it can't resolve in the bundle without a warning, and the action
has no `node_modules` to load it from.

## Security

The action installs its own pinned dependencies (`package-lock.json`) at run time, without
install scripts. It reads, but never runs, code from the pull request. Use it in `pull_request`
The action installs nothing at run time: it runs the committed bundle (see
[Implementation](#implementation)), built from the pinned dependencies in `package-lock.json`. It
reads, but never runs, code from the pull request. Use it in `pull_request`
workflows with a read-only token, never from `pull_request_target`. The content of a pull request
from a fork reaches the script, so it is untrusted: this is why the script stops workflow
commands, refuses symbolic links, lists changed files NUL-separated (`git diff -z`), and the
Expand All @@ -142,16 +156,24 @@ cd check-changelog
npm ci --ignore-scripts
npm run typecheck
npm test # unit tests of the package.json diff analysis
test/fixtures.sh # end-to-end runs against fixture git repositories
npm run build # rebuilds dist/check-changelog.js and dist/LICENSES.txt
test/fixtures.sh # end-to-end runs of dist/check-changelog.js against fixture git repositories
```

After changing the script or a dependency, run `npm run build` and commit `dist/`. CI rebuilds
the bundle and fails if `dist/` differs from what is committed. The build empties `dist/` first,
so a committed file that the build doesn't write also fails the check. The fixture tests run the bundle,
which is what the action ships; `SCRIPT="$PWD/scripts/check-changelog.ts" test/fixtures.sh` runs
them against the source instead. The unit tests run against the source.

The fixture tests also fail if any output line, split on `\r` as well as `\n`, would be taken as
a workflow command other than the script's own.

`.github/workflows/test_check-changelog.yml` runs these and, on this repository's own pull
requests, runs the action to check that the `no-changelog` label skips the checkout and that the
pull request head (from a fork too) and the base branch are fetched. On `push` and
`.github/workflows/test_check-changelog.yml` runs these, checks that `dist/` is up to date, and,
on this repository's own pull requests, runs the action to check that the `no-changelog` label
skips the checkout and that the pull request head (from a fork too) and the base branch are
fetched. On `push` and
`workflow_dispatch` it checks that the action fails without checking anything out. It also checks
out a merged `Consensys-Incorporated/ocap-kernel` pull request at `refs/pull/1290/head`, as the
action would in that repository, and runs the script against it. Run against upstream's script, the fixture tests pass or fail the same way except
action would in that repository, and runs the bundled script against it. Run against upstream's script, the fixture tests pass or fail the same way except
in the cases covering the differences listed above.
10 changes: 3 additions & 7 deletions check-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ runs:
node-version: 24.x
package-manager-cache: false

- name: Install check dependencies
if: ${{ steps.label-check.outputs.skip != 'true' }}
shell: bash
working-directory: ${{ github.action_path }}
run: npm ci --ignore-scripts --omit=dev --no-audit --no-fund

# dist/check-changelog.js bundles the script with the code it uses from
# its dependencies, so nothing is installed at run time.
- name: Check changelog
if: ${{ steps.label-check.outputs.skip != 'true' }}
shell: bash
env:
BASE_BRANCH: ${{ inputs.base-branch }}
PR_NUMBER: ${{ inputs.pr-number }}
ACTION_PATH: ${{ github.action_path }}
run: node "$ACTION_PATH/scripts/check-changelog.ts" target-repo "$BASE_BRANCH" "$PR_NUMBER"
run: node "$ACTION_PATH/dist/check-changelog.js" target-repo "$BASE_BRANCH" "$PR_NUMBER"
Loading
Loading