Merge commit 'cdbbf3afda' into clippy-subtree-update

This commit is contained in:
Philipp Krones 2025-07-10 20:25:36 +02:00
parent 0a64bfd685
commit 4e614bf683
126 changed files with 2759 additions and 475 deletions

View file

@ -1,7 +1,11 @@
name: Feature freeze check
on:
pull_request:
pull_request_target:
types:
- opened
branches:
- master
paths:
- 'clippy_lints/src/declared_lints.rs'
@ -9,6 +13,12 @@ jobs:
auto-comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
# Do not in any case add code that runs anything coming from the the content
# of the pull request, as malicious code would be able to access the private
# GitHub token.
steps:
- name: Check PR Changes
id: pr-changes
@ -19,7 +29,7 @@ jobs:
run: |
# Use GitHub API to create a comment on the PR
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT="**Seems that you are trying to add a new lint!**\nWe are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to August 1st and focusing on bugfixes.\nThanks a lot for your contribution, and sorry for the inconvenience.\nWith ❤ from the Clippy team"
COMMENT="**Seems that you are trying to add a new lint!**\nWe are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to September 18 and focusing on bugfixes.\nThanks a lot for your contribution, and sorry for the inconvenience.\nWith ❤ from the Clippy team\n\n@rustbot note Feature-freeze\n@rustbot blocked\n@rustbot label +A-lint\n"
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST $COMMENT_URL -d "{\"body\":\"$COMMENT\"}"

View file

@ -128,21 +128,27 @@ jobs:
- name: Download JSON
uses: actions/download-artifact@v4
- name: Store PR number
run: echo ${{ github.event.pull_request.number }} > pr.txt
- name: Diff results
# GH's summery has a maximum size of 1024k:
# https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary
# That's why we first log to file and then to the summary and logs
# GH's summery has a maximum size of 1MiB:
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#step-isolation-and-limits
# We upload the full diff as an artifact in case it's truncated
run: |
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate >> truncated_diff.md
head -c 1024000 truncated_diff.md >> $GITHUB_STEP_SUMMARY
cat truncated_diff.md
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json >> full_diff.md
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate | head -c 1M > $GITHUB_STEP_SUMMARY
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --write-summary summary.json > full_diff.md
- name: Upload full diff
uses: actions/upload-artifact@v4
with:
name: diff
if-no-files-found: ignore
name: full_diff
path: full_diff.md
- name: Upload summary
uses: actions/upload-artifact@v4
with:
name: summary
path: |
full_diff.md
truncated_diff.md
summary.json
pr.txt

106
.github/workflows/lintcheck_summary.yml vendored Normal file
View file

@ -0,0 +1,106 @@
name: Lintcheck summary
# The workflow_run event runs in the context of the Clippy repo giving it write
# access, needed here to create a PR comment when the PR originates from a fork
#
# The summary artifact is a JSON file that we verify in this action to prevent
# the creation of arbitrary comments
#
# This action must not checkout/run code from the originating workflow_run
# or directly interpolate ${{}} untrusted fields into code
#
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections
on:
workflow_run:
workflows: [Lintcheck]
types: [completed]
# Restrict the default permission scope https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defining-access-for-the-github_token-scopes
permissions:
pull-requests: write
jobs:
download:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: summary
path: untrusted
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Format comment
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const assert = require("assert/strict");
function validateName(s) {
assert.match(s, /^[a-z0-9_:]+$/);
return s;
}
function validateInt(i) {
assert.ok(Number.isInteger(i));
return i;
}
function tryReadSummary() {
try {
return JSON.parse(fs.readFileSync("untrusted/summary.json"));
} catch {
return null;
}
}
const prNumber = parseInt(fs.readFileSync("untrusted/pr.txt"), 10);
core.exportVariable("PR", prNumber.toString());
const untrustedSummary = tryReadSummary();
if (!Array.isArray(untrustedSummary)) {
return;
}
let summary = `Lintcheck changes for ${context.payload.workflow_run.head_sha}
| Lint | Added | Removed | Changed |
| ---- | ----: | ------: | ------: |
`;
for (const untrustedRow of untrustedSummary) {
const name = validateName(untrustedRow.name);
const added = validateInt(untrustedRow.added);
const removed = validateInt(untrustedRow.removed);
const changed = validateInt(untrustedRow.changed);
const id = name.replace("clippy::", "user-content-").replaceAll("_", "-");
const url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${context.payload.workflow_run.id}#${id}`;
summary += `| [\`${name}\`](${url}) | ${added} | ${removed} | ${changed} |\n`;
}
summary += "\nThis comment will be updated if you push new changes";
fs.writeFileSync("summary.md", summary);
- name: Create/update comment
run: |
if [[ -f summary.md ]]; then
gh pr comment "$PR" --body-file summary.md --edit-last --create-if-none
else
# There were no changes detected by Lintcheck
# - If a comment exists from a previous run that did detect changes, edit it (--edit-last)
# - If no comment exists do not create one, the `gh` command exits with an error which
# `|| true` ignores
gh pr comment "$PR" --body "No changes for ${{ github.event.workflow_run.head_sha }}" --edit-last || true
fi
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}