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

Support only testing components affected by recent git changes #304

Merged
merged 83 commits into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
eefd42a
Add --only-changed feature
ghengeveld Mar 10, 2021
0ed090a
Skip onlyStoryFiles
ghengeveld Mar 11, 2021
98b1562
Reword
ghengeveld Mar 11, 2021
779b1f2
Preserve missing specs when running with --only-changed
ghengeveld Mar 11, 2021
3c82255
Merge branch 'next' into determine-affected-stories
ghengeveld Mar 25, 2021
228fb24
Add some helper/debug scripts
ghengeveld Mar 30, 2021
68b4fee
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 8, 2021
81ce9e4
Trim the final output some more
ghengeveld Apr 8, 2021
9acd377
Log the target filename
ghengeveld Apr 8, 2021
49d09c2
Omit webpack stuff
ghengeveld Apr 8, 2021
dc33762
ESM
ghengeveld Apr 8, 2021
bef92a9
Rename file and add script
ghengeveld Apr 8, 2021
ebfd5b3
Rename file and add script
ghengeveld Apr 8, 2021
51514a5
Pass changedFiles as args
ghengeveld Apr 8, 2021
feb1c0d
Cleanup
ghengeveld Apr 8, 2021
aa1010b
Use real configDir and staticDir + big refactor
ghengeveld Apr 8, 2021
7e81012
Move dependency tracing to upload step so we can skip upload if nothi…
ghengeveld Apr 9, 2021
516dd7d
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 9, 2021
51ee57b
Deal with zero changed files since baseline commit(s), in conjunction…
ghengeveld Apr 9, 2021
3cbf88b
Update bin/lib/parseArgs.js
ghengeveld Apr 9, 2021
4e71b5a
Update bin/lib/parseArgs.js
ghengeveld Apr 9, 2021
4c66cc7
Fix tests
ghengeveld Apr 9, 2021
2639b3d
Rename getBaselineCommits to getParentCommits
ghengeveld Apr 9, 2021
176b5e8
Rename baselineCommits to parentCommits
ghengeveld Apr 9, 2021
b3d3539
Rewording
ghengeveld Apr 9, 2021
35d57b0
5.7.2-canary.0
ghengeveld Apr 12, 2021
56592de
Pass --webpack-stats-json to build-storybook
ghengeveld Apr 12, 2021
7e5007c
5.7.2-canary.1
ghengeveld Apr 12, 2021
06e9884
Check Storybook version before using --webpack-stats-json flag
ghengeveld Apr 12, 2021
eba9c79
Fix messaging
ghengeveld Apr 12, 2021
290af6d
5.7.2-canary.2
ghengeveld Apr 12, 2021
7dba03b
Fix messaging
ghengeveld Apr 12, 2021
c7853fd
5.7.2-canary.3
ghengeveld Apr 12, 2021
24bc6b5
Catch invalid commit and warn about it
ghengeveld Apr 15, 2021
3da983d
Change wording for snapshot progress message
ghengeveld Apr 15, 2021
6852874
Warn when using --only-changed without stats file
ghengeveld Apr 15, 2021
b1d5cdf
Update tests
ghengeveld Apr 15, 2021
c939a19
Don't infer preserveMissingSpecs on --only or --only-changed
ghengeveld Apr 15, 2021
6a5a56f
Run skip mutation when there's no changedFiles
ghengeveld Apr 15, 2021
db8ead2
Better messaging when bailing on --only-changed
ghengeveld Apr 15, 2021
bda4f29
5.7.2-canary.4
ghengeveld Apr 15, 2021
7c2fc81
Use actual baseline commits from which to determine changed files
ghengeveld Apr 15, 2021
782592c
Fix skipped count
ghengeveld Apr 16, 2021
149ced6
Fix baseline commits retrieval
ghengeveld Apr 16, 2021
e4de04f
Narrow down the try/catch so we don't catch too much
ghengeveld Apr 16, 2021
d5219c0
Support prerelease versions
ghengeveld Apr 16, 2021
61d752f
onlyStoryFiles is an object
ghengeveld Apr 16, 2021
c61894c
Not always due to --skip
ghengeveld Apr 16, 2021
3339bda
We don't need manager-stats
ghengeveld Apr 16, 2021
18b0a51
Better logs
ghengeveld Apr 16, 2021
1e17d11
Log fixes
ghengeveld Apr 16, 2021
344b9ab
Reword final status messages
ghengeveld Apr 17, 2021
0d4d613
Fix upload success message
ghengeveld Apr 17, 2021
a1a0c44
Fix upload success message
ghengeveld Apr 17, 2021
5bf0e1a
Update stats reporting
ghengeveld Apr 17, 2021
9b3f004
5.7.2-canary.5
ghengeveld Apr 17, 2021
2b67c45
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 17, 2021
b305bb8
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 17, 2021
2274698
Upload may have been skipped
ghengeveld Apr 19, 2021
04e5ca3
5.7.2-canary.6
ghengeveld Apr 19, 2021
cac4ac5
Fix numbering
ghengeveld Apr 21, 2021
f50b263
5.7.2-canary.7
ghengeveld Apr 21, 2021
15ccedd
Support only and onlyChanged in GitHub Action
ghengeveld Apr 21, 2021
bf090c7
Run with --only-changed against staging
ghengeveld Apr 21, 2021
a2c565a
Fix changedFiles is undefined error
ghengeveld Apr 21, 2021
f7e3700
Bump storybook
ghengeveld Apr 21, 2021
de5bc45
Remove --webpack-stats-json flag
ghengeveld Apr 22, 2021
679278b
Better messaging
ghengeveld Apr 23, 2021
6b7ac73
Set proper exitCode and show suitable message when inheriting a build
ghengeveld Apr 23, 2021
5517fd2
5.7.2-canary.8
ghengeveld Apr 23, 2021
4a6a860
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 23, 2021
1781dc4
Fix story data
ghengeveld Apr 23, 2021
95f0f76
Update CI scripts
ghengeveld Apr 23, 2021
eb7a13d
Exit once uploaded
ghengeveld Apr 23, 2021
8260dc9
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 24, 2021
19fd509
Don't skip build when changedFiles or onlyStoryFiles is empty
ghengeveld Apr 26, 2021
470ba7d
5.7.2-canary.9
ghengeveld Apr 26, 2021
61b72f1
Look at package.json rather than node_modules to determine installed …
ghengeveld Apr 27, 2021
5c33cbc
5.7.2-canary.10
ghengeveld Apr 27, 2021
c12588d
Add addon-essentials
ghengeveld Apr 27, 2021
88f99d3
5.7.2-canary.11
ghengeveld Apr 27, 2021
862d33c
Fix tests
ghengeveld Apr 29, 2021
6ed15f2
Merge branch 'next' into determine-affected-stories
ghengeveld Apr 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/action-run.yml
@@ -1,9 +1,9 @@
name: "self test development-like"
name: "Action"
on:
push:

