Skip to content

Commit 8ac93a9

Browse files
committed
fix(ci): Do no run tests on a release commit
Running tests on a release commit is too time consuming for this repo. This commit adds a parent stage that can skip all tests with a `when` clause, provided that the release commit title matches exactly what semantic-release puts out, and that the commiter is our bot (so that someone can't add a commit title that looks like a release commit, but skips CI). It's important to not the use of `git log` to get the top commit. Previous version of this use the Jenkins `changelog` feature. However, the value of that is ALL commits, not just the first one. When doing upstream merges, this can include hundreds of commits that we don't want subjected to this logic. Furthermore, `changelog` is no populated when a branch/PR is first pushed which renders it useless. Ref: LOG-19679
1 parent 73bdcaa commit 8ac93a9

File tree

1 file changed

+118
-105
lines changed

1 file changed

+118
-105
lines changed

Jenkinsfile

+118-105
Original file line numberDiff line numberDiff line change
@@ -58,143 +58,156 @@ pipeline {
5858
VECTOR_TARGET = "${BRANCH_BUILD}-target"
5959
VECTOR_CARGO_CACHE = "${BRANCH_BUILD}-cargo"
6060
VECTOR_RUSTUP_CACHE = "${BRANCH_BUILD}-rustup"
61+
TOP_COMMIT = sh(
62+
script: 'git log --pretty="format:%s by %cn" HEAD | head -1',
63+
returnStdout: true
64+
).trim()
6165
}
6266
stages {
63-
stage('Release Tool') {
64-
steps {
65-
sh 'make release-tool'
66-
}
67-
}
68-
stage('Lint and test release'){
69-
tools {
70-
nodejs 'NodeJS 20'
71-
}
72-
environment {
73-
GIT_BRANCH = "${CURRENT_BRANCH}"
74-
// This is not populated on PR builds and is needed for the release dry runs
75-
BRANCH_NAME = "${CURRENT_BRANCH}"
76-
CHANGE_ID = ""
67+
stage('Continue?') {
68+
// Do not run the stages on a release commit, unless it's for a sanity build.
69+
when {
70+
anyOf {
71+
expression { !(env.TOP_COMMIT ==~ /^chore\(release\): \d+\.\d+\.\d+ \[skip ci\] by LogDNA Bot$/) }
72+
environment name: 'SANITY_BUILD', value: 'true'
73+
}
7774
}
78-
steps {
79-
script {
80-
configFileProvider(NPMRC) {
81-
sh 'npm ci'
82-
sh 'npm run release:dry'
75+
stages {
76+
stage('Release Tool') {
77+
steps {
78+
sh 'make release-tool'
8379
}
8480
}
85-
sh './release-tool lint'
86-
sh './release-tool test'
87-
}
88-
}
89-
stage('Unit test'){
90-
// Important: do one step serially since it'll be the one to prepare the testing container
91-
// and install the rust toolchain in it. Volume mounts are created here, too.
92-
steps {
93-
sh """
94-
make test ENVIRONMENT=true
95-
"""
96-
}
97-
}
98-
stage('Checks') {
99-
// All `make ENVIRONMENT=true` steps should now use the existing container
100-
parallel {
101-
stage('check-clippy'){
81+
stage('Lint and test release'){
82+
tools {
83+
nodejs 'NodeJS 20'
84+
}
85+
environment {
86+
GIT_BRANCH = "${CURRENT_BRANCH}"
87+
// This is not populated on PR builds and is needed for the release dry runs
88+
BRANCH_NAME = "${CURRENT_BRANCH}"
89+
CHANGE_ID = ""
90+
}
10291
steps {
103-
sh """
104-
make check-clippy ENVIRONMENT=true
105-
make check-scripts ENVIRONMENT=true
106-
"""
92+
script {
93+
configFileProvider(NPMRC) {
94+
sh 'npm ci'
95+
sh 'npm run release:dry'
96+
}
97+
}
98+
sh './release-tool lint'
99+
sh './release-tool test'
107100
}
108101
}
109-
stage('check-fmt'){
110-
// Important: do this step serially since it'll be the one to prepare the testing container
102+
stage('Unit test'){
103+
// Important: do one step serially since it'll be the one to prepare the testing container
111104
// and install the rust toolchain in it. Volume mounts are created here, too.
112105
steps {
113106
sh """
114-
make check ENVIRONMENT=true
115-
make check-fmt ENVIRONMENT=true
107+
make test ENVIRONMENT=true
116108
"""
117109
}
118110
}
119-
stage('check-deny'){
120-
steps {
121-
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
122-
sh """
123-
make check-deny ENVIRONMENT=true
124-
"""
111+
stage('Checks') {
112+
// All `make ENVIRONMENT=true` steps should now use the existing container
113+
parallel {
114+
stage('check-clippy'){
115+
steps {
116+
sh """
117+
make check-clippy ENVIRONMENT=true
118+
make check-scripts ENVIRONMENT=true
119+
"""
120+
}
121+
}
122+
stage('check-fmt'){
123+
steps {
124+
sh """
125+
make check ENVIRONMENT=true
126+
make check-fmt ENVIRONMENT=true
127+
"""
128+
}
129+
}
130+
stage('check-deny'){
131+
steps {
132+
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
133+
sh """
134+
make check-deny ENVIRONMENT=true
135+
"""
136+
}
137+
}
138+
}
139+
stage('image test') {
140+
when {
141+
changeRequest() // Only do this during PRs because it can take 30 minutes
142+
}
143+
steps {
144+
script {
145+
buildx.build(
146+
project: PROJECT_NAME
147+
, push: false
148+
, tags: [BRANCH_BUILD]
149+
, dockerfile: "distribution/docker/mezmo/Dockerfile"
150+
)
151+
}
152+
}
125153
}
126154
}
127155
}
128-
stage('image test') {
156+
stage('Feature build and publish') {
129157
when {
130-
changeRequest() // Only do this during PRs because it can take 30 minutes
158+
expression {
159+
CURRENT_BRANCH ==~ /feature\/LOG-\d+/
160+
}
131161
}
132162
steps {
133163
script {
164+
def tag = slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}")
134165
buildx.build(
135166
project: PROJECT_NAME
136-
, push: false
137-
, tags: [BRANCH_BUILD]
167+
, push: true
168+
, tags: [tag]
138169
, dockerfile: "distribution/docker/mezmo/Dockerfile"
139170
)
140171
}
172+
sh './release-tool clean'
173+
sh './release-tool build'
174+
sh './release-tool publish'
141175
}
142176
}
143-
}
144-
}
145-
stage('Feature build and publish') {
146-
when {
147-
expression {
148-
CURRENT_BRANCH ==~ /feature\/LOG-\d+/
149-
}
150-
}
151-
steps {
152-
script {
153-
def tag = slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}")
154-
buildx.build(
155-
project: PROJECT_NAME
156-
, push: true
157-
, tags: [tag]
158-
, dockerfile: "distribution/docker/mezmo/Dockerfile"
159-
)
160-
}
161-
sh './release-tool clean'
162-
sh './release-tool build'
163-
sh './release-tool publish'
164-
}
165-
}
166-
stage('Release and publish') {
167-
when {
168-
branch DEFAULT_BRANCH
169-
not {
170-
environment name: 'SANITY_BUILD', value: 'true'
171-
}
172-
}
173-
tools {
174-
nodejs 'NodeJS 20'
175-
}
176-
steps {
177-
script {
178-
configFileProvider(NPMRC) {
179-
sh 'npm ci'
180-
sh 'npm run release'
177+
stage('Release and publish') {
178+
when {
179+
branch DEFAULT_BRANCH
180+
not {
181+
environment name: 'SANITY_BUILD', value: 'true'
182+
}
183+
}
184+
tools {
185+
nodejs 'NodeJS 20'
181186
}
187+
steps {
188+
script {
189+
configFileProvider(NPMRC) {
190+
sh 'npm ci'
191+
sh 'npm run release'
192+
}
182193

183-
def tag = sh (
184-
script: "./release-tool debug-RELEASE_VERSION",
185-
returnStdout: true
186-
).split(' = ')[1].trim()
194+
def tag = sh (
195+
script: "./release-tool debug-RELEASE_VERSION",
196+
returnStdout: true
197+
).split(' = ')[1].trim()
187198

188-
buildx.build(
189-
project: PROJECT_NAME
190-
, push: true
191-
, tags: [tag]
192-
, dockerfile: "distribution/docker/mezmo/Dockerfile"
193-
)
199+
buildx.build(
200+
project: PROJECT_NAME
201+
, push: true
202+
, tags: [tag]
203+
, dockerfile: "distribution/docker/mezmo/Dockerfile"
204+
)
205+
}
206+
sh './release-tool clean'
207+
sh './release-tool build'
208+
sh './release-tool publish'
209+
}
194210
}
195-
sh './release-tool clean'
196-
sh './release-tool build'
197-
sh './release-tool publish'
198211
}
199212
}
200213
}

0 commit comments

Comments
 (0)