Skip to content
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

Merged
merged 45 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
889a049
wip storybooks
brianseeders Jan 6, 2021
688ef0f
WIP storybook building and uploading
brianseeders Jan 7, 2021
a853aaa
Switch variable to function
brianseeders Jan 7, 2021
de28159
Fix path
brianseeders Jan 7, 2021
12409da
Don't try to set individual object permissions
brianseeders Jan 7, 2021
c3dc05a
Add showInline
brianseeders Jan 7, 2021
2fccd8a
Make storybook assets relative paths
brianseeders Jan 7, 2021
c447a9d
Build canvas dll
brianseeders Jan 7, 2021
9da83af
Change canvas asset paths also
brianseeders Jan 7, 2021
d7d00ad
Build all storybooks
brianseeders Jan 7, 2021
9cc3944
Add storybooks pr comment link
brianseeders Jan 7, 2021
922ba2c
Use gsutil for upload storybooks assets
brianseeders Jan 11, 2021
6c5dca5
Quiet gsutil and add more compressable file types
brianseeders Jan 11, 2021
b54b34c
Add github commit status for storybooks
brianseeders Jan 11, 2021
f442159
Change storybooks context and debug commit status
brianseeders Jan 11, 2021
705049a
Update context again and add toString() to URL
brianseeders Jan 11, 2021
b891071
Build all storybooks again
brianseeders Jan 11, 2021
5b1ed96
Re-enable full pipeline
brianseeders Jan 13, 2021
da8a193
Merge remote-tracking branch 'upstream/master' into storybooks-ci
brianseeders Jan 13, 2021
dbd0574
Limit storybook webpack parallelism in CI, and enable caching
brianseeders Jan 13, 2021
9f22779
Merge branch 'master' into storybooks-ci
kibanamachine Jan 20, 2021
99c4e31
Merge branch 'master' into storybooks-ci
kibanamachine Jan 20, 2021
02be1b2
Merge branch 'master' into storybooks-ci
kibanamachine Jan 20, 2021
acc5211
Merge branch 'master' into storybooks-ci
kibanamachine Jan 20, 2021
78fe140
Merge branch 'master' into storybooks-ci
kibanamachine Jan 29, 2021
7cdeeea
Add comment
brianseeders Jan 29, 2021
1ca927a
Add missing storybook
brianseeders Jan 29, 2021
ebf1003
Merge remote-tracking branch 'upstream/master' into storybooks-ci
brianseeders Jan 29, 2021
5791173
Merge branch 'master' into storybooks-ci
brianseeders Feb 1, 2021
48e88fd
Merge remote-tracking branch 'upstream/master' into storybooks-ci
brianseeders Feb 1, 2021
d186f39
Disable APM storybook in CI for now
brianseeders Feb 1, 2021
ccdc9dd
Remove set
brianseeders Feb 1, 2021
3738593
Merge branch 'master' into storybooks-ci
kibanamachine Feb 1, 2021
ba88a96
Merge branch 'master' into storybooks-ci
kibanamachine Feb 2, 2021
79cf59d
Merge branch 'master' into storybooks-ci
kibanamachine Feb 2, 2021
be66b50
Merge branch 'master' into storybooks-ci
kibanamachine Feb 4, 2021
6839c5e
Merge remote-tracking branch 'upstream/master' into storybooks-ci
brianseeders Feb 5, 2021
3c651d0
Fix license
brianseeders Feb 5, 2021
ce87f6a
Make sure eslint lints the .ci directory
brianseeders Feb 5, 2021
4f63800
Merge branch 'master' into storybooks-ci
kibanamachine Feb 8, 2021
f2e330b
Merge branch 'master' into storybooks-ci
kibanamachine Feb 10, 2021
1555c90
Merge branch 'master' into storybooks-ci
kibanamachine Feb 11, 2021
350a292
Merge remote-tracking branch 'upstream/master' into storybooks-ci
brianseeders Feb 16, 2021
ce4f34d
Merge branch 'storybooks-ci' of github.com:brianseeders/kibana into s…
brianseeders Feb 16, 2021
6752c65
Merge branch 'master' into storybooks-ci
kibanamachine Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .ci/.storybook/main.js
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
Copy link
Contributor

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.

.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;
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ node_modules
target
snapshots.js

