-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
148 lines (126 loc) · 5.66 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!groovy
properties([
parameters([
choice(
name: 'BUILD_TYPE',
// Build types. The first value in this list is the default, per
// https://stackoverflow.com/questions/47873401/.
choices: ['build', 'update-hypothesis-client'],
description: 'Build task to execute'
)
])
])
node {
deleteDir()
checkout scm
workspace = pwd()
// Git branch which releases are deployed from.
releaseFromBranch = "master"
sh "docker build -t hypothesis-browser-extension-tests ."
nodeEnv = docker.image("hypothesis-browser-extension-tests")
gitVersion = sh(
script: "git rev-parse --short HEAD",
returnStdout: true
).trim()
// Fetch tags because `git describe` uses them and the output from `git describe`
// is in turn used to produce the extension version number in `build/manifest.json`.
sh "git fetch --quiet --tags"
// Show version information in the build logs. This version string is used by
// `tools/settings.js` to generate the extension version.
sh "git describe"
stage('Setup') {
nodeEnv.inside("-e HOME=${workspace}") {
sh "yarn install"
}
}
if (params.BUILD_TYPE == 'update-hypothesis-client') {
stage('Update Hypothesis Client') {
nodeEnv.inside("-e HOME=${workspace}") {
// Update Hypothesis client and set the version of the extension
// to match the client release.
sh "yarn add hypothesis@latest --dev"
newClientVersion = sh(
script: """node -p 'require("./package.json").devDependencies.hypothesis.match(/[0-9.]+/)[0]'""",
returnStdout: true
).trim()
// nb. Any additional steps to test the new client release with
// the extension can go here.
sh "yarn version --no-git-tag-version --new-version ${newClientVersion}"
}
withCredentials([
usernamePassword(
credentialsId: 'github-jenkins-user',
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD'
)
]) {
tagAuthor = "${GIT_USERNAME} <${GIT_USERNAME}@hypothes.is>"
repoUrl = "https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/hypothesis/browser-extension"
sh "git config user.email ${GIT_USERNAME}@hypothes.is"
sh "git config user.name ${GIT_USERNAME}"
sh "git commit -a -m 'Update Hypothesis client to ${newClientVersion}'"
tagName = "v${newClientVersion}"
sh "git tag ${tagName}"
// Push the new commit to the source branch as well as the tag.
// Make the push atomic so that both will fail if the source
// branch has been updated since the build started.
sh "git push --atomic ${repoUrl} HEAD:${env.BRANCH_NAME} ${tagName}"
}
}
// Skip remaining pre-deploy steps.
//
// The `git push` to the source branch above will trigger a regular build which will in
// turn deploy an extension release with the new client version.
return
}
stage('Test') {
nodeEnv.inside("-e HOME=${workspace}") {
sh "make checkformatting lint test"
}
}
stage('Build Packages') {
nodeEnv.inside("-e HOME=${workspace}") {
sh "make SETTINGS_FILE=settings/chrome-qa.json dist/${gitVersion}-chrome-qa.zip"
sh "make SETTINGS_FILE=settings/chrome-prod.json dist/${gitVersion}-chrome-prod.zip"
sh "make SETTINGS_FILE=settings/firefox-qa.json dist/${gitVersion}-firefox-qa.xpi"
sh "make SETTINGS_FILE=settings/firefox-prod.json dist/${gitVersion}-firefox-prod.xpi"
}
}
if (params.BUILD_TYPE != "build") {
echo "Skipping deployment because this is not a regular build"
return
}
if (env.BRANCH_NAME != releaseFromBranch) {
echo "Skipping deployment because ${env.BRANCH_NAME} is not the ${releaseFromBranch} branch"
return
}
milestone()
stage('Upload Packages') {
nodeEnv.inside("-e HOME=${workspace}") {
withCredentials([
// Credentials for Chrome Web Store API calls.
// These are managed under the "Client Chrome Extension" project under the
// "Hypothes.is" organization in the Google Developers Console
// (https://console.developers.google.com/apis/credentials?project=client-chrome-extension)
usernamePassword(
credentialsId: 'chrome-webstore-client',
usernameVariable: 'CHROME_WEBSTORE_CLIENT_ID',
passwordVariable: 'CHROME_WEBSTORE_CLIENT_SECRET'),
// Refresh token for Chrome Web Store API calls.
// This is generated using the `tools/chrome-webstore-refresh-token` script.
string(
credentialsId: 'chrome-webstore-refresh-token',
variable: 'CHROME_WEBSTORE_REFRESH_TOKEN'),
// Credentials for addons.mozilla.org API calls.
// These are accessible/managed from https://addons.mozilla.org/en-GB/developers/addon/api/key/
// when logged into our shared Firefox account.
usernamePassword(
credentialsId: 'firefox-amo-key',
usernameVariable: 'FIREFOX_AMO_KEY',
passwordVariable: 'FIREFOX_AMO_SECRET'),
]) {
sh "tools/deploy"
}
}
}
}