Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

111
tools/actions/commit-queue.sh Executable file
View File

@ -0,0 +1,111 @@
#!/bin/sh
set -xe
OWNER=$1
REPOSITORY=$2
shift 2
UPSTREAM=origin
DEFAULT_BRANCH=main
COMMIT_QUEUE_LABEL="commit-queue"
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
commit_queue_failed() {
pr=$1
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}"
# shellcheck disable=SC2154
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
echo "$body"
gh pr comment "$pr" --body "$body"
rm output
}
# TODO(mmarchini): should this be set with whoever added the label for each PR?
git config --local user.email "github-bot@iojs.org"
git config --local user.name "Node.js GitHub Bot"
for pr in "$@"; do
gh pr view "$pr" --json labels --jq ".labels" > labels.json
# Skip PR if CI was requested
if jq -e 'map(.name) | index("request-ci")' < labels.json; then
echo "pr ${pr} skipped, waiting for CI to start"
continue
fi
# Skip PR if CI is still running
if gh pr checks "$pr" | grep -q "\spending\s"; then
echo "pr ${pr} skipped, CI still running"
continue
fi
# Delete the commit queue label
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"
if jq -e 'map(.name) | index("commit-queue-squash")' < labels.json; then
MULTIPLE_COMMIT_POLICY="--fixupAll"
elif jq -e 'map(.name) | index("commit-queue-rebase")' < labels.json; then
MULTIPLE_COMMIT_POLICY=""
else
MULTIPLE_COMMIT_POLICY="--oneCommitMax"
fi
git node land --autorebase --yes $MULTIPLE_COMMIT_POLICY "$pr" >output 2>&1 || echo "Failed to land #${pr}"
# cat here otherwise we'll be suppressing the output of git node land
cat output
# TODO(mmarchini): workaround for ncu not returning the expected status code,
# if the "Landed in..." message was not on the output we assume land failed
if ! grep -q '. Post "Landed in .*/pull/'"${pr}" output; then
commit_queue_failed "$pr"
# If `git node land --abort` fails, we're in unknown state. Better to stop
# the script here, current PR was removed from the queue so it shouldn't
# interfere again in the future.
git node land --abort --yes
continue
fi
if [ -z "$MULTIPLE_COMMIT_POLICY" ]; then
start_sha=$(git rev-parse $UPSTREAM/$DEFAULT_BRANCH)
end_sha=$(git rev-parse HEAD)
commits="${start_sha}...${end_sha}"
if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then
commit_queue_failed "$pr"
continue
fi
else
# If there's only one commit, we can use the Squash and Merge feature from GitHub.
# TODO: use `gh pr merge` when the GitHub CLI allows to customize the commit title (https://github.com/cli/cli/issues/1023).
commit_title=$(git log -1 --pretty='format:%s')
commit_body=$(git log -1 --pretty='format:%b')
commit_head=$(grep 'Fetched commits as' output | cut -d. -f3 | xargs git rev-parse)
if ! commits="$(
jq -cn \
--arg title "${commit_title}" \
--arg body "${commit_body}" \
--arg head "${commit_head}" \
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' |\
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
--jq 'if .merged then .sha else halt_error end'
)"; then
commit_queue_failed "$pr"
continue
fi
fi
rm output
gh pr comment "$pr" --body "Landed in $commits"
[ -z "$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
done
rm -f labels.json

View File

@ -0,0 +1,130 @@
#!/bin/sh
set -xe
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-nodejs/node}
BOT_TOKEN=${BOT_TOKEN:-}
RELEASE_DATE=$1
RELEASE_LINE=$2
RELEASER=$3
if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
echo "Usage: $0 <RELEASE_DATE> <RELEASE_LINE>"
exit 1
fi
if [ -z "$GITHUB_REPOSITORY" ] || [ -z "$BOT_TOKEN" ]; then
echo "Invalid value in env for GITHUB_REPOSITORY and BOT_TOKEN"
exit 1
fi
if ! command -v node || ! command -v gh || ! command -v git || ! command -v awk; then
echo "Missing required dependencies"
exit 1
fi
git node release --prepare --skipBranchDiff --yes --releaseDate "$RELEASE_DATE"
HEAD_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
HEAD_SHA="$(git rev-parse HEAD^)"
TITLE="$(git log -1 --format=%s)"
TEMP_BODY="$(awk -v MAX_BODY_LENGTH="65536" \
"/^## ${RELEASE_DATE}/,/^<a id=/{ if (/^<a id=/) {exit;} if ((output_length += length(\$0)) > MAX_BODY_LENGTH) {exit 1;} print }" \
"doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md" || echo "…")"
# Create the proposal branch
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/git/refs" \
-f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$HEAD_SHA"
# Create the proposal PR
PR_URL="$(gh api \
--method POST \
--jq .html_url \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/pulls" \
-f "title=$TITLE" -f "body=$TEMP_BODY" -f "head=$HEAD_BRANCH" -f "base=v$RELEASE_LINE.x" -f draft=true)"
# Push the release commit to the proposal branch using `BOT_TOKEN` from the env
node --input-type=module - \
"$GITHUB_REPOSITORY" \
"$HEAD_BRANCH" \
"$HEAD_SHA" \
"$TITLE" \
"$(git log -1 HEAD --format=%b | awk -v PR_URL="$PR_URL" '{sub(/^PR-URL: TODO$/, "PR-URL: " PR_URL)} 1' || true)" \
"$(git show HEAD --diff-filter=d --name-only --format= || true)" \
"$(git show HEAD --diff-filter=D --name-only --format= || true)" \
<<'EOF'
const [,,
repo,
branch,
parentCommitSha,
commit_title,
commit_body,
modifiedOrAddedFiles,
deletedFiles,
] = process.argv;
import { readFileSync } from 'node:fs';
import util from 'node:util';
const query = `
mutation ($repo: String! $branch: String!, $parentCommitSha: GitObjectID!, $changes: FileChanges!, $commit_title: String!, $commit_body: String) {
createCommitOnBranch(input: {
branch: {
repositoryNameWithOwner: $repo,
branchName: $branch
},
message: {
headline: $commit_title,
body: $commit_body
},
expectedHeadOid: $parentCommitSha,
fileChanges: $changes
}) {
commit {
url
}
}
}
`;
const response = await fetch('https://api.github.com/graphql', {
method: 'POST',
headers: {
'Authorization': `bearer ${process.env.BOT_TOKEN}`,
},
body: JSON.stringify({
query,
variables: {
repo,
branch,
parentCommitSha,
commit_title,
commit_body,
changes: {
additions: modifiedOrAddedFiles.split('\n').filter(Boolean)
.map(path => ({ path, contents: readFileSync(path).toString('base64') })),
deletions: deletedFiles.split('\n').filter(Boolean),
}
},
})
});
if (!response.ok) {
console.log({statusCode: response.status, statusText: response.statusText});
process.exitCode ||= 1;
}
const data = await response.json();
if (data.errors?.length) {
throw new Error('Endpoint returned an error', { cause: data });
}
console.log(util.inspect(data, { depth: Infinity }));
EOF
gh pr edit "$PR_URL" --add-label release --add-label "v$RELEASE_LINE.x" --add-assignee "$RELEASER"

