mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
build: auto start Jenkins CI via PR labels
Add an Action that will find every PR with the `request-ci` label and will start a Jenkins CI for each of these Pull Requests. The scheduler event is used to circumvent GitHub Actions limitations on Pull Requests from forks (where secrets are not accessible and the GITHUB_TOKEN is read-only). If the Action fails to start a CI, it will add a `request-ci-failed` label and will leave a comment with the error message from NCU. Fixes: https://github.com/nodejs/github-bot/issues/234 PR-URL: https://github.com/nodejs/node/pull/34089 Reviewed-By: Christian Clauss <cclauss@me.com>
This commit is contained in:
2 files changed
+118
No files matched your search
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
GITHUB_TOKEN=$1
|
||||
OWNER=$2
|
||||
REPOSITORY=$3
|
||||
API_URL=https://api.github.com
|
||||
REQUEST_CI_LABEL='request-ci'
|
||||
REQUEST_CI_FAILED_LABEL='request-ci-failed'
|
||||
shift 3
|
||||
|
||||
function issueUrl() {
|
||||
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
|
||||
}
|
||||
|
||||
function labelsUrl() {
|
||||
echo "$(issueUrl "${1}")/labels"
|
||||
}
|
||||
|
||||
function commentsUrl() {
|
||||
echo "$(issueUrl "${1}")/comments"
|
||||
}
|
||||
|
||||
for pr in "$@"; do
|
||||
curl -sL --request DELETE \
|
||||
--url "$(labelsUrl "$pr")"/"$REQUEST_CI_LABEL" \
|
||||
--header "authorization: Bearer ${GITHUB_TOKEN}" \
|
||||
--header 'content-type: application/json'
|
||||
|
||||
ci_started=yes
|
||||
rm -f output;
|
||||
ncu-ci run "$pr" >output 2>&1 || ci_started=no
|
||||
|
||||
if [ "$ci_started" == "no" ]; then
|
||||
# Do we need to reset?
|
||||
curl -sL --request PUT \
|
||||
--url "$(labelsUrl "$pr")" \
|
||||
--header "authorization: Bearer ${GITHUB_TOKEN}" \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{"labels": ["'"${REQUEST_CI_FAILED_LABEL}"'"]}'
|
||||
|
||||
jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" '{body: $content}' > output.json
|
||||
|
||||
curl -sL --request POST \
|
||||
--url "$(commentsUrl "$pr")" \
|
||||
--header "authorization: Bearer ${GITHUB_TOKEN}" \
|
||||
--header 'content-type: application/json' \
|
||||
--data @output.json
|
||||
|
||||
rm output.json;
|
||||
fi
|
||||
done;
|
||||
Reference in new issue
Block a user