Skip to content

Commit 5e1a89c

Browse files
committed
generalize Jenkinsfile to be usable for multiple apps
Signed-off-by: Jakub Sokołowski <[email protected]>
1 parent ea274b1 commit 5e1a89c

File tree

3 files changed

+144
-274
lines changed

3 files changed

+144
-274
lines changed

Jenkinsfile

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env groovy
2+
3+
4+
def changesDetected = false
5+
6+
pipeline {
7+
agent { label 'linux' }
8+
9+
options {
10+
timestamps()
11+
/* Prevent Jenkins jobs from running forever */
12+
timeout(time: 10, unit: 'MINUTES')
13+
/* manage how many builds we keep */
14+
buildDiscarder(logRotator(
15+
numToKeepStr: '20',
16+
daysToKeepStr: '30',
17+
))
18+
disableConcurrentBuilds()
19+
}
20+
21+
parameters {
22+
choice(
23+
name: 'APP_NAME',
24+
description: 'Name of app from apps folder.',
25+
choices: choiceFromJobName(params.APP_NAME, ['connector', 'wallet']),
26+
)
27+
}
28+
29+
environment {
30+
PLATFORM = "${params.APP_NAME}"
31+
ZIP_NAME = utils.pkgFilename(
32+
type: 'Extension',
33+
version: 'none',
34+
arch: 'chrome',
35+
ext: 'zip',
36+
)
37+
}
38+
39+
stages {
40+
stage('Check Changed Files') {
41+
when {
42+
changeset(
43+
pattern: "apps/${params.APP_NAME}/**",
44+
comparator: "GLOB"
45+
)
46+
}
47+
steps {
48+
script {
49+
changesDetected = true
50+
}
51+
}
52+
}
53+
54+
stage('Install') {
55+
when { expression { changesDetected } }
56+
steps {
57+
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
58+
script {
59+
nix.shell(
60+
'pnpm install --frozen-lockfile',
61+
pure: false,
62+
entryPoint: "${env.WORKSPACE}/apps/${params.APP_NAME}/shell.nix"
63+
)
64+
}
65+
}
66+
}
67+
}
68+
69+
stage('Build') {
70+
when { expression { changesDetected } }
71+
steps {
72+
dir("${env.WORKSPACE}") {
73+
script {
74+
nix.shell(
75+
"pnpm turbo run build --filter=${params.APP_NAME}",
76+
pure: false,
77+
entryPoint: "${env.WORKSPACE}/apps/${params.APP_NAME}/shell.nix"
78+
)
79+
}
80+
}
81+
}
82+
}
83+
84+
stage('Zip') {
85+
when { expression { changesDetected } }
86+
steps {
87+
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
88+
zip(
89+
zipFile: env.ZIP_NAME,
90+
dir: 'build/chrome-mv3-prod',
91+
archive: false,
92+
)
93+
}
94+
}
95+
}
96+
97+
stage('Archive') {
98+
when { expression { changesDetected } }
99+
steps {
100+
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
101+
archiveArtifacts(
102+
artifacts: env.ZIP_NAME,
103+
fingerprint: true,
104+
)
105+
}
106+
}
107+
}
108+
109+
stage('Upload') {
110+
when { expression { changesDetected } }
111+
steps {
112+
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
113+
script {
114+
env.PKG_URL = s5cmd.upload(env.ZIP_NAME)
115+
}
116+
}
117+
}
118+
}
119+
}
120+
121+
post {
122+
success { script { if(changesDetected) { github.notifyPR(true) } } }
123+
failure { script { if(changesDetected) { github.notifyPR(false) } } }
124+
cleanup { cleanWs() }
125+
}
126+
}
127+
128+
List<String> moveToStart(List<String> original, String input) {
129+
original.split {it.equals(input)}.flatten()
130+
}
131+
132+
/* If job name contains one of choices make that the default(first). */
133+
def choiceFromJobName(String previousChoice, List defaultChoices) {
134+
if (previousChoice != null) {
135+
return moveToStart(defaultChoices, previousChoice)
136+
}
137+
def tokens = env.JOB_NAME.split('/')
138+
for (choice in defaultChoices) {
139+
if (tokens.contains(choice)) {
140+
return moveToStart(defaultChoices, choice)
141+
}
142+
}
143+
return defaultChoices
144+
}

apps/connector/Jenkinsfile

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)