-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18800 from storybookjs/yann/sb-509-create-github-…
…action Add command to publish repros + GH action
- Loading branch information
Showing
16 changed files
with
384 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Generate and push repros to the next branch | ||
|
||
on: | ||
schedule: | ||
- cron: '2 2 */1 * *' | ||
workflow_dispatch: | ||
# To remove when the branch will be merged | ||
push: | ||
branches: | ||
- yann/sb-509-create-github-action | ||
|
||
jobs: | ||
generate: | ||
runs-on: ubuntu-latest | ||
env: | ||
YARN_ENABLE_IMMUTABLE_INSTALLS: false | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup git user | ||
run: | | ||
git config --global user.name "Storybook Bot" | ||
git config --global user.email "[email protected]" | ||
- name: Install dependencies | ||
run: node ./scripts/check-dependencies.js | ||
- name: Bootstrap Storybook libraries | ||
run: yarn bootstrap --prep | ||
working-directory: ./code | ||
- name: Generate repros | ||
run: yarn next-repro | ||
working-directory: ./code | ||
- name: Publish repros to GitHub | ||
run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push | ||
working-directory: ./code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"deepscan.enable": true | ||
"deepscan.enable": true, | ||
"workbench.colorCustomizations": { | ||
"activityBar.background": "#263108", | ||
"titleBar.activeBackground": "#35450C", | ||
"titleBar.activeForeground": "#F8FCED" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
./scripts/node_modules/.bin/ts-node ./scripts/next-repro-generators/index.ts | ||
./scripts/node_modules/.bin/ts-node ./scripts/next-repro-generators/generate.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import program from 'commander'; | ||
import { join } from 'path'; | ||
import { existsSync } from 'fs'; | ||
import { command } from 'execa'; | ||
import * as tempy from 'tempy'; | ||
import { copy, remove, writeFile } from 'fs-extra'; | ||
|
||
import { getTemplatesData, renderTemplate } from './utils/template'; | ||
import { commitAllToGit } from './utils/git'; | ||
|
||
export const logger = console; | ||
|
||
const REPROS_DIRECTORY = join(__dirname, '..', '..', 'repros'); | ||
|
||
interface PublishOptions { | ||
remote?: string; | ||
push?: boolean; | ||
next?: boolean; | ||
} | ||
|
||
const publish = async (options: PublishOptions & { tmpFolder: string }) => { | ||
const { next: useNextVersion, remote, push, tmpFolder } = options; | ||
|
||
const scriptPath = __dirname; | ||
const gitBranch = useNextVersion ? 'next' : 'main'; | ||
|
||
const templatesData = await getTemplatesData(join(scriptPath, 'repro-config.yml')); | ||
|
||
logger.log(`👯♂️ Cloning the repository ${remote} in branch ${gitBranch}`); | ||
await command(`git clone ${remote} .`, { cwd: tmpFolder }); | ||
await command(`git checkout ${gitBranch}`, { cwd: tmpFolder }); | ||
|
||
logger.log(`🚚 Moving template files into the repository`); | ||
|
||
const templatePath = join(scriptPath, 'templates', 'root.ejs'); | ||
const templateData = { data: templatesData, version: gitBranch }; | ||
|
||
const output = await renderTemplate(templatePath, templateData); | ||
|
||
await writeFile(join(tmpFolder, 'README.md'), output); | ||
|
||
logger.log(`🚛 Moving all the repros into the repository`); | ||
await copy(join(REPROS_DIRECTORY), tmpFolder); | ||
|
||
await commitAllToGit(tmpFolder); | ||
|
||
logger.info(` | ||
🙌 All the examples were bootstrapped: | ||
- in ${tmpFolder} | ||
- using the '${gitBranch}' version of Storybook CLI | ||
- and committed on the '${gitBranch}' branch of a local Git repository | ||
Also all the files in the 'templates' folder were copied at the root of the Git repository. | ||
`); | ||
|
||
if (push) { | ||
await command(`git push --set-upstream origin ${gitBranch}`, { | ||
cwd: tmpFolder, | ||
}); | ||
const remoteRepoUrl = `${remote.replace('.git', '')}/tree/${gitBranch}`; | ||
logger.info(`🚀 Everything was pushed on ${remoteRepoUrl}`); | ||
} else { | ||
logger.info(` | ||
To publish these examples you just need to: | ||
- push the branch: 'git push --set-upstream origin ${gitBranch} | ||
`); | ||
} | ||
}; | ||
|
||
program | ||
.description('Create a reproduction from a set of possible templates') | ||
.option('--remote <remote>', 'Choose the remote to push the contents to') | ||
.option('--next', 'Whether to use the next version of Storybook CLI', true) | ||
.option('--push', 'Whether to push the contents to the remote', false) | ||
.option('--force-push', 'Whether to force push the changes into the repros repository', false); | ||
|
||
program.parse(process.argv); | ||
|
||
if (!existsSync(REPROS_DIRECTORY)) { | ||
throw Error("Can't find repros directory. Did you forget to run generate-repros?"); | ||
} | ||
|
||
const tmpFolder = tempy.directory(); | ||
logger.log(`⏱ Created tmp folder: ${tmpFolder}`); | ||
|
||
const options = program.opts() as PublishOptions; | ||
|
||
publish({ ...options, tmpFolder }).catch(async (e) => { | ||
logger.error(e); | ||
|
||
if (existsSync(tmpFolder)) { | ||
logger.log('🚮 Removing the temporary folder..'); | ||
await remove(tmpFolder); | ||
} | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"installDependencies": true, | ||
"startCommand": "yarn storybook" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h1><%= name %></h1> | ||
|
||
<p>This is project generated to serve as a reproduction starter for Storybook.</p> | ||
|
||
<a href="<%= stackblitzUrl %>">View it in Stackblitz</a> | ||
|
||
<h3>Testing instructions</h3> | ||
|
||
<p>Install dependencies:</p> | ||
<pre> | ||
yarn | ||
</pre> | ||
|
||
<p>Run Storybook:</p> | ||
<pre> | ||
yarn storybook | ||
</pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h1>Storybook Reproduction Templates</h1> | ||
|
||
<img alt="Storybook <%= version %> Badge" src="https://img.shields.io/npm/v/@storybook/react/<%= version %>" /> | ||
|
||
<p>The following repros have been generated with the `<%= version %>` version of Storybook.</p> | ||
|
||
<% if (typeof data !== 'undefined' && Object.keys(data).length) { %> | ||
<p>Preview any repro live on <a href="http://stackblitz.com/">StackBlitz:</a></p> | ||
<% for (var groupName in data) { %> | ||
<% if (data[groupName] !== undefined) { %> | ||
<details> | ||
<summary><b><%- (groupName) %></b></summary> | ||
<ul> | ||
<% for (var exampleName in data[groupName]) { %> | ||
<% if (data[groupName][exampleName] !== undefined) { %> | ||
<li> | ||
<a href="<%=data[groupName][exampleName]['stackblitzUrl']%>"> | ||
<%=data[groupName][exampleName]['name']%> | ||
</a> | ||
</li> | ||
<% } %> | ||
<% } %> | ||
</ul> | ||
</details> | ||
<% } %> | ||
<% } %> | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { command } from 'execa'; | ||
import { logger } from '../publish'; | ||
|
||
export async function commitAllToGit(cwd: string) { | ||
try { | ||
logger.log(`💪 Committing everything to the repository`); | ||
|
||
await command('git add .', { cwd }); | ||
|
||
const currentCommitSHA = await command('git rev-parse HEAD'); | ||
await command( | ||
`git commit -m "Update examples - ${new Date().toDateString()} - ${currentCommitSHA.stdout | ||
.toString() | ||
.slice(0, 12)}"`, | ||
{ | ||
shell: true, | ||
cwd, | ||
} | ||
); | ||
} catch (e) { | ||
logger.log( | ||
`🤷 Git found no changes between previous versions so there is nothing to commit. Skipping publish!` | ||
); | ||
} | ||
} |
Oops, something went wrong.