forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorybooks.groovy
83 lines (67 loc) · 2.27 KB
/
storybooks.groovy
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
def getStorybooksBucket() {
return "ci-artifacts.kibana.dev/storybooks"
}
def getDestinationDir() {
return env.ghprbPullId ? "pr-${env.ghprbPullId}" : buildState.get('checkoutInfo').branch.replace("/", "__")
}
def getUrl() {
return "https://${getStorybooksBucket()}/${getDestinationDir()}"
}
def getUrlLatest() {
return "${getUrl()}/latest"
}
def getUrlForCommit() {
return "${getUrl()}/${buildState.get('checkoutInfo').commit}"
}
def upload() {
dir("built_assets/storybook") {
sh "mv ci_composite composite"
def storybooks = sh(
script: 'ls -1d */',
returnStdout: true
).trim()
.split('\n')
.collect { it.replace('/', '') }
.findAll { it != 'composite' }
def listHtml = storybooks.collect { """<li><a href="${getUrlForCommit()}/${it}">${it}</a></li>""" }.join("\n")
def html = """
<html>
<body>
<h1>Storybooks</h1>
<p><a href="${getUrlForCommit()}/composite">Composite Storybook</a></p>
<h2>All</h2>
<ul>
${listHtml}
</ul>
</body>
</html>
"""
writeFile(file: 'index.html', text: html)
withGcpServiceAccount.fromVaultSecret('secret/kibana-issues/dev/ci-artifacts-key', 'value') {
kibanaPipeline.bash("""
gsutil -q -m cp -r -z js,css,html,json,map,txt,svg '*' 'gs://${getStorybooksBucket()}/${getDestinationDir()}/${buildState.get('checkoutInfo').commit}/'
gsutil -h "Cache-Control:no-cache, max-age=0, no-transform" cp -z html 'index.html' 'gs://${getStorybooksBucket()}/${getDestinationDir()}/latest/'
""", "Upload Storybooks to GCS")
}
buildState.set('storybooksUrl', getUrlForCommit())
}
}
def build() {
withEnv(["STORYBOOK_BASE_URL=${getUrlForCommit()}"]) {
kibanaPipeline.bash('test/scripts/jenkins_storybook.sh', 'Build Storybooks')
}
}
def buildAndUpload() {
def sha = buildState.get('checkoutInfo').commit
def context = 'Build and Publish Storybooks'
githubCommitStatus.create(sha, 'pending', 'Building Storybooks', context)
try {
build()
upload()
githubCommitStatus.create(sha, 'success', 'Storybooks built', context, getUrlForCommit())
} catch(ex) {
githubCommitStatus.create(sha, 'error', 'Building Storybooks failed', context)
throw ex
}
}
return this