jobs:
test:
self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -12,6 +12,6 @@ jobs:
- run: yarn build-storybook
- uses: ./
with:
projectToken: 5oy3iw6rkio
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: 5oy3iw6rkio
storybookBuildDir: storybook-static
6 changes: 4 additions & 2 deletions .github/workflows/chromatic-action.yml
@@ -1,4 +1,4 @@
name: "Chromatic via action"
name: "Chromatic (action)"
on: [push, pull_request, pull_request_review, pull_request_target]

jobs:
Expand All @@ -10,4 +10,6 @@ jobs:
- uses: chromaui/action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: gcaw1ai2dgo
projectToken: gcaw1ai2dgo
exitZeroOnChanges: true
exitOnceUploaded: true
3 changes: 1 addition & 2 deletions .github/workflows/chromatic-manual.yml
@@ -1,4 +1,4 @@
name: "Chromatic via manual"
name: "Chromatic (manual)"
on: [push]
# do not use pull_request here, it report the wrong commit_sha and commit_ref

Expand All @@ -18,4 +18,3 @@ jobs:
run: yarn chromatic
env:
CHROMATIC_PROJECT_TOKEN: gcaw1ai2dgo
CHROMATIC_APP_CODE: gcaw1ai2dgo
10 changes: 5 additions & 5 deletions .github/workflows/chromatic-staging-action.yml
@@ -1,4 +1,4 @@
name: "[Staging] Chromatic via action"
name: "[Staging] Chromatic (action)"
on: [push, pull_request, pull_request_target, pull_request_review]

jobs:
Expand All @@ -10,10 +10,10 @@ jobs:
- uses: chromaui/action@v1
env:
DEBUG: chromatic-cli
CHROMATIC_APP_CODE: mpm7osoy9sa
CHROMATIC_PROJECT_TOKEN: mpm7osoy9sa
CHROMATIC_INDEX_URL: https://www.staging-chromatic.com
with:
appCode: mpm7osoy9sa
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: mpm7osoy9sa
token: ${{ secrets.GITHUB_TOKEN }}
onlyChanged: true
exitZeroOnChanges: true
exitOnceUploaded: true
7 changes: 3 additions & 4 deletions .github/workflows/chromatic-staging-manual.yml
@@ -1,4 +1,4 @@
name: "[Staging] Chromatic via manual"
name: "[Staging] Chromatic (manual)"
on: [push]
# do not use pull_request here, it report the wrong commit_sha and commit_ref

