-
Notifications
You must be signed in to change notification settings - Fork 10
fix(release): wait for the npm tarball before bumping Homebrew #318
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
4 commits
Select commit
Hold shift + click to select a range
621b7ad
fix(release): wait for the npm tarball before bumping Homebrew
elkaix 92c1595
fix(release): keep nightly snapshots and brew drift from failing CI
elkaix ee07a65
fix(release): drop unused lastError initializer in brew tarball poll
elkaix 546b0fd
fix(release): use the leftover brew poll budget for a last fetch
elkaix 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@pymodel/pythinker-code": patch | ||
| --- | ||
|
|
||
| Wait for the npm tarball to become downloadable before updating the Homebrew formula. |
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
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
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
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,106 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import test from 'node:test'; | ||
|
|
||
| import { downloadNpmTarball } from './update-brew-formula.mjs'; | ||
|
|
||
| const TARBALL_URL = 'https://registry.npmjs.org/@pymodel/pythinker-code/-/pythinker-code-2.0.0.tgz'; | ||
| const BODY = Buffer.from('pythinker-tarball'); | ||
|
|
||
| function response(status, body = BODY) { | ||
| return new Response(body, { status }); | ||
| } | ||
|
|
||
| function pollClock() { | ||
| let now = 0; | ||
| const sleeps = []; | ||
| const sleep = async (ms) => { | ||
| sleeps.push(ms); | ||
| now += ms; | ||
| }; | ||
| return { | ||
| now: () => now, | ||
| sleeps, | ||
| sleep, | ||
| }; | ||
| } | ||
|
|
||
| function pollOptions(clock, fetchImpl) { | ||
| return { | ||
| url: TARBALL_URL, | ||
| fetchImpl, | ||
| sleep: (ms) => clock.sleep(ms), | ||
| now: () => clock.now(), | ||
| log: () => {}, | ||
| budgetMs: 45_000, | ||
| intervalMs: 15_000, | ||
| }; | ||
| } | ||
|
|
||
| void test('returns the tarball when the first fetch is HTTP 200', async () => { | ||
| const clock = pollClock(); | ||
| let fetches = 0; | ||
| const result = await downloadNpmTarball( | ||
| pollOptions(clock, async () => { | ||
| fetches += 1; | ||
| return response(200); | ||
| }), | ||
| ); | ||
|
|
||
| assert.equal(fetches, 1); | ||
| assert.equal(result.attempts, 1); | ||
| assert.deepEqual(result.tarball, BODY); | ||
| assert.deepEqual(clock.sleeps, []); | ||
| }); | ||
|
|
||
| void test('retries after HTTP 404 and returns the tarball once npm serves it', async () => { | ||
| const clock = pollClock(); | ||
| const statuses = [404, 404, 200]; | ||
| const result = await downloadNpmTarball( | ||
| pollOptions(clock, async () => response(statuses.shift() ?? 500)), | ||
| ); | ||
|
|
||
| assert.equal(result.attempts, 3); | ||
| assert.deepEqual(result.tarball, BODY); | ||
| assert.deepEqual(clock.sleeps, [15_000, 15_000]); | ||
| }); | ||
|
|
||
| void test('retries an empty 200 body until a non-empty tarball arrives', async () => { | ||
| const clock = pollClock(); | ||
| const bodies = [Buffer.alloc(0), BODY]; | ||
| const result = await downloadNpmTarball( | ||
| pollOptions(clock, async () => response(200, bodies.shift() ?? BODY)), | ||
| ); | ||
|
|
||
| assert.equal(result.attempts, 2); | ||
| assert.deepEqual(result.tarball, BODY); | ||
| assert.deepEqual(clock.sleeps, [15_000]); | ||
| }); | ||
|
|
||
| void test('throws after the budget when every fetch is HTTP 404', async () => { | ||
| const clock = pollClock(); | ||
| let fetches = 0; | ||
| await assert.rejects( | ||
| () => | ||
| downloadNpmTarball( | ||
| pollOptions(clock, async () => { | ||
| fetches += 1; | ||
| return response(404); | ||
| }), | ||
| ), | ||
| { message: 'Failed to download npm tarball: HTTP 404 after 4 attempt(s)' }, | ||
| ); | ||
| assert.equal(fetches, 4); | ||
| assert.deepEqual(clock.sleeps, [15_000, 15_000, 15_000]); | ||
| }); | ||
|
|
||
| void test('sleeps the leftover budget then fetches again before giving up', async () => { | ||
| const clock = pollClock(); | ||
| const statuses = [404, 404, 404, 200]; | ||
| const result = await downloadNpmTarball({ | ||
| ...pollOptions(clock, async () => response(statuses.shift() ?? 500)), | ||
| budgetMs: 40_000, | ||
| }); | ||
| assert.equal(result.attempts, 4); | ||
| assert.deepEqual(result.tarball, BODY); | ||
| assert.deepEqual(clock.sleeps, [15_000, 15_000, 10_000]); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.