forked from ghostery/ghostery-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
141 lines (128 loc) · 4.7 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
properties([
parameters([
booleanParam(name: 'WITH_CLIQZ_MASTER', defaultValue: false, description: 'Builds with latest Cliqz master')
])
])
node('docker') {
stage ('Checkout') {
checkout scm
}
def img
def artifacts = []
def uploadPath = "cdncliqz/update/ghostery/${env.BRANCH_NAME}"
stage('Build Docker Image') {
img = docker.build('ghostery/build', '--build-arg UID=`id -u` --build-arg GID=`id -g` .')
// clean workdir
sh 'rm -rf build ghostery-*'
}
stage('Build Extension') {
img.inside() {
withCache {
sh 'rm -rf build'
if (params.WITH_CLIQZ_MASTER) {
sh 'yarn add https://s3.amazonaws.com/cdncliqz/update/edge/ghostery/master/latest.tgz'
}
// make browser-core noisy
sh 'sed -i \'s/global.__DEV__/true/1\' node_modules/browser-core/build/core/console.js'
withGithubCredentials {
sh 'moab makezip'
}
// get the name of the firefox build
artifacts.add(sh(returnStdout: true, script: 'ls build/ | grep firefox').trim())
}
}
}
stage('Package Chrome') {
withGithubCredentials {
def chromeArtifact = sh(returnStdout: true, script: 'ls build/ | grep chrome').trim().replace('.zip', '')
echo "${chromeArtifact}"
sh """#!/bin/bash -l
set -x
set -e
rm -rf ${chromeArtifact}/
mkdir -p ${chromeArtifact}
unzip build/${chromeArtifact}.zip -d ${chromeArtifact}
tools/crxmake.sh ${chromeArtifact}/ ~/.ssh/id_rsa
mv ${chromeArtifact}.crx build/
"""
artifacts.add("${chromeArtifact}.crx")
}
}
stage('Upload Builds') {
withS3Credentials {
echo "${env.BRANCH_NAME}/${env.BUILD_NUMBER}"
def uploadLocation = "s3://${uploadPath}/"
currentBuild.description = uploadLocation
artifacts.each {
sh "aws s3 cp build/${it} ${uploadLocation} --acl public-read"
}
}
}
if (env.BRANCH_NAME == 'develop') {
stage('Publish Beta') {
artifacts.each {
if (it.contains('firefox')) {
// firefox artifact (zip) - sign for cliqz_beta
def artifactUrl = "https://s3.amazonaws.com/${uploadPath}/${it}"
build job: 'addon-repack', parameters: [
string(name: 'XPI_URL', value: artifactUrl),
string(name: 'XPI_SIGN_CREDENTIALS', value: '41572f9c-06aa-46f0-9c3b-b7f4f78e9caa'),
string(name: 'XPI_SIGN_REPO_URL', value: '[email protected]:cliqz/xpi-sign.git'),
string(name: 'CHANNEL', value: 'browser_beta')
]
} else if (it.contains('chrome')) {
withS3Credentials {
// publish chrome builds, also with 'latest' tag
def publishUrl = 's3://cdncliqz/update/ghostery_beta/chrome';
sh "aws s3 cp build/${it} ${publishUrl}/${it} --acl public-read"
sh "aws s3 cp build/${it} ${publishUrl}/latest.crx --acl public-read"
}
}
}
}
}
}
def withCache(Closure body=null) {
def cleanCache = {
sh 'rm -fr node_modules'
}
try {
cleanCache()
// Main dependencies
sh 'cp -fr /home/jenkins/node_modules .'
body()
} finally {
cleanCache()
}
}
def withGithubCredentials(Closure body) {
withCredentials([sshUserPrivateKey(
credentialsId: '6739a36f-0b19-4f4d-b6e4-b01d0bc2e175',
keyFileVariable: 'GHOSTERY_CI_SSH_KEY')
]) {
// initialise git+ssh access using ghostery-ci credentials
try {
sh '''#!/bin/bash -l
set -x
set -e
mkdir -p ~/.ssh
cp $GHOSTERY_CI_SSH_KEY ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
'''
body()
} finally {
sh 'rm -f ~/.ssh/id_rsa'
sh 'rm -f ~/.ssh/known_hosts'
}
}
}
def withS3Credentials(Closure body) {
withCredentials([[
$class: 'UsernamePasswordMultiBinding',
credentialsId: '06ec4a34-9d01-46df-9ff8-64c79eda8b14',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID']]) {
body()
}
}