nwaku/ci/Jenkinsfile.prs

139 lines
3.7 KiB
Plaintext
Raw Normal View History

library 'status-jenkins-lib@v1.6.0'
pipeline {
agent { label "${getAgentLabel()} && x86_64" }
parameters {
string(
name: 'NIMFLAGS',
description: 'Flags for Nim compilation.',
defaultValue: params.NIMFLAGS ?: [
'--colors:off',
'-d:insecure',
'-d:disableMarchNative',
'--parallelBuild:6',
].join(' ')
)
string(
name: 'LOG_LEVEL',
description: 'Build logging level. (DEBUG, TRACE)',
defaultValue: params.LOG_LEVEL ?: 'DEBUG'
)
string(
name: 'VERBOSITY',
description: 'Makefile verbosity level.(0-2)',
defaultValue: params.VERBOSITY ?: '1'
)
string(
name: 'MAKEFLAGS',
description: 'Makefile flags.',
defaultValue: params.MAKEFLAGS ?: '-j6'
)
booleanParam(
name: 'EXPERIMENTAL',
description: 'Enable experimental features.',
defaultValue: false
)
}
options {
timestamps()
/* Prevent Jenkins jobs from running forever */
timeout(time: 30, unit: 'MINUTES')
/* Limit builds retained. */
buildDiscarder(logRotator(
numToKeepStr: '3',
daysToKeepStr: '30',
artifactNumToKeepStr: '1',
))
}
environment {
TARGET = getAgentLabel()
}
stages {
stage('Deps') { steps { script {
/* Avoid checking multiple times. */
v2changed = versionWasChanged('v2')
/* TODO: Re-add caching of Nim compiler. */
nix.shell("make ${params.MAKEFLAGS} V=${params.VERBOSITY} update", pure: false)
nix.shell("make ${params.MAKEFLAGS} V=${params.VERBOSITY} deps", pure: false)
} } }
stage('Binaries') {
parallel {
stage('V2') {
when { expression { v2changed } }
steps { script {
nix.shell("make ${params.MAKEFLAGS} NIMFLAGS=\"${params.NIMFLAGS}\" V=${params.VERBOSITY} EXPERIMENTAL=${params.EXPERIMENTAL} all")
} }
}
}
}
stage('Run Tests') {
parallel {
stage('V2') {
when { expression { v2changed } }
steps { script {
nix.shell("make ${params.MAKEFLAGS} NIMFLAGS=\"${params.NIMFLAGS}\" V=${params.VERBOSITY} EXPERIMENTAL=${params.EXPERIMENTAL} test")
} }
}
}
}
stage('Upload') {
when { expression { v2changed } }
steps { script {
def out = genOutputFilename()
sh "mv build/wakunode2 ${out}"
env.PKG_URL = s3.uploadArtifact(out)
jenkins.setBuildDesc(Waku: env.PKG_URL)
} }
}
} // stages
post {
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
always { cleanWs() }
} // post
} // pipeline
/* This allows us to use one Jenkinsfile and run
* jobs on different platforms based on job name. */
def getAgentLabel() {
if (params.AGENT_LABEL) {
return params.AGENT_LABEL
}
def tokens = env.JOB_NAME.split('/')
for (platform in ['linux', 'macos', 'windows']) {
if (tokens.contains(platform)) { return platform }
}
throw new Exception('No agent provided or found in job path!')
}
def genOutputFilename() {
return [
"wakunode2", utils.timestamp(), utils.gitCommit(), getAgentLabel()
].join('-') + (env.NODE_NAME.startsWith('windows') ? '.exe' : '.bin')
}
def versionWasChanged(version) {
def changes = sh(
script: "git diff --name-only origin/${env.CHANGE_TARGET}",
returnStdout: true
)
if (changes =~ "(?m)^(Makefile|waku.nimble|config.nims|vendor|ci|shell.nix).*") {
return true
}
2022-10-20 16:44:22 +00:00
if (version == 'v2' && changes =~ "(?m)^(apps|tools)/.*") {
return true
}
if (changes =~ "(?m)^(waku|tests|examples)/(${version}|common)/.*") {
return true
}
return false
}