2023-11-21 15:39:11 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-08-20 07:38:38 +00:00
|
|
|
library 'status-jenkins-lib@v1.9.6'
|
2021-05-06 15:14:58 +00:00
|
|
|
|
2019-02-25 17:48:44 +00:00
|
|
|
pipeline {
|
2024-06-26 15:55:26 +00:00
|
|
|
agent { label 'linux && x86_64 && nix-2.19' }
|
2019-02-25 17:48:44 +00:00
|
|
|
|
|
|
|
parameters {
|
|
|
|
string(
|
|
|
|
name: 'BRANCH',
|
|
|
|
defaultValue: 'develop',
|
|
|
|
description: 'Name of branch to build.'
|
|
|
|
)
|
2023-11-21 15:39:11 +00:00
|
|
|
string(
|
|
|
|
name: 'UNIT_TEST_COUNT',
|
|
|
|
defaultValue: getDefaultUnitTestCount(),
|
|
|
|
description: 'How many times to run tests?'
|
|
|
|
)
|
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_FAILFAST',
|
2024-05-08 19:04:15 +00:00
|
|
|
defaultValue: !isTestNightlyJob(),
|
2023-11-21 15:39:11 +00:00
|
|
|
description: 'Should the job fail fast on first test failure?'
|
|
|
|
)
|
2024-02-26 15:04:20 +00:00
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_RERUN_FAILS',
|
2024-05-08 19:04:15 +00:00
|
|
|
defaultValue: !isTestNightlyJob(),
|
2024-02-26 15:04:20 +00:00
|
|
|
description: 'Should the job rerun failed tests?'
|
|
|
|
)
|
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_USE_DEVELOPMENT_LOGGER',
|
2024-05-08 19:04:15 +00:00
|
|
|
defaultValue: !isTestNightlyJob(),
|
2024-02-26 15:04:20 +00:00
|
|
|
description: 'Should the job use detailed logging for tests, potentially generating large logs?'
|
|
|
|
)
|
2024-05-08 08:25:01 +00:00
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_REPORT_CODECLIMATE',
|
2024-05-08 20:57:50 +00:00
|
|
|
defaultValue: true,
|
2024-05-08 08:25:01 +00:00
|
|
|
description: 'Should the job report test coverage to CodeClimate?'
|
|
|
|
)
|
2024-09-05 09:11:16 +00:00
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_REPORT_CODECOV',
|
|
|
|
defaultValue: true,
|
|
|
|
description: 'Should the job report test coverage to Codecov?'
|
|
|
|
)
|
2024-09-03 11:50:09 +00:00
|
|
|
booleanParam(
|
|
|
|
name: 'UNIT_TEST_DRY_RUN',
|
|
|
|
defaultValue: false,
|
|
|
|
description: 'Should the job report ignore the actual test run and just print the test plan?'
|
|
|
|
)
|
2019-02-25 17:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
options {
|
|
|
|
timestamps()
|
2024-06-21 00:34:44 +00:00
|
|
|
ansiColor('xterm')
|
2023-05-29 10:40:00 +00:00
|
|
|
/* Prevent Jenkins jobs from running forever */
|
2023-11-21 15:39:11 +00:00
|
|
|
timeout(time: getDefaultTimeout(), unit: 'MINUTES')
|
2019-02-25 17:48:44 +00:00
|
|
|
disableConcurrentBuilds()
|
|
|
|
/* manage how many builds we keep */
|
|
|
|
buildDiscarder(logRotator(
|
2024-08-20 07:03:10 +00:00
|
|
|
numToKeepStr: isTestNightlyJob() ? '14' : '5',
|
2019-02-25 17:48:44 +00:00
|
|
|
daysToKeepStr: '30',
|
2024-08-20 07:03:10 +00:00
|
|
|
artifactNumToKeepStr: isTestNightlyJob() ? '14' : '1',
|
2019-02-25 17:48:44 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
environment {
|
2024-08-13 09:58:48 +00:00
|
|
|
PLATFORM = 'tests'
|
|
|
|
DB_CONT = "status-go-test-db-${env.EXECUTOR_NUMBER.toInteger() + 1}"
|
|
|
|
DB_PORT = "${5432 + env.EXECUTOR_NUMBER.toInteger()}"
|
|
|
|
TMPDIR = "${WORKSPACE_TMP}"
|
|
|
|
GOPATH = "${WORKSPACE_TMP}/go"
|
|
|
|
GOCACHE = "${WORKSPACE_TMP}/gocache"
|
|
|
|
PATH = "${PATH}:${GOPATH}/bin"
|
|
|
|
REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go"
|
|
|
|
BASE_BRANCH = "${env.CHANGE_TARGET}"
|
2024-05-08 19:04:15 +00:00
|
|
|
|
2024-08-15 18:43:37 +00:00
|
|
|
NWAKU_CONT = "status-go-test-nwaku-${env.EXECUTOR_NUMBER.toInteger() + 1}"
|
|
|
|
NWAKU_TCP_PORT = "${60000 + env.EXECUTOR_NUMBER.toInteger()}"
|
|
|
|
NWAKU_UDP_PORT = "${9000 + env.EXECUTOR_NUMBER.toInteger()}"
|
|
|
|
NWAKU_REST_PORT = "${9645 + env.EXECUTOR_NUMBER.toInteger()}"
|
|
|
|
|
2024-05-08 19:04:15 +00:00
|
|
|
/* Hack-fix for params not being set in env on first job run. */
|
|
|
|
UNIT_TEST_FAILFAST = "${params.UNIT_TEST_FAILFAST}"
|
|
|
|
UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}"
|
|
|
|
UNIT_TEST_USE_DEVELOPMENT_LOGGER = "${params.UNIT_TEST_USE_DEVELOPMENT_LOGGER}"
|
|
|
|
UNIT_TEST_REPORT_CODECLIMATE = "${params.UNIT_TEST_REPORT_CODECLIMATE}"
|
2024-09-05 09:11:16 +00:00
|
|
|
UNIT_TEST_REPORT_CODECOV = "${params.UNIT_TEST_REPORT_CODECOV}"
|
2024-09-03 11:50:09 +00:00
|
|
|
UNIT_TEST_DRY_RUN = "${params.UNIT_TEST_DRY_RUN}"
|
2024-10-03 19:59:44 +00:00
|
|
|
|
|
|
|
/* prevent sharing cache dir across different jobs */
|
|
|
|
GO_GENERATE_FAST_DIR = "${env.WORKSPACE_TMP}/go-generate-fast"
|
2019-02-25 17:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
2022-12-02 18:03:35 +00:00
|
|
|
stage('Prep') {
|
|
|
|
steps { /* Go needs to find status-go in GOPATH. */
|
|
|
|
sh "mkdir -p \$(dirname ${REPO_SRC})"
|
|
|
|
sh "ln -s ${WORKSPACE} ${REPO_SRC}"
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 17:48:44 +00:00
|
|
|
|
2024-10-03 19:59:44 +00:00
|
|
|
stage('Generate') {
|
|
|
|
steps { script {
|
|
|
|
nix.shell('make generate', pure: false)
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2022-12-02 18:03:35 +00:00
|
|
|
stage('Vendor Check') {
|
|
|
|
steps { script {
|
|
|
|
nix.shell('make vendor', pure: false)
|
|
|
|
/* fail build if vendoring hasn't been done */
|
|
|
|
nix.shell('git diff --exit-code --no-color --stat vendor/')
|
|
|
|
} }
|
|
|
|
}
|
2019-02-25 17:48:44 +00:00
|
|
|
|
2024-04-10 10:31:37 +00:00
|
|
|
stage('Migration') {
|
|
|
|
when { // https://github.com/status-im/status-go/issues/4993#issuecomment-2022685544
|
|
|
|
expression { !isTestNightlyJob() }
|
|
|
|
}
|
|
|
|
steps { script {
|
|
|
|
nix.shell('make migration-check', pure: false)
|
|
|
|
} }
|
|
|
|
}
|
2019-12-20 12:02:44 +00:00
|
|
|
|
2024-08-27 22:40:17 +00:00
|
|
|
stage('Commit') {
|
|
|
|
environment {
|
|
|
|
BASE_BRANCH = "${env.BASE_BRANCH}"
|
|
|
|
}
|
|
|
|
when { // https://github.com/status-im/status-go/issues/4993#issuecomment-2022685544
|
|
|
|
expression { !isTestNightlyJob() }
|
|
|
|
}
|
|
|
|
steps { script {
|
|
|
|
nix.shell('make commit-check', pure: false)
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2022-12-02 18:03:35 +00:00
|
|
|
stage('Lint') {
|
|
|
|
steps { script {
|
2023-08-18 12:09:04 +00:00
|
|
|
nix.shell('make lint', pure: true)
|
2022-12-02 18:03:35 +00:00
|
|
|
} }
|
|
|
|
}
|
2019-02-25 17:48:44 +00:00
|
|
|
|
2022-12-02 18:03:35 +00:00
|
|
|
stage('Canary') {
|
|
|
|
steps { script {
|
2023-08-18 12:09:04 +00:00
|
|
|
nix.shell('make canary-test', pure: true)
|
2022-12-02 18:03:35 +00:00
|
|
|
} }
|
|
|
|
}
|
2019-02-25 17:48:44 +00:00
|
|
|
|
2022-12-02 18:03:35 +00:00
|
|
|
stage('Unit Tests') {
|
2023-09-18 15:50:26 +00:00
|
|
|
environment {
|
|
|
|
TEST_POSTGRES_PORT = "${env.DB_PORT}"
|
2024-08-15 18:43:37 +00:00
|
|
|
NWAKU_REST_PORT = "${env.NWAKU_REST_PORT}"
|
2023-09-18 15:50:26 +00:00
|
|
|
}
|
2022-12-02 18:03:35 +00:00
|
|
|
steps { script {
|
2024-08-15 18:43:37 +00:00
|
|
|
def ipAddress = sh(script: "hostname -I | awk '{print \$1}'", returnStdout: true).trim()
|
2023-02-21 12:25:50 +00:00
|
|
|
db = docker.image('postgres:9.6-alpine').withRun([
|
|
|
|
"--name=${DB_CONT}",
|
2023-09-18 15:50:26 +00:00
|
|
|
"--env=POSTGRES_HOST_AUTH_METHOD=trust",
|
|
|
|
"--publish=${DB_PORT}:${DB_PORT}",
|
|
|
|
].join(' '), "-p ${DB_PORT}") { c ->
|
2024-08-15 18:43:37 +00:00
|
|
|
nwaku = docker.image('harbor.status.im/wakuorg/nwaku:latest').withRun([
|
|
|
|
"--name=${NWAKU_CONT}",
|
|
|
|
"--publish=${NWAKU_TCP_PORT}:${NWAKU_TCP_PORT}/tcp",
|
|
|
|
"--publish=${NWAKU_UDP_PORT}:${NWAKU_UDP_PORT}/udp",
|
|
|
|
"--publish=${NWAKU_REST_PORT}:8645/tcp"
|
|
|
|
].join(' '), [
|
|
|
|
"--tcp-port=${NWAKU_TCP_PORT}",
|
|
|
|
"--discv5-discovery=true",
|
|
|
|
"--cluster-id=16",
|
|
|
|
"--pubsub-topic=/waku/2/rs/16/32",
|
|
|
|
"--pubsub-topic=/waku/2/rs/16/64",
|
|
|
|
"--nat=extip:${ipAddress}",
|
|
|
|
"--discv5-discovery",
|
|
|
|
"--discv5-udp-port=${NWAKU_UDP_PORT}",
|
|
|
|
"--rest-address=0.0.0.0",
|
|
|
|
"--store",
|
|
|
|
"--filter",
|
|
|
|
"--lightpush"
|
|
|
|
].join(' ')) { c2 ->
|
|
|
|
withCredentials([
|
|
|
|
string(
|
|
|
|
credentialsId: 'codeclimate-test-reporter-id',
|
|
|
|
variable: 'CC_TEST_REPORTER_ID'
|
|
|
|
),
|
2024-09-05 09:11:16 +00:00
|
|
|
string(
|
|
|
|
credentialsId: 'codecov-repository-upload-token',
|
|
|
|
variable: 'CODECOV_TOKEN'
|
|
|
|
),
|
2024-08-15 18:43:37 +00:00
|
|
|
]) {
|
|
|
|
nix.shell('make test-unit V=1', pure: false)
|
|
|
|
}
|
|
|
|
sh "mv c.out test-coverage.out"
|
2024-09-05 09:11:16 +00:00
|
|
|
archiveArtifacts('report_*.xml, test_*.log, test-coverage.out, coverage/codeclimate.json, test-coverage.html, coverage_merged.out')
|
2024-05-08 08:25:01 +00:00
|
|
|
}
|
2022-12-02 18:03:35 +00:00
|
|
|
}
|
|
|
|
} }
|
2023-02-21 12:25:50 +00:00
|
|
|
post { cleanup { /* Leftover DB containers. */
|
|
|
|
sh "docker rm ${DB_CONT} || true"
|
2024-08-15 18:43:37 +00:00
|
|
|
sh "docker rm ${NWAKU_CONT} || true"
|
2023-02-21 12:25:50 +00:00
|
|
|
} }
|
2022-12-02 18:03:35 +00:00
|
|
|
}
|
2019-02-25 17:48:44 +00:00
|
|
|
} // stages
|
2023-01-03 14:40:45 +00:00
|
|
|
|
|
|
|
post {
|
2023-08-10 10:46:57 +00:00
|
|
|
always {
|
2024-02-26 15:04:20 +00:00
|
|
|
script {
|
2024-05-08 19:04:15 +00:00
|
|
|
env.PKG_URL = "${currentBuild.absoluteUrl}/consoleText"
|
2024-02-26 15:04:20 +00:00
|
|
|
|
2024-05-08 19:04:15 +00:00
|
|
|
if (isTestNightlyJob()) {
|
2024-09-03 11:50:09 +00:00
|
|
|
archiveArtifacts('report_*.xml, test_*.log, test-coverage.html, test-coverage.out, coverage/codeclimate.json')
|
2024-02-26 15:04:20 +00:00
|
|
|
}
|
|
|
|
if (params.UNIT_TEST_RERUN_FAILS) {
|
2024-09-03 11:50:09 +00:00
|
|
|
def rerunReports = findFiles(glob: 'report_rerun_fails_*.txt')
|
2024-02-26 15:04:20 +00:00
|
|
|
if (rerunReports.length > 0) {
|
2024-09-03 11:50:09 +00:00
|
|
|
archiveArtifacts('report_rerun_fails_*.txt')
|
2024-02-26 15:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-08 19:04:15 +00:00
|
|
|
junit(
|
2024-09-03 11:50:09 +00:00
|
|
|
testResults: 'report_*.xml',
|
2024-05-08 19:04:15 +00:00
|
|
|
skipOldReports: true,
|
|
|
|
skipPublishingChecks: true,
|
|
|
|
skipMarkingBuildUnstable: true
|
|
|
|
)
|
|
|
|
publishHTML(target: [
|
|
|
|
allowMissing: true,
|
|
|
|
alwaysLinkToLastBuild: true,
|
|
|
|
keepAll: true,
|
|
|
|
reportDir: 'reports',
|
|
|
|
reportFiles: 'test_stats.txt',
|
|
|
|
reportName: 'Reports',
|
|
|
|
reportTitles: 'Test Stats'
|
|
|
|
])
|
2024-02-26 15:04:20 +00:00
|
|
|
}
|
2023-08-10 10:46:57 +00:00
|
|
|
}
|
2023-01-03 14:40:45 +00:00
|
|
|
success { script { github.notifyPR(true) } }
|
2024-06-14 11:03:51 +00:00
|
|
|
failure {
|
|
|
|
script {
|
|
|
|
github.notifyPR(false)
|
2024-09-03 11:50:09 +00:00
|
|
|
archiveArtifacts('**/test_*.log')
|
2024-06-14 11:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-22 10:37:05 +00:00
|
|
|
cleanup {
|
|
|
|
dir(env.TMPDIR) { deleteDir() }
|
|
|
|
sh "make git-clean"
|
|
|
|
}
|
2023-01-03 14:40:45 +00:00
|
|
|
} // post
|
2019-02-25 17:48:44 +00:00
|
|
|
} // pipeline
|
2023-11-21 15:39:11 +00:00
|
|
|
|
2023-11-30 11:09:16 +00:00
|
|
|
def isTestNightlyJob() { env.JOB_BASE_NAME == 'tests-nightly' }
|
2023-11-21 15:39:11 +00:00
|
|
|
|
2023-11-30 11:09:16 +00:00
|
|
|
def getDefaultUnitTestCount() { isTestNightlyJob() ? '20' : '1' }
|
2023-11-21 15:39:11 +00:00
|
|
|
|
2024-03-26 16:00:17 +00:00
|
|
|
def getDefaultTimeout() { isTestNightlyJob() ? 5*60 : 50 }
|