Skip to content
Open
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
13 changes: 0 additions & 13 deletions .github/workflows/commit-lint-problem-matcher.json

This file was deleted.

49 changes: 33 additions & 16 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
name: First commit message adheres to guidelines

on:
pull_request:
pull_request_target:
branches:
- main

env:
NODE_VERSION: lts/*

permissions:
contents: read
pull-requests: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
lint-commit-message:
name: lint-commit-message
runs-on: ubuntu-slim
steps:
- name: Compute number of commits in the PR
id: nb-of-commits
run: |
echo "plusOne=$((${{ github.event.pull_request.commits }} + 1))" >> $GITHUB_OUTPUT
echo "minusOne=$((${{ github.event.pull_request.commits }} - 1))" >> $GITHUB_OUTPUT
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: ${{ steps.nb-of-commits.outputs.plusOne }}
persist-credentials: false
- run: git reset HEAD^2
- name: Install Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Validate commit message
run: |
echo "::add-matcher::.github/workflows/commit-lint-problem-matcher.json"
git rev-parse HEAD~${{ steps.nb-of-commits.outputs.minusOne }} | xargs npx -q core-validate-commit --no-validate-metadata --tap
- name: Validate first commit message
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { data: [commit] } = await github.rest.pulls.listCommits({
...context.repo,
pull_number: context.issue.number,
per_page: 1,
});
if (!commit) {
throw new Error('No commits found in pull request');
}
const { exitCode, stdout, stderr } = await exec.getExecOutput('npx', [
'-q', '--yes', '--ignore-scripts', 'core-validate-commit@6.0.0',
'--no-validate-metadata', '--tap', '-',
], {
cwd: process.env.RUNNER_TEMP,
input: Buffer.from(JSON.stringify([{ id: commit.sha, message: commit.commit.message }])),
silent: true,
ignoreReturnCode: true,
});
if (exitCode !== 0) {
core.setFailed(stdout + stderr || 'Commit message validation failed');
} else {
core.info('First commit message passes validation');
}
Comment on lines +28 to +52

@aduh95 aduh95 Sep 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would work and be more maintainable

Suggested change
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { data: [commit] } = await github.rest.pulls.listCommits({
...context.repo,
pull_number: context.issue.number,
per_page: 1,
});
if (!commit) {
throw new Error('No commits found in pull request');
}
const { exitCode, stdout, stderr } = await exec.getExecOutput('npx', [
'-q', '--yes', '--ignore-scripts', 'core-validate-commit@6.0.0',
'--no-validate-metadata', '--tap', '-',
], {
cwd: process.env.RUNNER_TEMP,
input: Buffer.from(JSON.stringify([{ id: commit.sha, message: commit.commit.message }])),
silent: true,
ignoreReturnCode: true,
});
if (exitCode !== 0) {
core.setFailed(stdout + stderr || 'Commit message validation failed');
} else {
core.info('First commit message passes validation');
}
run: echo "$COMMITS" | npx -q core-validate-commit -
env:
COMMITS: ${{ toJSON([github.event.commits[0]]) }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't work. github.event.commits is an integer count for pull_request_target, not the individual commits, and array index literals don't work in expressions either. I also wanted to avoid streaming linter output to avoid workflow-command injection since we're on pull_request_target.

Loading