View File

@ -0,0 +1,72 @@
#!/usr/bin/env node
// Takes a stream of JSON objects as inputs, validates the CHANGELOG contains a
// line corresponding, then outputs the prURL value.
//
// Example:
// $ git log upstream/vXX.x...upstream/vX.X.X-proposal \
// --format='{"prURL":"%(trailers:key=PR-URL,valueonly,separator=)","title":"%s","smallSha":"%h"}' \
// | ./lint-release-proposal-commit-list.mjs "path/to/CHANGELOG.md" "$(git rev-parse upstream/vX.X.X-proposal)"
const [,, CHANGELOG_PATH, RELEASE_COMMIT_SHA] = process.argv;
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { createInterface } from 'node:readline';
// Creating the iterator early to avoid missing any data:
const stdinLineByLine = createInterface(process.stdin)[Symbol.asyncIterator]();
const changelog = await readFile(CHANGELOG_PATH, 'utf-8');
const commitListingStart = changelog.indexOf('\n### Commits\n');
let commitList;
if (commitListingStart === -1) {
// We're preparing a semver-major release.
commitList = changelog.replace(/(^.+\n### Semver-Major|\n### Semver-(Minor|Patch)) Commits\n/gs, '')
.replaceAll('**(SEMVER-MAJOR)** ', '');
} else {
const commitListingEnd = changelog.indexOf('\n\n<a', commitListingStart);
assert.notStrictEqual(commitListingEnd, -1);
commitList = changelog.slice(commitListingStart, commitListingEnd + 1);
}
// Normalize for consistent comparison
commitList = commitList
.replaceAll('**(SEMVER-MINOR)** ', '')
.replaceAll('\\', '');
let expectedNumberOfCommitsLeft = commitList.match(/\n\* \[/g)?.length ?? 0;
for await (const line of stdinLineByLine) {
const { smallSha, title, prURL } = JSON.parse(line);
if (smallSha === RELEASE_COMMIT_SHA.slice(0, 10)) {
assert.strictEqual(
expectedNumberOfCommitsLeft, 0,
'Some commits are listed without being included in the proposal, or are listed more than once',
);
continue;
}
const lineStart = commitList.indexOf(`\n* [[\`${smallSha}\`]`);
assert.notStrictEqual(lineStart, -1, `Cannot find ${smallSha} on the list`);
const lineEnd = commitList.indexOf('\n', lineStart + 1);
const colonIndex = title.indexOf(':');
const expectedCommitTitle = `${`**${title.slice(0, colonIndex)}`.replace('**Revert "', '_**Revert**_ "**')}**${title.slice(colonIndex)}`;
try {
assert(commitList.lastIndexOf(`/${smallSha})] - ${expectedCommitTitle} (`, lineEnd) > lineStart, `Commit title doesn't match`);
} catch (e) {
if (e?.code === 'ERR_ASSERTION') {
e.operator = 'includes';
e.expected = expectedCommitTitle;
e.actual = commitList.slice(lineStart + 1, lineEnd);
}
throw e;
}
assert.strictEqual(commitList.slice(lineEnd - prURL.length - 2, lineEnd), `(${prURL})`, `when checking ${smallSha} ${title}`);
expectedNumberOfCommitsLeft--;
console.log(prURL);
}
assert.strictEqual(expectedNumberOfCommitsLeft, 0, 'Release commit is not the last commit in the proposal');

52
tools/actions/merge.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/sh
# Requires [gh](https://cli.github.com/), [jq](https://jqlang.github.io), git, and grep. Also awk if you pass a URL.
# This script can be used to "purple-merge" PRs that are supposed to land as a single commit, using the "Squash and Merge" feature of GitHub.
# To land a PR with this tool:
# 1. Run `git node land <pr-id-or-url> --fixupAll`
# 2. Copy the hash of the commit at the top of the PR branch.
# 3. Run `tools/actions/merge.sh <pr-id-or-url> <commit-hash>`.
set -xe
pr=$1
commit_head=$2
shift 2 || { echo "Expected two arguments"; exit 1; }
OWNER=nodejs
REPOSITORY=node
if expr "X$pr" : 'Xhttps://github.com/[^/]\{1,\}/[^/]\{1,\}/pull/[0-9]\{1,\}' >/dev/null; then
OWNER="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $4 }')"
REPOSITORY="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $5 }')"
pr="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $7 }')"
elif ! expr "X$pr" : 'X[0-9]\{1,\}' >/dev/null; then
echo "The first argument should be the PR ID or URL"
fi
git log -1 HEAD --pretty='format:%B' | git interpret-trailers --parse --no-divider | \
grep -q -x "^PR-URL: https://github.com/$OWNER/$REPOSITORY/pull/$pr$" || {
echo "Invalid PR-URL trailer"
exit 1
}
git log -1 HEAD^ --pretty='format:%B' | git interpret-trailers --parse --no-divider | \
grep -q -x "^PR-URL: https://github.com/$OWNER/$REPOSITORY/pull/$pr$" && {
echo "Refuse to squash and merge a PR landing in more than one commit"
exit 1
}
commit_title=$(git log -1 --pretty='format:%s')
commit_body=$(git log -1 --pretty='format:%b')
commitSHA="$(
jq -cn \
--arg title "${commit_title}" \
--arg body "${commit_body}" \
--arg head "${commit_head}" \
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' |\
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
--jq 'if .merged then .sha else halt_error end'
)"
gh pr comment "$pr" --repo "$OWNER/$REPOSITORY" --body "Landed in $commitSHA"

11
tools/actions/rebase.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
set -xe
# shellcheck disable=SC2016
gh api graphql -F "prID=$(gh pr view "$1" --json id --jq .id || true)" -f query='
mutation RebasePR($prID: ID!) {
updatePullRequestBranch(input:{pullRequestId:$prID,updateMethod:REBASE}) {
clientMutationId
}
}'

29
tools/actions/start-ci.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
set -xe
REQUEST_CI_LABEL="request-ci"
REQUEST_CI_FAILED_LABEL="request-ci-failed"
for pr in "$@"; do
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
ci_started=yes
rm -f output;
ncu-ci run "$pr" >output 2>&1 || ci_started=no
cat output
if [ "$ci_started" = "no" ]; then
# Do we need to reset?
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
# shellcheck disable=SC2154
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
echo "$body"
gh pr comment "$pr" --body "$body"
rm output
fi
done;