Expand All @@ -15,8 +15,7 @@ jobs:
- name: prep package
run: ./scripts/rename.js storybook-chromatic
- name: run chromatic
run: yarn chromatic
run: yarn chromatic --only-changed
env:
CHROMATIC_APP_CODE: mpm7osoy9sa
CHROMATIC_PROJECT_TOKEN: mpm7osoy9sa
CHROMATIC_INDEX_URL: https://www.staging-chromatic.com
CHROMATIC_INDEX_URL: https://www.staging-chromatic.com
7 changes: 3 additions & 4 deletions .github/workflows/chromatic-staging-windows.yml
@@ -1,4 +1,4 @@
name: "[Staging] Chromatic via windows"
name: "[Staging] Chromatic (windows)"
on: [push]
# do not use pull_request here, it report the wrong commit_sha and commit_ref

Expand All @@ -15,8 +15,7 @@ jobs:
- name: prep package
run: node ./scripts/rename.js storybook-chromatic
- name: run chromatic
run: yarn chromatic
run: yarn chromatic --only-changed
env:
CHROMATIC_APP_CODE: mpm7osoy9sa
CHROMATIC_PROJECT_TOKEN: mpm7osoy9sa
CHROMATIC_INDEX_URL: https://www.staging-chromatic.com
CHROMATIC_INDEX_URL: https://www.staging-chromatic.com
3 changes: 1 addition & 2 deletions .github/workflows/chromatic-windows.yml
@@ -1,4 +1,4 @@
name: "Chromatic via windows"
name: "Chromatic (windows)"
on: [push]
# do not use pull_request here, it report the wrong commit_sha and commit_ref

