Skip to content

ci: enforce PR commit policy - #1775

Merged
lizhengfeng101 merged 1 commit into
mainfrom
ci/pr-commit-policy
Oct 19, 2026
Merged

lizhengfeng101 merged 1 commit into
mainfrom
ci/pr-commit-policy

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Description

Add a lightweight PR Commit Policy check to reject GitHub Actions skip directives in PR titles and complete commit messages. A historical formatting commit in #956 carried a skip directive into the squash commit and prevented main-branch CI from starting.

  • Use pull_request_target so commit-message skip directives cannot disable the policy itself.
  • Execute only the trusted workflow-SHA script with read-only permissions on the existing Linux/X64 self-hosted pool, using a resource-limited node:24.18.0 container.
  • Read PR commits with GraphQL cursor pagination and fall back to the paginated compare API when GitHub truncates the PR connection at 250 commits. Pin the comparison to immutable base/head SHAs, recheck metadata afterward, and require the fetched head and title to match the triggering event.
  • Keep PR descriptions out of scope because squash defaults use the PR title only, and descriptions need to discuss these directives.
  • Add regression tests and synchronize contributor guidance across all five repository-guide and documentation-site locales.

Type of Change

  • CI / Build / Tooling
  • Documentation update

How Has This Been Tested?

  • make check
  • make test
  • make build
  • npm run test:github-actions
  • Policy regression tests: 64 cases; 100% line, branch, and function coverage for the policy script.
  • Actionlint and the repository's action-pin verification.
  • Markdown renderer tests and documentation-site production build; the build reports two asset-size warnings.
  • Verified that the policy text matches exactly across the five repository/site locale pairs.
  • Read-only validation with real PR metadata: feat(language): support for Nushell language #956 is rejected and feat(rules): add PowerShell review support #970 passes.
  • Real large-PR validation using NixOS/nixpkgs#560469: reproduced the GraphQL 250-commit truncation, then fetched and validated all 780 commits through eight compare-API pages with a final metadata recheck.

Rollout Notes

This PR does not change branch protection. Merge the workflow first, verify an actual fork PR and title-only edit on the self-hosted runners, then add PR Commit Policy as a required check. A newly introduced pull_request_target workflow does not execute from this PR's untrusted branch.

Monitor runner queue time before making the check mandatory. The container provides runtime consistency and resource limits, not an ephemeral host or a security boundary against a compromised shared runner. Keep the title-only squash default and review manually edited merge messages.

Checklist

  • Coding-style, license, and language checks pass.
  • Regression tests and contributor documentation are included.
  • The contributor has personally reviewed all generated code and translations.
  • The contributor has confirmed CLA status.

AI Assistance

Implementation, tests, translations, and this PR description were prepared with OpenAI Codex using gpt-6-astra. The repository-required automated review used OpenCodeReview with the configured model claude-opus-5-5. No AI attribution or co-author trailers are added to the commit. The contributor remains responsible for reviewing the generated material and answering maintainer questions from their own understanding.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

- name: Check out trusted policy script
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}

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.

security · high
Security: Untrusted code execution via pull_request_target

For pull_request_target events, github.sha resolves to the PR head commit (potentially from a fork). This means the workflow checks out and executes code authored by the PR submitter — specifically scripts/github-actions/check-pr-commit-policy.js loaded via require() in the next step.

Although permissions are scoped to read-only, a malicious PR author could modify this script to exfiltrate repository contents or PR data accessible under those permissions. The step name says "Check out trusted policy script" but the checked-out code is not trusted.

The existing ocr-review.yml in this repo demonstrates the safe pattern: omitting ref: so that actions/checkout defaults to the base branch for pull_request_target.

Suggested fix: Remove the ref: input entirely so the checkout defaults to the base branch (the trusted main branch), or explicitly set ref: ${{ github.event.pull_request.base.sha }}. The sparse-checkout already limits what files are materialized, so only the trusted version of the policy script will be present.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No change planned here: this workflow uses pull_request_target, where github.sha refers to the trusted default-branch commit, not the PR head (GitHub docs). The explicit ref therefore checks out the trusted policy script.

@css521 css521 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 55450a9 into main Oct 19, 2026
16 checks passed
@lizhengfeng101
lizhengfeng101 deleted the ci/pr-commit-policy branch October 19, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants