generated from lit/lit-element-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Jenkinsfile
184 lines (171 loc) · 5.33 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
pipeline {
options {
timeout(time: 60, unit: 'MINUTES')
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5')
}
agent {
label 'linux-arm64-docker || arm64linux'
}
environment {
NODE_ENV = 'production'
TZ = "UTC"
}
stages {
stage('Check for typos') {
steps {
sh '''
curl -qsL https://github.com/crate-ci/typos/releases/download/v1.13.7/typos-v1.13.7-x86_64-unknown-linux-musl.tar.gz | tar xvzf - ./typos
curl -qsL https://github.com/halkeye/typos-json-to-checkstyle/releases/download/v0.1.1/typos-checkstyle-v0.1.1-x86_64 > typos-checkstyle && chmod 0755 typos-checkstyle
./typos --format json | ./typos-checkstyle - > checkstyle.xml || true
'''
}
post {
always {
recordIssues(tools: [checkStyle(id: 'typos', name: 'Typos', pattern: 'checkstyle.xml')])
}
}
}
stage('Install Dependencies') {
environment {
NODE_ENV = 'development'
}
steps {
sh 'asdf install'
sh 'npm ci'
sh 'npx playwright install'
}
}
stage('Lint') {
environment {
NODE_ENV = "development"
}
steps {
sh '''
npx eslint --format checkstyle . > eslint-results.json
npx stylelint --custom-formatter ./node_modules/stylelint-checkstyle-formatter src/**/*.css -o stylelint-results.json
'''
}
post {
always {
recordIssues(tools: [
esLint(pattern: 'eslint-results.json'),
styleLint(pattern: 'stylelint-results.json')
])
}
}
}
stage('Build') {
steps {
sh '''
npm run build --if-present
npm run build-storybook
'''
}
}
stage('Prep storybook for testing') {
steps {
sh 'npx http-server -p 6321 storybook-static &'
sh 'npx wait-on -v http://127.0.0.1:6321'
}
}
stage('Test') {
environment {
TARGET_URL = "http://127.0.0.1:6321"
}
steps {
sh '''
npx test-storybook --maxWorkers=2 --coverage --junit --ci
'''
}
post {
always {
junit('junit.xml')
}
}
}
stage('Coverage') {
// cobertura seems broken on infra, and we don't need to publish it from there
when { not { expression { infra.isInfra() } } }
steps {
sh 'npx nyc report --reporter=cobertura -t coverage/storybook --report-dir coverage/storybook'
}
post {
always {
recordCoverage name: 'coverage', sourceCodeRetention: 'NEVER', tools: [[parser: 'COBERTURA', pattern: 'coverage/storybook/cobertura-coverage.xml']]
}
}
}
stage('Deploy PR to preview site') {
when {
allOf{
changeRequest target: 'main'
// Only deploy to production from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
steps {
sh 'netlify-deploy --draft=true --siteName "jenkins-io-components" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./storybook-static'
}
post {
success {
recordDeployment('jenkins-infra', 'jenkins-io-components', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--jenkins-io-components.netlify.app")
}
failure {
recordDeployment('jenkins-infra', 'jenkins-io-components', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--jenkins-io-components.netlify.app")
}
}
}
stage('Deploy Production') {
when {
allOf {
branch "main"
// Only deploy to production from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
steps {
sh 'netlify-deploy --draft=false --siteName "jenkins-io-components" --title "Deploy" -d ./storybook-static'
}
post {
success {
recordDeployment('jenkins-infra', 'jenkins-io-components', env.GIT_COMMIT, 'success', 'https://jenkins-io-components.netlify.app', [environment: 'production'])
}
failure {
recordDeployment('jenkins-infra', 'jenkins-io-components', env.GIT_COMMIT, 'failure', 'https://jenkins-io-components.netlify.app', [environment: 'production'])
}
}
}
stage('Release') {
when {
allOf {
anyOf {
branch "main"
branch "beta"
}
// Only deploy to production from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NPM_TOKEN = credentials('jenkinsci-npm-token')
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'jenkins-io-components-ghapp',
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_TOKEN')]) {
sh 'npx semantic-release --repositoryUrl https://x-access-token:[email protected]/jenkins-infra/jenkins-io-components.git'
}
}
}
}
}
}