Expand All @@ -18,4 +18,3 @@ jobs:
run: yarn chromatic
env:
CHROMATIC_PROJECT_TOKEN: gcaw1ai2dgo
CHROMATIC_APP_CODE: gcaw1ai2dgo
6 changes: 6 additions & 0 deletions action.yml
Expand Up @@ -30,6 +30,12 @@ inputs:
skip:
description: 'Skip Chromatic tests, but mark the commit as passing'
required: false
only:
description: 'Only run a single story or a subset of stories'
required: false
onlyChanged:
description: 'Only run stories affected by files changed since the baseline build'
required: false
doNotStart:
description: 'Do not attempt to start or build; use if your Storybook is already running'
required: false
Expand Down
6 changes: 5 additions & 1 deletion action/main.js
Expand Up @@ -136,7 +136,7 @@ function runChromatic(options) {
}
function run() {
return __awaiter(this, void 0, void 0, function () {
var commit, branch, sha, projectToken, workingDir, buildScriptName, scriptName, exec, skip, doNotStart, storybookPort, storybookUrl, storybookBuildDir, storybookHttps, storybookCert, storybookKey, storybookCa, preserveMissing, autoAcceptChanges, allowConsoleErrors, exitZeroOnChanges, exitOnceUploaded, ignoreLastBuildOnBranch, output, e_1;
var commit, branch, sha, projectToken, workingDir, buildScriptName, scriptName, exec, skip, only, onlyChanged, doNotStart, storybookPort, storybookUrl, storybookBuildDir, storybookHttps, storybookCert, storybookKey, storybookCa, preserveMissing, autoAcceptChanges, allowConsoleErrors, exitZeroOnChanges, exitOnceUploaded, ignoreLastBuildOnBranch, output, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Expand All @@ -154,6 +154,8 @@ function run() {
scriptName = core_1.getInput('scriptName');
exec = core_1.getInput('exec');
skip = core_1.getInput('skip');
only = core_1.getInput('only');
onlyChanged = core_1.getInput('onlyChanged');
doNotStart = core_1.getInput('doNotStart');
storybookPort = core_1.getInput('storybookPort');
storybookUrl = core_1.getInput('storybookUrl');
Expand All @@ -178,6 +180,8 @@ function run() {
scriptName: maybe(scriptName),
exec: maybe(exec),
skip: maybe(skip),
only: maybe(only),
onlyChanged: maybe(onlyChanged),
doNotStart: maybe(doNotStart),
storybookPort: maybe(storybookPort),
storybookUrl: maybe(storybookUrl),
Expand Down
4 changes: 4 additions & 0 deletions action/main.ts
Expand Up @@ -102,6 +102,8 @@ async function run() {
const scriptName = getInput('scriptName');
const exec = getInput('exec');
const skip = getInput('skip');
const only = getInput('only');
const onlyChanged = getInput('onlyChanged');
const doNotStart = getInput('doNotStart');
const storybookPort = getInput('storybookPort');
const storybookUrl = getInput('storybookUrl');
Expand All @@ -128,6 +130,8 @@ async function run() {
scriptName: maybe(scriptName),
exec: maybe(exec),
skip: maybe(skip),
only: maybe(only),
onlyChanged: maybe(onlyChanged),
doNotStart: maybe(doNotStart),
storybookPort: maybe(storybookPort),
storybookUrl: maybe(storybookUrl),
Expand Down
63 changes: 41 additions & 22 deletions bin/git/git.js
Expand Up @@ -63,6 +63,21 @@ const TesterHasBuildsWithCommitsQuery = gql`
}
`;

const TesterBaselineCommitsQuery = gql`
query TesterBaselineCommitsQuery($branch: String!, $parentCommits: [String!]!) {
app {
baselineBuilds(branch: $branch, parentCommits: $parentCommits) {
number
status
Copy link
Member

Choose a reason for hiding this comment

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

Needs legacy:false!!

Copy link
Member Author

Choose a reason for hiding this comment

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

That is such a gotcha 🤦‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

IKR. I'm not sure what we can do about it, beyond renaming the field entirely.

commit
committedAt
changeCount
webUrl
}
}
}
`;

export async function getVersion() {
const result = await execGitCommand(`git --version`);
return result.replace('git version ', '');
Expand Down Expand Up @@ -229,19 +244,15 @@ async function step(
});
}

export async function getBaselineCommits(
{ client, log },
{ branch, ignoreLastBuildOnBranch = false } = {}
export async function getParentCommits(
{ client, git, log },
{ ignoreLastBuildOnBranch = false } = {}
) {
const { commit, committedAt } = await getCommit();
const { branch, commit, committedAt } = git;

// Include the latest build from this branch as an ancestor of the current build
const {
app: { firstBuild, lastBuild, pullRequest },
} = await client.runQuery(TesterFirstCommittedAtQuery, {
branch,
commit,
});
const { app } = await client.runQuery(TesterFirstCommittedAtQuery, { branch, commit });
const { firstBuild, lastBuild, pullRequest } = app;
log.debug(
`App firstBuild: %o, lastBuild: %o, pullRequest: %o`,
firstBuild,
Expand All @@ -255,9 +266,9 @@ export async function getBaselineCommits(
}

const initialCommitsWithBuilds = [];
const extraBaselineCommits = [];
const extraParentCommits = [];

// Add the most recent build on the branch as a (potential) baseline build, unless:
// Add the most recent build on the branch as a parent build, unless:
// - the user opts out with `--ignore-last-build-on-branch`
// - the commit is newer than the build we are running, in which case we doing this build out
// of order and that could lead to problems.
Expand All @@ -275,14 +286,14 @@ export async function getBaselineCommits(
initialCommitsWithBuilds.push(lastBuild.commit);
} else {
log.debug(
`Last branch build commit ${lastBuild.commit} not in index, blindly appending to baselines`
`Last branch build commit ${lastBuild.commit} not in index, blindly appending to parents`
);
extraBaselineCommits.push(lastBuild.commit);
extraParentCommits.push(lastBuild.commit);
}
}

// Add the most recent build on a (merged) branch as a (potential) baseline if we think
// this commit was the commit that merged the PR.
// Add the most recent build on a (merged) branch as a parent if we think this was the commit that
// merged the pull request.
// @see https://www.chromatic.com/docs/branching-and-baselines#squash-and-rebase-merging
if (pullRequest && pullRequest.lastHeadBuild) {
if (await commitExists(pullRequest.lastHeadBuild.commit)) {
Expand All @@ -292,9 +303,9 @@ export async function getBaselineCommits(
initialCommitsWithBuilds.push(pullRequest.lastHeadBuild.commit);
} else {
log.debug(
`Merged PR build commit ${pullRequest.lastHeadBuild.commit} not in index, blindly appending to baselines`
`Merged PR build commit ${pullRequest.lastHeadBuild.commit} not in index, blindly appending to parents`
);
extraBaselineCommits.push(pullRequest.lastHeadBuild.commit);
extraParentCommits.push(pullRequest.lastHeadBuild.commit);
}
}

Expand All @@ -312,10 +323,18 @@ export async function getBaselineCommits(
log.debug(`Final commitsWithBuilds: ${commitsWithBuilds}`);

// For any pair A,B of builds, there is no point in using B if it is an ancestor of A.
return [
...extraBaselineCommits,
...(await maximallyDescendentCommits({ log }, commitsWithBuilds)),
];
return [...extraParentCommits, ...(await maximallyDescendentCommits({ log }, commitsWithBuilds))];
}

export async function getBaselineBuilds({ client }, { branch, parentCommits }) {
const { app } = await client.runQuery(TesterBaselineCommitsQuery, { branch, parentCommits });
return app.baselineBuilds;
}

export async function getChangedFiles(baseCommit, headCommit = '') {
// Note that an empty headCommit will include uncommitted (staged or unstaged) changes.
const files = await execGitCommand(`git diff --name-only ${baseCommit} ${headCommit}`);
return files.split(EOL).filter(Boolean);
}

/**
Expand Down