-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pipelines: add lint-py to linter pipeline (#1745)
- Loading branch information
1 parent
cf5b76f
commit b8d5cf2
Showing
2 changed files
with
54 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,19 @@ pipeline { | |
string(name: 'GITHUB_ORG', defaultValue: 'nodejs', description: 'The user/org of the GitHub repo') | ||
string(name: 'REPO_NAME', defaultValue: 'node', description: 'The name of the repo') | ||
string(name: 'GIT_REMOTE_REF', defaultValue: 'refs/heads/master', description: 'The remote portion of the Git refspec to fetch and test') | ||
string(name: 'REBASE_ONTO', defaultValue: '', description: 'Optionally, rebase onto the given ref before testing. Leave blank to skip rebasing.') | ||
string(name: 'POST_REBASE_SHA1_CHECK', defaultValue: '', description: 'After rebasing, check that the resulting commit sha1 matches the given one. If left blank, no check is performed.') | ||
string(name: 'CONFIG_FLAGS', defaultValue: '', description: 'Add arguments to ./configure.') | ||
} | ||
|
||
stages { | ||
stage("Setup repository") { | ||
steps { | ||
checkout(poll: false, scm: [ | ||
checkout(changelog: false, poll: false, scm: [ | ||
$class: 'GitSCM', | ||
branches: [[ | ||
name: 'refs/heads/_jenkins_local_branch' | ||
]], | ||
userRemoteConfigs: [[ | ||
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c", | ||
url: "[email protected]:${params.GITHUB_ORG}/${params.REPO_NAME}", | ||
refspec: "+refs/heads/*:refs/remotes/origin/* +${params.GIT_REMOTE_REF}:refs/remotes/origin/_jenkins_local_branch" | ||
]] | ||
]) | ||
} | ||
|
@@ -38,19 +34,30 @@ pipeline { | |
} | ||
} | ||
|
||
|
||
stage('Build linting tools') { | ||
steps { | ||
// Calling with `returnStatus` suppresses automatic failures | ||
sh(script: "${env.MAKE} lint-md-build", returnStatus: true) | ||
sh(script: "${env.MAKE} lint-py-build", returnStatus: true) | ||
} | ||
} | ||
|
||
stage('Run tests') { | ||
steps { | ||
script { | ||
def node_version = sh(script: "python tools/getnodeversion.py", returnStdout: true).trim() | ||
echo node_version | ||
def node_version_parts = node_version.tokenize('.') | ||
def node_major = node_version_parts[0] as int | ||
def lint_py3_ret = 0 | ||
if (node_major > 11) { | ||
// this job does not build node, so we use the system's node | ||
lint_py3_ret = sh(script: "NODE=node PYTHON=python3 ${env.MAKE} lint-py", returnStatus: true) | ||
} | ||
// this job does not build node, so we use the system's node | ||
def ret = sh(script: "NODE=node ${env.MAKE} lint-ci", returnStatus: true) | ||
if (ret != 0) { | ||
if (ret != 0 || lint_py3_ret != 0) { | ||
echo(extractErrors()) | ||
error('lint failed - open above section for details') | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,53 +4,53 @@ pipeline { | |
agent { label 'jenkins-workspace' } | ||
parameters { | ||
booleanParam(name: 'CERTIFY_SAFE', defaultValue: false, description: 'I have reviewed *the latest version of* these changes and I am sure that they don’t contain any code that could compromise the security of the CI infrastructure.') | ||
string(name: 'GITHUB_ORG', defaultValue: 'nodejs', description: 'The user/org of the GitHub repo') | ||
string(name: 'REPO_NAME', defaultValue: 'node', description: 'The name of the repo') | ||
string(name: 'PR_ID', defaultValue: '', description: 'PR ID') | ||
string(name: 'REBASE_ONTO', defaultValue: '', description: 'Optionally, rebase onto the given ref before testing. Leave blank to skip rebasing.') | ||
string(name: 'CONFIG_FLAGS', defaultValue: '', description: 'Add arguments to ./configure.') | ||
} | ||
stages { | ||
stage("Setup repository") { | ||
steps { | ||
checkout(poll: false, scm: [ | ||
$class: 'GitSCM', | ||
branches: [[ | ||
name: 'refs/heads/_jenkins_local_branch' | ||
]], | ||
userRemoteConfigs: [[ | ||
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c", | ||
url: "[email protected]:${params.GITHUB_ORG}/${params.REPO_NAME}.git", | ||
refspec: "+refs/heads/*:refs/remotes/origin/* +${getBranchName(params)}:refs/remotes/origin/_jenkins_local_branch" | ||
]] | ||
]) | ||
checkout( | ||
changelog: false, | ||
poll: false, | ||
scm: [ | ||
$class: 'GitSCM', | ||
branches: [[ | ||
name: 'refs/heads/_jenkins_local_branch' | ||
]], | ||
userRemoteConfigs: [[ | ||
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c", | ||
url: "[email protected]:nodejs/node.git" | ||
]] | ||
] | ||
) | ||
} | ||
} | ||
|
||
stage('Preflight') { | ||
steps { | ||
checkCertify(params) | ||
setupGit(env, params) | ||
setupSubParams(env, params) | ||
script { | ||
if (!params.CERTIFY_SAFE) { | ||
error "Please certify that you have reviewed the changes to be tested, by ticking the CERTIFY_SAFE checkbox on the job launch page." | ||
} | ||
setupEnv(env, params) | ||
} | ||
} | ||
} | ||
|
||
stage('Run tests') { | ||
parallel { | ||
stage('Run linuxone') { | ||
steps { | ||
build(job: "node-test-commit-linuxone", | ||
parameters: setupSubParams(env, params), | ||
propagate: true) | ||
} | ||
} | ||
|
||
stage('Run linter') { | ||
steps { | ||
build(job: "node-linter", | ||
parameters: setupSubParams(env, params), | ||
propagate: true) | ||
} | ||
steps { | ||
script { | ||
def buildParams = setupSubParams(env, params) | ||
def testResult | ||
parallel( | ||
regressionTests: { | ||
testResult = build job: "node-test-commit-linuxone", parameters: buildParams, propagate: false | ||
}, | ||
linter: { | ||
build job: "node-linter", parameters: buildParams, propagate: true | ||
} | ||
) | ||
currentBuild.result = testResult.result | ||
} | ||
} | ||
} | ||
|
@@ -65,49 +65,22 @@ def getBranchName(params) { | |
} | ||
} | ||
|
||
def checkCertify(params) { | ||
if (!params.CERTIFY_SAFE) { | ||
echo "Please certify that you have reviewed the changes to be tested, by ticking the CERTIFY_SAFE checkbox on the job launch page." | ||
currentBuild.result = 'FAILURE' | ||
sh "exit 1" | ||
} | ||
} | ||
|
||
def setupGit(env, params) { | ||
sh ''' | ||
git config --replace-all user.name Dummy | ||
git config --replace-all user.email [email protected] | ||
git config user.name | ||
git config user.email | ||
echo $GIT_COMMITTER_NAME | ||
echo $GIT_AUTHOR_NAME | ||
git rebase --abort || true | ||
git checkout -f refs/remotes/origin/_jenkins_local_branch | ||
git status | ||
git rev-parse HEAD | ||
''' | ||
|
||
env.POST_REBASE_SHA1_CHECK = sh(script: "git rev-parse HEAD", returnStdout: true).trim() | ||
|
||
def node_version_from_branch = sh(script: "python tools/getnodeversion.py", returnStdout: true).trim() | ||
echo "Detected version from branch: ${node_version_from_branch}" | ||
|
||
env.NODE_MAJOR_VERSION = sh(script: "grep '^#define[[:space:]]*NODE_MAJOR_VERSION[[:space:]]' src/node_version.h | sed 's/^#define[[:space:]]*NODE_MAJOR_VERSION[[:space:]]*//'", returnStdout: true).trim() | ||
echo "Detected node major version: ${env.NODE_MAJOR_VERSION}" | ||
def setupEnv(env, params) { | ||
def node_version = sh(script: "python tools/getnodeversion.py", returnStdout: true).trim() | ||
echo "Detected node version: ${node_version}" | ||
def node_version_parts = node_version.tokenize('.') | ||
env.NODE_MAJOR_VERSION = node_version_parts[0] | ||
echo "NODE_MAJOR_VERSION=${env.NODE_MAJOR_VERSION}" | ||
} | ||
|
||
def setupSubParams(env, params) { | ||
def pr = [:] // Mutable copy of params. | ||
params.each{ key, value -> pr.put(key, value) } | ||
pr['NODES_SUBSET'] = "auto" | ||
pr['IGNORE_FLAKY_TESTS'] = "true" | ||
pr["POST_STATUS_TO_PR"] = "true" | ||
pr["GITHUB_ORG"] = "nodejs" | ||
pr["REPO_NAME"] = "node" | ||
pr["GIT_REMOTE_REF"] = getBranchName(params) | ||
pr["GIT_ORIGIN_SCHEME"] = "[email protected]:" | ||
pr['NODE_MAJOR_VERSION'] = env.NODE_MAJOR_VERSION | ||
pr['POST_REBASE_SHA1_CHECK'] = env.POST_REBASE_SHA1_CHECK | ||
|
||
p = [] | ||
for (param in pr) { | ||
|