|
| 1 | +name: Comment on V8 backports to the main branch |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened] |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + comment: |
| 13 | + name: Comment on V8 backports to the main branch |
| 14 | + # A triager/collaborator can add the v8-backport-to-main label when opening the pull |
| 15 | + # request to skip the comment when it is already known to meet the criteria. |
| 16 | + if: >- |
| 17 | + github.run_attempt == 1 && |
| 18 | + github.event.pull_request.user.type != 'Bot' && |
| 19 | + github.repository == 'nodejs/node' && |
| 20 | + !startsWith(github.event.pull_request.title, 'Revert ') && |
| 21 | + !contains(github.event.pull_request.labels.*.name, 'v8-backport-to-main') |
| 22 | + runs-on: ubuntu-slim |
| 23 | + permissions: |
| 24 | + pull-requests: write |
| 25 | + steps: |
| 26 | + - name: Check whether the pull request is a backport of individual V8 patches |
| 27 | + id: check |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ github.token }} |
| 30 | + NUMBER: ${{ github.event.pull_request.number }} |
| 31 | + run: | |
| 32 | + # Major and patch updates to V8 would update deps/v8/include/v8-version.h, |
| 33 | + # while individual backports do not. |
| 34 | + # The API lists at most 3000 files sorted by path. The version header |
| 35 | + # should appear early enough to show up within the limit even for major updates. |
| 36 | + gh api --paginate \ |
| 37 | + "/repos/$GITHUB_REPOSITORY/pulls/$NUMBER/files?per_page=100" > files.json |
| 38 | + files=$(jq -r '.[].filename' files.json) |
| 39 | + if printf '%s\n' "$files" | grep -q '^deps/v8/' && |
| 40 | + ! printf '%s\n' "$files" | grep -qx 'deps/v8/include/v8-version.h'; then |
| 41 | + echo 'is_backport=true' >> "$GITHUB_OUTPUT" |
| 42 | + else |
| 43 | + echo 'is_backport=false' >> "$GITHUB_OUTPUT" |
| 44 | + fi |
| 45 | + # Check if the patch bumps v8_embedder_string in common.gypi. |
| 46 | + if jq -r '.[] | select(.filename == "common.gypi") | .patch // ""' files.json | |
| 47 | + grep -q '^+.*v8_embedder_string'; then |
| 48 | + echo 'bumps_embedder_string=true' >> "$GITHUB_OUTPUT" |
| 49 | + else |
| 50 | + echo 'bumps_embedder_string=false' >> "$GITHUB_OUTPUT" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Comment with V8 backport guidance |
| 54 | + if: steps.check.outputs.is_backport == 'true' |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ github.token }} |
| 57 | + NUMBER: ${{ github.event.pull_request.number }} |
| 58 | + BUMPS_EMBEDDER_STRING: ${{ steps.check.outputs.bumps_embedder_string }} |
| 59 | + # GitHub renders line breaks as-is, so keep each paragraph on a single line. |
| 60 | + MESSAGE: |- |
| 61 | + Hi! This pull request changes `deps/v8` on the `main` branch without updating the V8 version, so you are likely submitting a backport of individual V8 patches. |
| 62 | +
|
| 63 | + In general we recommend waiting for a V8 patch to be included in the next V8 major version update instead of fast-tracking it, since individual backports add audit cost and can delay the major update. |
| 64 | +
|
| 65 | + A patch may be backported to `main` when at least one of these criteria applies: |
| 66 | +
|
| 67 | + * It fixes a build issue on a platform or toolchain supported on `main`. |
| 68 | + * It fixes a security issue. |
| 69 | + * It unblocks a pending V8 update, for example by adjusting how the Node.js code uses a V8 API so that it works with the future update. |
| 70 | +
|
| 71 | + If the patch has demonstrated real-world urgency and impact that justifies landing it before the next V8 major version update, it's recommended to backport it to the release staging branches like `v<MAJOR>.x-staging` (see [Criteria for backporting](https://github.com/nodejs/node/blob/HEAD/doc/contributing/backporting-to-release-lines.md#criteria-for-backporting) to decide what release line to target) instead of `main`. |
| 72 | +
|
| 73 | + Please explain in the pull request description which of these criteria applies. Otherwise, consider closing this pull request and waiting for the next V8 update instead of fast-tracking a backport. See [Backporting patches to `main`](https://github.com/nodejs/node/blob/HEAD/doc/contributing/maintaining/maintaining-V8.md#backporting-patches-to-main) for details. |
| 74 | + EMBEDDER_STRING_MESSAGE: |- |
| 75 | + Additional note: This pull request does not appear to bump `v8_embedder_string` in `common.gypi`. Backports of V8 patches should increment it. `git node v8 backport` from [`@node-core/utils`](https://github.com/nodejs/node-core-utils) does this automatically. |
| 76 | + run: | |
| 77 | + { |
| 78 | + printf '%s\n' "$MESSAGE" |
| 79 | + if [ "$BUMPS_EMBEDDER_STRING" != 'true' ]; then |
| 80 | + printf '\n%s\n' "$EMBEDDER_STRING_MESSAGE" |
| 81 | + fi |
| 82 | + } | gh pr comment "$NUMBER" --repo "$GITHUB_REPOSITORY" --body-file - |
0 commit comments