Repository navigation
fix(ci): a pull request whose head predates the package-size check skips it visibly instead of failing build-storybook #9191
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a98b208
fix(ci): a pull request whose head predates the package-size check sk…
cixzhang da5d0a6
fix(ci): drop the size-base fallback (size-base goes away with Main's…
cixzhang 8ae797a
fix(ci): gate the package-size check on the scope step's requires-hea…
cixzhang bfd36ea
ci: the head-file notice holds for every job that asks for it
cixzhang 6ba036c
Merge main (#9164) into the predating-head skip; the record download …
cixzhang 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 hidden or 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 hidden or 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,82 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file ci-package-size-predating-head.test.mjs | ||
| * Contract: a pull request whose head predates the package-size check (the | ||
| * workflow comes from the merge ref, the checkout from the head) skips the | ||
| * check instead of failing build-storybook: the scope step's | ||
| * `requires-head-file` notes the missing script (test-scope-action.test.mjs), | ||
| * and the comparison steps after it run only when the head was measured. | ||
| */ | ||
|
|
||
| import {spawnSync} from 'node:child_process'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import {afterEach, describe, expect, it} from 'vitest'; | ||
| import yaml from 'yaml'; | ||
|
|
||
| const ROOT = path.resolve(import.meta.dirname, '../..'); | ||
| const ci = yaml.parse( | ||
| fs.readFileSync(path.join(ROOT, '.github/workflows/ci.yml'), 'utf8'), | ||
| ); | ||
| const step = (job, name) => | ||
| ci.jobs[job].steps.find(entry => entry.name === name); | ||
| const roots = []; | ||
| afterEach(() => { | ||
| for (const root of roots.splice(0)) | ||
| fs.rmSync(root, {recursive: true, force: true}); | ||
| }); | ||
|
|
||
| /** Runs a step's script in a fresh directory; returns its exit, stdout and outputs. */ | ||
| function runStep(script, setup = () => {}) { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'predating-')); | ||
| roots.push(root); | ||
| setup(root); | ||
| const output = path.join(root, 'github-output'); | ||
| fs.writeFileSync(output, ''); | ||
| const result = spawnSync('bash', ['-e', '-c', script], { | ||
| cwd: root, | ||
| encoding: 'utf8', | ||
| env: {...process.env, GITHUB_OUTPUT: output, BASE_REF: 'main'}, | ||
| }); | ||
| return {...result, outputs: fs.readFileSync(output, 'utf8')}; | ||
| } | ||
|
|
||
| describe('package size on a head that predates it', () => { | ||
| const job = ci.jobs['build-storybook']; | ||
| const measure = step('build-storybook', 'Measure published package size'); | ||
|
|
||
| it("asks the scope step whether the head has the check's script", () => { | ||
| const scope = job.steps.find(entry => entry.id === 'scope'); | ||
| expect(scope.with['requires-head-file']).toBe( | ||
| '.github/scripts/package-size.mjs', | ||
| ); | ||
| expect(measure.if).toContain( | ||
| "steps.scope.outputs.head_file_present != 'false'", | ||
| ); | ||
| }); | ||
|
|
||
| it('records a measurement only after measuring', () => { | ||
| const result = runStep(measure.run, root => { | ||
| fs.mkdirSync(path.join(root, '.github/scripts'), {recursive: true}); | ||
| fs.writeFileSync( | ||
| path.join(root, '.github/scripts/package-size.mjs'), | ||
| "import fs from 'node:fs';\nfs.writeFileSync('package-size-head.json', '{}');\n", | ||
| ); | ||
| }); | ||
| expect(result.status).toBe(0); | ||
| expect(result.outputs).toContain('measured=true'); | ||
| }); | ||
|
|
||
| it('runs the comparison steps only after a measurement', () => { | ||
| for (const name of [ | ||
| "Download main's package size for the merge base", | ||
| 'Compare published package size', | ||
| ]) { | ||
| expect(step('build-storybook', name).if).toContain( | ||
| "steps.package-size.outputs.measured == 'true'", | ||
| ); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
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.
With the lookup no longer behind
applies === 'true', the notice on line 244 now also fires when this job's work would not run: on a head cut beforeplaywright.interaction.config.ts,pr-interaction-webkitshows "merge main to run this check" for any non-gesture component change, andpr-interactionfor a README change, beside their own "No … interaction proofs for this change". Mergingmainwould not run those proofs. Could the notice say something true for every caller, for example "This pull request's head has no ${headFile}, so this job skips what needs it; merging main brings it in."?