-
Notifications
You must be signed in to change notification settings - Fork 23
advisory check for published tarball drift [agent-managed] #7019
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
Open
pip-the-concierge-via-chinmina
wants to merge
7
commits into
main
Choose a base branch
from
agent/advisory-tarball-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60a026b
feat: add changeset gate for package changes and fix publish notifica…
pip-the-concierge[bot] ceff0aa
feat: replace changeset gate with advisory tarball drift check [agent…
pip-the-concierge[bot] 4f793f0
refactor: reduce tarball drift check to a pass/fail signal
ckychris b15e581
fix: JSON-escape commit subject in publish-failure Slack payload
ckychris 3b30f32
fix: run drift check on feature branches only, and satisfy prettier
ckychris fbcf911
fix: fetch published tarballs directly instead of shelling out to npm
ckychris 9466747
chore: drop check:changeset script
ckychris 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,27 @@ | ||
| name: Check package output | ||
|
|
||
| # The inverse of changeset.yaml: that publishes from main and release branches, | ||
| # this advises on feature branches, where a changeset can still be added. | ||
| on: | ||
| push: | ||
| branches-ignore: | ||
| - 'main' | ||
| - 'release/**' | ||
| - 'changeset-release/**' | ||
|
|
||
| jobs: | ||
| check-package-output: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: ./.github/actions/setup | ||
|
|
||
| - name: Build workspace | ||
| run: pnpm turbo build | ||
|
|
||
| - name: Check package output drift | ||
| run: pnpm check:package-output |
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| !*.scss | ||
|
|
||
| # Explicitly ignore... | ||
| .devbox/ | ||
| devbox.lock | ||
| pnpm-lock.yaml | ||
| **/CHANGELOG.md | ||
|
|
||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,121 @@ | ||
| /** | ||
| * Advisory: does the tarball we'd publish differ from the one already on npm? | ||
| * | ||
| * Assumes `pnpm turbo build` has already run. Exits 1 if any package's output | ||
| * differs with no changeset covering it — a human decides whether that warrants | ||
| * a release. | ||
| */ | ||
|
|
||
| /* eslint-disable no-console */ | ||
|
|
||
| import { execFileSync } from 'node:child_process' | ||
| import { createHash } from 'node:crypto' | ||
| import { mkdirSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
|
|
||
| const run = (cmd: string, args: string[], cwd?: string): string => | ||
| execFileSync(cmd, args, { encoding: 'utf-8', cwd, maxBuffer: 64 * 1024 * 1024 }).trim() | ||
|
|
||
| const sha = (data: Buffer | string): string => createHash('sha256').update(data).digest('hex') | ||
|
|
||
| const fingerprint = (dir: string): string => { | ||
| const files = readdirSync(dir, { recursive: true, withFileTypes: true }) | ||
| .filter((entry) => entry.isFile()) | ||
| .map((entry) => join(entry.parentPath, entry.name).slice(dir.length + 1)) | ||
| .sort() | ||
| return sha(files.map((f) => `${sha(readFileSync(join(dir, f)))} ${f}`).join('\n')) | ||
| } | ||
|
|
||
| /** Extract into a directory of its own, so the tarball file never lands in the fingerprint. */ | ||
| const extractedFingerprint = (tarball: string, dest: string): string => { | ||
| const contents = join(dest, 'contents') | ||
| mkdirSync(contents) | ||
| run('tar', ['-xf', tarball, '-C', contents, '--strip-components=1']) | ||
| return fingerprint(contents) | ||
| } | ||
|
|
||
| const packedFingerprint = (pkgDir: string, tmp: string): string => { | ||
| const dest = mkdtempSync(join(tmp, 'local-')) | ||
| const tarball = run('pnpm', ['pack', '--pack-destination', dest], pkgDir).split('\n').pop()! | ||
| return extractedFingerprint(tarball, dest) | ||
| } | ||
|
|
||
| /** Null means this version was never published, which is a skip rather than a failure. */ | ||
| const publishedFingerprint = async ( | ||
| name: string, | ||
| version: string, | ||
| tmp: string, | ||
| ): Promise<string | null> => { | ||
| const metadata = await fetch(`https://registry.npmjs.org/${name}/${version}`) | ||
| if (metadata.status === 404) return null | ||
| if (!metadata.ok) throw new Error(`registry returned ${metadata.status} for ${name}@${version}`) | ||
|
|
||
| const { dist } = (await metadata.json()) as { dist: { tarball: string } } | ||
| const download = await fetch(dist.tarball) | ||
| if (!download.ok) throw new Error(`tarball download failed for ${name}@${version}`) | ||
|
|
||
| const dest = mkdtempSync(join(tmp, 'published-')) | ||
| const tarball = join(dest, 'published.tgz') | ||
| writeFileSync(tarball, Buffer.from(await download.arrayBuffer())) | ||
| return extractedFingerprint(tarball, dest) | ||
| } | ||
|
|
||
| const releasedPackages = (): Set<string> => { | ||
| const out = join(mkdtempSync(join(tmpdir(), 'changeset-')), 'status.json') | ||
| try { | ||
| execFileSync('pnpm', ['changeset', 'status', '--since=origin/main', `--output=${out}`], { | ||
| stdio: 'ignore', | ||
| }) | ||
| } catch { | ||
| // Non-zero simply means uncovered changes; the status file is still written. | ||
| } | ||
| try { | ||
| const status = JSON.parse(readFileSync(out, 'utf-8')) | ||
| return new Set<string>(status.releases.map((r: { name: string }) => r.name)) | ||
| } catch { | ||
| return new Set() | ||
| } | ||
| } | ||
|
|
||
| const root = run('git', ['rev-parse', '--show-toplevel']) | ||
| const tmp = mkdtempSync(join(tmpdir(), 'package-output-')) | ||
| const released = releasedPackages() | ||
|
|
||
| const packages = readdirSync(join(root, 'packages'), { withFileTypes: true }) | ||
| .filter((entry) => entry.isDirectory()) | ||
| .map((entry) => join(root, 'packages', entry.name)) | ||
| .flatMap((dir) => { | ||
| try { | ||
| const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8')) | ||
| return pkg.private === true ? [] : [{ dir, name: pkg.name, version: pkg.version }] | ||
| } catch { | ||
| return [] | ||
| } | ||
| }) | ||
|
|
||
| const drifted: string[] = [] | ||
|
|
||
| for (const { dir, name, version } of packages) { | ||
| const published = await publishedFingerprint(name, version, tmp) | ||
| if (published === null) { | ||
| console.log(`? ${name} — ${version} not on registry, skipped`) | ||
| continue | ||
| } | ||
| if (packedFingerprint(dir, tmp) === published) { | ||
| console.log(`= ${name} — matches ${version}`) | ||
| } else if (released.has(name)) { | ||
| console.log(`~ ${name} — differs, changeset present`) | ||
| } else { | ||
| console.log(`! ${name} — differs from ${version}, no changeset`) | ||
| drifted.push(name) | ||
| } | ||
| } | ||
|
|
||
| if (drifted.length > 0) { | ||
| console.log( | ||
| `\nOutput differs from the published version with no changeset: ${drifted.join(', ')}.\n` + | ||
| `Advisory only — add a changeset if these changes should ship.`, | ||
| ) | ||
| process.exit(1) | ||
| } |
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.