Skip to content

Commit

Permalink
jenkins: linter refactor & fix for 6.x (#1349)
Browse files Browse the repository at this point in the history
* break down directive into single commands
* don't fail if `lint-md-build` doesn't exist
* replace `sed` with `awk`

PR-URL: #1349
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
  • Loading branch information
refack authored Aug 13, 2018
1 parent 126d197 commit 5a68cf1
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions jenkins/pipelines/node-linter.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pipeline {
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.')
choice(name: 'GIT_ORIGIN_SCHEME', choices: "https://github.com/\ngit@github.com:", description: '')
string(name: 'POST_STATUS_TO_PR', defaultValue: '', description: 'Posts build status updates to a nodejs/node PR.')
string(name: 'CONFIG_FLAGS', defaultValue: '', description: 'Add arguments to ./configure.')
}

Expand All @@ -23,33 +21,40 @@ pipeline {
]],
userRemoteConfigs: [[
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c",
url: "${params.GIT_ORIGIN_SCHEME}${params.GITHUB_ORG}/${params.REPO_NAME}",
url: "git@github.com:${params.GITHUB_ORG}/${params.REPO_NAME}",
refspec: "+refs/heads/*:refs/remotes/origin/* +${params.GIT_REMOTE_REF}:refs/remotes/origin/_jenkins_local_branch"
]]
])
}
}

stage('Preflight') {
stage('Pre-flight') {
steps {
sh "curl https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe"
sh "curl -L -s https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe"
sendBuildStatus("pending", env)
checkMake()
// Make sure we have a node binary in the path
sh 'node --version'
}
}

stage('Build linting tools') {
steps {
// Calling with `returnStatus` suppresses automatic failures
sh(script: "${env.MAKE} lint-md-build", returnStatus: true)
}
}

stage('Run tests') {
steps {
checkMake()
checkSed()
sh """
# this job does not build node, so we symlink the system's node
which node #&& ln -s ${sh(script: "which node", returnStdout: true).trim()}
node --version
${env.MAKE} lint-md-build || true
# If lint-ci fails, print all the interesting lines to the console.
${env.MAKE} lint-ci || { cat test-eslint.tap | grep -v '^ok\\|^TAP version 13\\|^1\\.\\.' | ${env.SED} '/^/\\s*\$/d' && exit 1; }
"""
script {
// 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) {
echo(extractErrors())
error('lint failed - open above section for details')
}
}
}
}
}
Expand All @@ -65,6 +70,23 @@ pipeline {
}
}

def extractErrors() {
def tap = readFile('test-eslint.tap')
tap = tap.replaceAll('(?m)^ok.*', '')
tap = tap.replaceAll('(?m)^TAP version 13.*', '')
tap = tap.replaceAll('(?m)^1\\.\\..*', '')
tap = tap.replaceAll('(?m)^\\s+$', '')
return tap
}

def tap2JUnit() {
fileOperations([folderCreateOperation('out/junit')])
def status = sh(returnStatus: true, script: 'tap2junit -i test-eslint.tap -o out/junit/test-eslint.xml')
if (status == 0) {
junit(allowEmptyResults: true, testResults: 'out/junit/*.xml')
}
}

def checkMake() {
def status = sh(returnStatus: true, script: "which gmake")
if (status != 0) {
Expand All @@ -74,14 +96,6 @@ def checkMake() {
}
}

def checkSed() {
def status = sh(returnStatus: true, script: "which gsed")
if (status != 0) {
env.SED = 'sed'
} else {
env.SED = 'gsed'
}
}

def sendBuildStatus(status, env) {
build job: 'post-build-status-update', parameters: [
Expand Down

0 comments on commit 5a68cf1

Please sign in to comment.