-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CI] Build and publish storybooks #87701
Changes from 42 commits
889a049
688ef0f
a853aaa
de28159
12409da
c3dc05a
2fccd8a
c447a9d
9da83af
d7d00ad
9cc3944
922ba2c
6c5dca5
b54b34c
f442159
705049a
b891071
5b1ed96
da8a193
dbd0574
9f22779
99c4e31
02be1b2
acc5211
78fe140
7cdeeea
1ca927a
ebf1003
5791173
48e88fd
d186f39
ccdc9dd
3738593
ba88a96
79cf59d
be66b50
6839c5e
3c651d0
ce87f6a
4f63800
f2e330b
1555c90
350a292
ce4f34d
6752c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
const config = require('@kbn/storybook').defaultConfig; | ||
const aliases = require('../../src/dev/storybook/aliases.ts').storybookAliases; | ||
|
||
config.refs = {}; | ||
|
||
for (const alias of Object.keys(aliases).filter((a) => a !== 'ci_composite')) { | ||
// snake_case -> Title Case | ||
const title = alias | ||
.replace(/_/g, ' ') | ||
.split(' ') | ||
.map((n) => n[0].toUpperCase() + n.slice(1)) | ||
.join(' '); | ||
|
||
config.refs[alias] = { | ||
title: title, | ||
url: `${process.env.STORYBOOK_BASE_URL}/${alias}`, | ||
}; | ||
} | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ node_modules | |
target | ||
snapshots.js | ||
|
||
!/.ci | ||
!/.eslintrc.js | ||
!.storybook | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
source src/dev/ci_setup/setup_env.sh | ||
|
||
cd "$XPACK_DIR/plugins/canvas" | ||
node scripts/storybook --dll | ||
|
||
cd "$KIBANA_DIR" | ||
|
||
# yarn storybook --site apm # TODO re-enable after being fixed | ||
yarn storybook --site canvas | ||
yarn storybook --site ci_composite | ||
yarn storybook --site codeeditor | ||
yarn storybook --site dashboard | ||
yarn storybook --site dashboard_enhanced | ||
yarn storybook --site data_enhanced | ||
yarn storybook --site embeddable | ||
yarn storybook --site infra | ||
yarn storybook --site security_solution | ||
yarn storybook --site ui_actions_enhanced | ||
yarn storybook --site observability | ||
yarn storybook --site presentation |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,26 +169,34 @@ def getNextCommentMessage(previousCommentInfo = [:], isFinal = false) { | |
? getBuildStatusIncludingMetrics() | ||
: buildUtils.getBuildStatus() | ||
|
||
def storybooksUrl = buildState.get('storybooksUrl') | ||
def storybooksMessage = storybooksUrl ? "* [Storybooks Preview](${storybooksUrl})" : "* Storybooks not built" | ||
|
||
if (!isFinal) { | ||
storybooksMessage = storybooksUrl ? storybooksMessage : "* Storybooks not built yet" | ||
|
||
def failuresPart = status != 'SUCCESS' ? ', with failures' : '' | ||
messages << """ | ||
## :hourglass_flowing_sand: Build in-progress${failuresPart} | ||
* [continuous-integration/kibana-ci/pull-request](${env.BUILD_URL}) | ||
* Commit: ${getCommitHash()} | ||
${storybooksMessage} | ||
* This comment will update when the build is complete | ||
""" | ||
} else if (status == 'SUCCESS') { | ||
messages << """ | ||
## :green_heart: Build Succeeded | ||
* [continuous-integration/kibana-ci/pull-request](${env.BUILD_URL}) | ||
* Commit: ${getCommitHash()} | ||
${storybooksMessage} | ||
${getDocsChangesLink()} | ||
Comment on lines
+191
to
192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will get this fixed. I didn't notice before because it only happens if it's not the last link in the list (e.g. when there's a flaky suite) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, it's actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, my bad, makes sense. Thank you |
||
""" | ||
} else if(status == 'UNSTABLE') { | ||
def message = """ | ||
## :yellow_heart: Build succeeded, but was flaky | ||
* [continuous-integration/kibana-ci/pull-request](${env.BUILD_URL}) | ||
* Commit: ${getCommitHash()} | ||
${storybooksMessage} | ||
${getDocsChangesLink()} | ||
""".stripIndent() | ||
|
||
|
@@ -204,6 +212,7 @@ def getNextCommentMessage(previousCommentInfo = [:], isFinal = false) { | |
## :broken_heart: Build Failed | ||
* [continuous-integration/kibana-ci/pull-request](${env.BUILD_URL}) | ||
* Commit: ${getCommitHash()} | ||
${storybooksMessage} | ||
* [Pipeline Steps](${env.BUILD_URL}flowGraphTable) (look for red circles / failed steps) | ||
* [Interpreting CI Failures](https://www.elastic.co/guide/en/kibana/current/interpreting-ci-failures.html) | ||
${getDocsChangesLink()} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a tiny bit concerned about creating HTML with string concatenation, though our sources are pretty predictable it would be great if we could limit the character set to |
||
|
||
def html = """ | ||
<html> | ||
<body> | ||
<h1>Storybooks</h1> | ||
<p><a href="${getUrlForCommit()}/composite">Composite Storybook</a></p> | ||
<h2>All</h2> | ||
<ul> | ||
${listHtml} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this page? What is the composite storybook missing that this gives us? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want the links to the individual storybooks to be effectively hidden, so I built this index page to put in front of all of them. This seems particularly useful if you're only concerned about a particular storybook, because the composite takes a long time to load. |
||
</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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a draft PR (#80061) I started by making the aliases an object so that a
title
could be added. Doing this transformation would probably be fine if there were no title specified, but it would be better to allow a title. For instance here "apm" would end up as "Apm" where we want APM.