-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Add command to publish repros + GH action #18800
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ea2fffc
add command to publish repos + GH action
yannbf a2f1bae
update action
yannbf 113edf0
switch to npx
yannbf a2c7b71
update action
yannbf ae6c332
update action
yannbf 37075f3
rename next-repros action
yannbf de83f4f
replace zx with execa and fs-extra commands
yannbf f402094
make it dynamic form a template
ndelangen fd4bfe0
refactor and improve repro generate and publish scripts
yannbf 649a92e
add documentation per repro
yannbf b962cf3
rename tmp folder
yannbf ce84ddb
change paths after refactor
yannbf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can probably reuse this from above