Skip to content

Commit a7a185f

Browse files
authored
jenkins: relax check for trusted nodejs/node branches (#4052)
Only enforce the COMMIT_SHA_CHECK verification when: - The org/repo is not nodejs/node (i.e. outside of our project). - The org/repo is nodejs/node and the reference is for a pull request. Refs: #4046
1 parent 967103d commit a7a185f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

jenkins/scripts/node-test-commit-pre.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,28 @@ git status
2727
git rev-parse HEAD
2828
git rev-parse $REBASE_ONTO
2929

30-
# COMMIT_SHA_CHECK needs to be set in the job. Check that it looks like
31-
# a SHA and not some other git ref (e.g. branch ref)
32-
if ! echo "${COMMIT_SHA_CHECK}" | grep -qE '^[0-9a-fA-F]+$'; then
33-
echo "COMMIT_SHA_CHECK does not look like a SHA"
34-
exit 1
35-
fi
30+
# COMMIT_SHA_CHECK must be specified, unless the
31+
# org/repo is nodejs/node and the ref is not a GitHub pull request
32+
if [ -z "${COMMIT_SHA_CHECK}" ]; then
33+
if [ "${GITHUB_ORG}" != "nodejs" ] || [ "${REPO_NAME}" != "node" ] || echo "${GIT_REMOTE_REF}" | grep -qE '^(refs/)?pull/[0-9]+'; then
34+
echo "Error: Starting CI for ${GIT_REMOTE_REF} from ${GITHUB_ORG}/${REPO_NAME} is not allowed without a specified COMMIT_SHA_CHECK value"
35+
exit 1
36+
fi
37+
echo "Allowing ${GIT_REMOTE_REF} for ${GITHUB_ORG}/${REPO_NAME} without a specified COMMIT_SHA_CHECK"
38+
else
39+
# Check COMMIT_SHA_CHECK looks like a SHA and not some other git ref
40+
# (e.g. branch ref)
41+
if ! echo "${COMMIT_SHA_CHECK}" | grep -qE '^[0-9a-fA-F]+$'; then
42+
echo "Error: COMMIT_SHA_CHECK does not look like a SHA"
43+
exit 1
44+
fi
3645

37-
# Check that the gitref that is checked out hasn't been updated since
38-
# the job was requested.
39-
if [ "$(git rev-parse HEAD)" != "$(git rev-parse ${COMMIT_SHA_CHECK})" ]; then
40-
echo "HEAD does not match expected COMMIT_SHA_CHECK"
46+
# Check that the git ref that is checked out hasn't been updated since
47+
# the job was requested.
48+
if [ "$(git rev-parse HEAD)" != "$(git rev-parse ${COMMIT_SHA_CHECK})" ]; then
49+
echo "Error: HEAD does not match expected COMMIT_SHA_CHECK"
4150
exit 1
51+
fi
4252
fi
4353

4454
if [ -n "${REBASE_ONTO}" ]; then

0 commit comments

Comments
 (0)