-
Notifications
You must be signed in to change notification settings - Fork 12
docs: add Signed-off-by check for pull requests #20
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: Commit Signoff | ||
|
|
||
| 'on': | ||
| pull_request: | ||
| merge_group: | ||
| types: [checks_requested] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| commit-signoff: | ||
| name: commit-signoff | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check PR commits for Signed-off-by | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const pull_number = context.payload.pull_request.number; | ||
|
|
||
| const commits = await github.paginate( | ||
| github.rest.pulls.listCommits, | ||
| { | ||
| owner, | ||
| repo, | ||
| pull_number, | ||
| per_page: 100, | ||
| } | ||
| ); | ||
|
|
||
| const trailerPattern = /^Signed-off-by:\s+.+\s+<[^<>]+>$/im; | ||
| const missing = commits.filter(({ commit }) => !trailerPattern.test(commit.message)); | ||
|
|
||
| const writeSummary = async (lines) => { | ||
| await core.summary | ||
| .addHeading('Signed-off-by check') | ||
| .addRaw(lines.join('\n') + '\n') | ||
| .write(); | ||
| }; | ||
|
|
||
| if (missing.length === 0) { | ||
| await writeSummary([ | ||
| `Checked ${commits.length} commit(s).`, | ||
| 'All commits include a Signed-off-by trailer.', | ||
| ]); | ||
| return; | ||
| } | ||
|
|
||
| await writeSummary([ | ||
| `Found ${missing.length} commit(s) without a valid Signed-off-by trailer:`, | ||
| '', | ||
| ...missing.map(({ sha, commit }) => `- ${sha.slice(0, 12)} ${commit.message.split('\n')[0]}`), | ||
| '', | ||
| 'Please rewrite the commit message(s) and push again.', | ||
| 'Examples: `git commit --amend -s` or `git rebase --signoff <base>`.', | ||
| ]); | ||
|
|
||
| core.setFailed( | ||
| [ | ||
| `Found ${missing.length} commit(s) without a valid Signed-off-by trailer.`, | ||
| ...missing.map(({ sha, commit }) => `- ${sha.slice(0, 12)} ${commit.message.split('\n')[0]}`), | ||
| 'Please rewrite the commit message(s) and push again.', | ||
| 'Examples: git commit --amend -s or git rebase --signoff <base>.', | ||
| ].join('\n') | ||
| ); | ||
|
|
||
| - name: Report merge queue compatibility | ||
| if: ${{ github.event_name == 'merge_group' }} | ||
| run: | | ||
| echo "Signed-off-by is enforced on pull_request workflows." | ||
| echo "This merge_group run reports the required status for merge queue compatibility." | ||
|
Comment on lines
+72
to
+76
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Signed-off-by detection regex will treat any line starting with “Signed-off-by:” anywhere in the commit message as valid, even if it appears in the body (e.g., quoted text) rather than as a trailer/footer. That can lead to false positives and undermines the “trailer” requirement. Consider validating only the trailer block at the end of the commit message (e.g., scan upward from the end after the last blank line, or use a trailer parser strategy) instead of a whole-message regex match.