diff --git a/ci/github-script/check-cherry-picks.md b/ci/github-script/check-cherry-picks.md deleted file mode 100644 index 1b214b28eaa7..000000000000 --- a/ci/github-script/check-cherry-picks.md +++ /dev/null @@ -1,10 +0,0 @@ -This report is automatically generated by the `PR / Check / cherry-pick` CI workflow. - -Some of the commits in this PR require the author's and reviewer's attention. - -Please follow the [backporting guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#how-to-backport-pull-requests) and cherry-pick with the `-x` flag. -This requires changes to the unstable `master` and `staging` branches first, before backporting them. - -Occasionally, it is not possible to cherry-pick exactly the same patch. -This most frequently happens when resolving merge conflicts or when updating minor versions of packages which have already advanced to the next major on unstable. -If you need to merge this PR despite the warnings, please [dismiss](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/dismissing-a-pull-request-review) this review shortly before merging. diff --git a/ci/github-script/commits.js b/ci/github-script/commits.js index f22034ea788d..82fedd608b06 100644 --- a/ci/github-script/commits.js +++ b/ci/github-script/commits.js @@ -23,21 +23,35 @@ module.exports = async function ({ github, context, core, dry }) { pull_number async function extract({ sha, commit }) { + const noCherryPick = Array.from( + commit.message.matchAll(/^Not-cherry-picked-because: (.*)$/g) + ).at(0) + + if (noCherryPick) + return { + sha, + commit, + severity: 'important', + message: `${sha} is not a cherry-pick, because: ${noCherryPick[1]}. Please review this commit manually.`, + type: 'no-cherry-pick', + } + // Using the last line with "cherry" + hash, because a chained backport // can result in multiple of those lines. Only the last one counts. - const match = Array.from( + const cherry = Array.from( commit.message.matchAll(/cherry.*([0-9a-f]{40})/g), ).at(-1) - if (!match) + if (!cherry) return { sha, commit, severity: 'warning', message: `Couldn't locate original commit hash in message of ${sha}.`, + type: 'no-commit-hash', } - const original_sha = match[1] + const original_sha = cherry[1] let branches try { @@ -121,6 +135,7 @@ module.exports = async function ({ github, context, core, dry }) { colored_diff, severity: 'warning', message: `Difference between ${sha} and original ${original_sha} may warrant inspection.`, + type: 'diff', } } @@ -202,10 +217,29 @@ module.exports = async function ({ github, context, core, dry }) { if (results.some(({ severity }) => severity == 'error')) process.exitCode = 1 - core.summary.addRaw( - await readFile(join(__dirname, 'check-cherry-picks.md'), 'utf-8'), - true, - ) + core.summary.addRaw('This report is automatically generated by the `PR / Check / cherry-pick` CI workflow.', true) + core.summary.addEOL() + core.summary.addRaw("Some of the commits in this PR require the author's and reviewer's attention.", true) + core.summary.addEOL() + + if (results.some(({ type }) => type === 'no-commit-hash')) { + core.summary.addRaw('Please follow the [backporting guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#how-to-backport-pull-requests) and cherry-pick with the `-x` flag.', true) + core.summary.addRaw('This requires changes to the unstable `master` and `staging` branches first, before backporting them.', true) + core.summary.addEOL() + core.summary.addRaw('Occasionally, commits are not cherry-picked at all, for example when updating minor versions of packages which have already advanced to the next major on unstable.', true) + core.summary.addRaw('These commits can optionally be marked with a `Not-cherry-picked-because: ` footer.', true) + core.summary.addEOL() + } + + if (results.some(({ type }) => type === 'diff')) { + core.summary.addRaw('Sometimes it is not possible to cherry-pick exactly the same patch.', true) + core.summary.addRaw('This most frequently happens when resolving merge conflicts.', true) + core.summary.addRaw('The range-diff will help to review the resolution of conflicts.', true) + core.summary.addEOL() + } + + core.summary.addRaw('If you need to merge this PR despite the warnings, please [dismiss](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/dismissing-a-pull-request-review) this review shortly before merging.', true) + results.forEach(({ severity, message, diff }) => { if (severity == 'info') return @@ -222,7 +256,7 @@ module.exports = async function ({ github, context, core, dry }) { // Whether this is intended or just an implementation detail is unclear. core.summary.addRaw('
') core.summary.addRaw( - `\n\n[!${severity == 'warning' ? 'WARNING' : 'CAUTION'}]`, + `\n\n[!${({ important: 'IMPORTANT', warning: 'WARNING', error: 'CAUTION' })[severity]}]`, true, ) core.summary.addRaw(`${message}`, true)