It is a linter of pull requests for GitHub Actions.
To enforce pull request titles in the same format will be useful like generating standard changelog messages. Besides it can be used to parse titles and link with issue tracking systems such as JIRA.
name: PR lint
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
jobs:
pr-lint:
runs-on: ubuntu-latest
steps:
- uses: seferov/pr-lint-action@master
with:
title-regex: '^\[PROJECT-\d*\](\ )'
title-regex-flags: 'g' # optional
error-message: 'Add Jira ID to your title' # optionalIn this example, for every pull request the title is expected to match ^\[PROJECT-\d*\]\ regex with a global flag g. For instance, [PROJECT-123] lorem ipsum or [PROJECT-2345] dolor sit amet are valid titles for this example. You can customize the title regex for your needs. The regex flags configuration is optional.
It can be configured to close pull request automatically if the title does not match the pattern provided. To do so, github-token and auto-close-message options must be configured.
In the message, %pattern% is replaced with the actual the pattern provided. Here is an example pull request.
Config:
name: PR lint
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
jobs:
pr-lint:
runs-on: ubuntu-latest
steps:
- uses: seferov/pr-lint-action@master
with:
title-regex: '^\[PROJECT-\d*\](\ )'
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ auto-close-message: 'Closing this pull request since the title does not match %pattern% pattern. Please fix the title and re-open the pull request.'- Source entry point: The action's implementation lives in TypeScript under
src/main.ts. - Bundled artifact: During the build step we use
@vercel/nccto bundle the source into a single JavaScript file atdist/index.js(vianpm run build). - Why
dist/index.jsis committed: GitHub JavaScript actions are executed directly from the repository contents on the runner. To ensure consumers can run the action without installing Node.js or any build tooling, the compileddist/index.jsfile is checked into version control and referenced fromaction.yml. - Contributor workflow: When you change code under
src/, runnpm installonce (if needed) and thennpm run buildto regeneratedist/index.jsbefore committing. The repository expects the compiled artifact to be in sync with the TypeScript sources.
There is also a helper script and CI workflow to ensure the committed bundle stays in sync:
npm run verify-indexrunsnpm run buildand then checks thatdist/index.jshas no uncommitted changes (git diff --exit-code dist/index.js)..github/workflows/pr-index-verify.ymlruns this script on every pull request in this repository, so PRs will fail ifdist/index.jsis out of date with respect tosrc/main.ts.
- This action is implemented as a JavaScript action and is configured in
action.ymlwithruns.using: 'node20'andruns.main: 'dist/index.js'. - When you use the action in a workflow (for example
- uses: seferov/pr-lint-action@masteror- uses: ./when developing locally), GitHub Actions automatically uses its Node.js 20 runtime to execute the bundleddist/index.js; you do not need to set up a Node version in your workflow steps for this action to work.