!/.ci
!/.eslintrc.js
!.storybook

Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-storybook/lib/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ export const defaultConfig: StorybookConfig = {
typescript: {
reactDocgen: false,
},
webpackFinal: (config, options) => {
if (process.env.CI) {
config.parallelism = 4;
config.cache = true;
}
return config;
},
};
10 changes: 5 additions & 5 deletions packages/kbn-storybook/lib/templates/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

<!-- Added for Kibana shared dependencies -->
<script>
window.__kbnPublicPath__ = { 'kbn-ui-shared-deps': '/' };
window.__kbnPublicPath__ = { 'kbn-ui-shared-deps': '.' };
</script>
<script src="/kbn-ui-shared-deps.@elastic.js"></script>
<script src="/kbn-ui-shared-deps.js"></script>
<link href="/kbn-ui-shared-deps.css" rel="stylesheet" />
<link href="/kbn-ui-shared-deps.v7.light.css" rel="stylesheet" />
<script src="kbn-ui-shared-deps.@elastic.js"></script>
<script src="kbn-ui-shared-deps.js"></script>
<link href="kbn-ui-shared-deps.css" rel="stylesheet" />
<link href="kbn-ui-shared-deps.v7.light.css" rel="stylesheet" />
<!-- -->

<% if (typeof headHtmlSnippet !== 'undefined') { %> <%= headHtmlSnippet %> <% } %> <%
Expand Down
2 changes: 2 additions & 0 deletions src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* Side Public License, v 1.
*/

// Please also add new aliases to test/scripts/jenkins_storybook.sh
export const storybookAliases = {
apm: 'x-pack/plugins/apm/.storybook',
canvas: 'x-pack/plugins/canvas/storybook',
codeeditor: 'src/plugins/kibana_react/public/code_editor/.storybook',
ci_composite: '.ci/.storybook',
dashboard: 'src/plugins/dashboard/.storybook',
dashboard_enhanced: 'x-pack/plugins/dashboard_enhanced/.storybook',
data_enhanced: 'x-pack/plugins/data_enhanced/.storybook',
Expand Down
22 changes: 22 additions & 0 deletions test/scripts/jenkins_storybook.sh
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
6 changes: 4 additions & 2 deletions vars/githubCommitStatus.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def trackBuild(commit, context, Closure closure) {
}

// state: error|failure|pending|success
def create(sha, state, description, context) {
def create(sha, state, description, context, targetUrl = null) {
targetUrl = targetUrl ?: env.BUILD_URL

withGithubCredentials {
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
state: state,
description: description,
context: context,
target_url: env.BUILD_URL
target_url: targetUrl.toString()
])
}
}
Expand Down
9 changes: 9 additions & 0 deletions vars/githubPr.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newlines that end up in the list here cause the list to render much larger, which would be ideal to work around:

image

vs

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, it's actually getDocsChangesLink() that's inserting a blank newline when it's missing. I can still get it fixed in this PR

Copy link
Contributor

Choose a reason for hiding this comment

The 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()

Expand All @@ -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()}
Expand Down
1 change: 1 addition & 0 deletions vars/kibanaPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def allCiTasks() {
tasks.test()
tasks.functionalOss()
tasks.functionalXpack()
tasks.storybooksCi()
}
},
jest: {
Expand Down
83 changes: 83 additions & 0 deletions vars/storybooks.groovy
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")
Copy link
Contributor

Choose a reason for hiding this comment

The 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 /[a-z\-_]/i or something


def html = """
<html>
<body>
<h1>Storybooks</h1>
<p><a href="${getUrlForCommit()}/composite">Composite Storybook</a></p>
<h2>All</h2>
<ul>
${listHtml}
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
6 changes: 6 additions & 0 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ def functionalXpack(Map params = [:]) {
}
}

def storybooksCi() {
task {
storybooks.buildAndUpload()
}
}

return this
4 changes: 2 additions & 2 deletions x-pack/plugins/canvas/storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
This file is looked for by Storybook and included in the HEAD element
if it exists. This is how we load the DLL content into the Storybook UI.
-->
<script src="/dll.js"></script>
<link href="/dll.css" rel="stylesheet" />
<script src="dll.js"></script>
<link href="dll.css" rel="stylesheet" />