Skip to content

Commit 37a4e73

Browse files
authored
ci: keep persisten beta storybook (#5293)
* ci: keep persisten beta storybook * docs: add banner when beta version is available
1 parent 2c18676 commit 37a4e73

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches:
99
- main
10+
- beta
1011

1112
jobs:
1213
build:
@@ -215,7 +216,7 @@ jobs:
215216
- name: Export custom variables
216217
run: |
217218
SAFE_GITHUB_HEAD_REF_SLUG_URL=$(echo $GITHUB_HEAD_REF_SLUG_URL-$DEPLOYMENT_NAME | rev | cut -c-37 | rev | awk '{gsub(/^-/, ""); print}')
218-
([[ $GITHUB_REF == 'refs/heads/main' ]] && echo "STORYBOOK_BRANCH_SLUG=main" || echo "STORYBOOK_BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
219+
([[ $GITHUB_REF == 'refs/heads/main' || $GITHUB_REF == 'refs/heads/beta' ]] && echo "STORYBOOK_BRANCH_SLUG=$(basename $GITHUB_REF)" || echo "STORYBOOK_BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
219220
220221
- name: Start deployment
221222
uses: bobheadxi/[email protected]

.storybook/components/DocsContainer.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {
55
Unstyled,
66
} from '@storybook/blocks'
77
import { consoleLightTheme as lightTheme } from '@ultraviolet/themes'
8-
import { ReactNode, cloneElement, isValidElement } from 'react'
8+
import { ReactNode, cloneElement, isValidElement, useState } from 'react'
99
import { globalStyles } from './globalStyle'
1010
import '@ultraviolet/fonts/fonts.css'
11+
import { GlobalAlert } from '@ultraviolet/ui'
1112

1213
type ExtraProps = {
1314
/**
@@ -34,20 +35,44 @@ type ExtraProps = {
3435

3536
type DocsContainerProps = BaseContainerProps & {
3637
context?: {
37-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3839
attachedCSFFiles: Set<any>
3940
}
4041
} & { children: ReactNode }
4142

4243
const DocsContainer = ({ children, context }: DocsContainerProps) => {
44+
const [isBeta, setIsBeta] = useState(false)
4345
const scope = context?.attachedCSFFiles?.values()?.next()?.value?.meta
4446
const parameters = scope?.parameters
4547

4648
const isPlusLibrary = scope?.title?.includes('Plus/') ?? false
4749

50+
if (
51+
import.meta.env['STORYBOOK_ENVIRONMENT'] === 'production' &&
52+
!window.location.hostname.includes('beta.storybook.ultraviolet.scaleway.com')
53+
) {
54+
fetch('https://api.github.com/repos/scaleway/ultraviolet/branches/beta')
55+
.then((data) => {
56+
if (data.ok) {
57+
setIsBeta(true)
58+
}
59+
})
60+
.catch(() => {
61+
setIsBeta(false)
62+
})
63+
}
64+
4865
return (
4966
<Unstyled>
5067
<ThemeProvider theme={lightTheme}>
68+
{isBeta ?
69+
<GlobalAlert
70+
buttonText="Access to Beta"
71+
onClickButton={() => window.top?.location.assign('https://beta.storybook.ultraviolet.scaleway.com')}
72+
closable={false}
73+
>
74+
A Beta version is available. Please use this version if your dependencies include the Beta release.
75+
</GlobalAlert> : null}
5176
<Global styles={[globalStyles]} />
5277
<BaseContainer context={context}>
5378
{isValidElement<ExtraProps>(children)

0 commit comments

Comments
 (0)