-
Notifications
You must be signed in to change notification settings - Fork 468
ci(repo): ship electron-passkeys native binaries in canary and snapshot releases #9510
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
Closed
Closed
Changes from all commits
Commits
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,2 @@ | ||
| --- | ||
| --- |
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,91 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { createHash } from 'node:crypto'; | ||
| import { readFile, readdir, stat, writeFile } from 'node:fs/promises'; | ||
| import { join, relative, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| export const DEFAULT_PACKAGE_DIR = 'packages/electron-passkeys'; | ||
| export const DEFAULT_HASH_FILE = 'packages/electron-passkeys/npm/.source-hash'; | ||
|
|
||
| // Inputs that change the compiled binary. Anything else in the package (loader, README, npm/*) does not. | ||
| export const SOURCE_INPUTS = ['src', 'Cargo.toml', 'Cargo.lock', 'build.rs']; | ||
|
|
||
| async function collectFiles(path) { | ||
| const info = await stat(path); | ||
| if (!info.isDirectory()) { | ||
| return [path]; | ||
| } | ||
| const entries = await readdir(path, { withFileTypes: true }); | ||
| const nested = await Promise.all(entries.map(entry => collectFiles(join(path, entry.name)))); | ||
| return nested.flat(); | ||
| } | ||
|
|
||
| export async function computeSourceHash(packageDir) { | ||
| const files = (await Promise.all(SOURCE_INPUTS.map(input => collectFiles(resolve(packageDir, input))))).flat(); | ||
| const hash = createHash('sha256'); | ||
|
|
||
| for (const file of files.sort()) { | ||
| hash.update(relative(packageDir, file).split('\\').join('/')); | ||
| hash.update('\0'); | ||
| hash.update(await readFile(file)); | ||
| hash.update('\0'); | ||
| } | ||
|
|
||
| return hash.digest('hex'); | ||
| } | ||
|
|
||
| export function formatStaleError(expected, actual) { | ||
| return `::error::electron-passkeys binaries were built from source hash ${actual} but the tree is at ${expected}; re-run the "Electron Passkeys Native Build" workflow on this commit`; | ||
| } | ||
|
|
||
| export function formatStaleWarning(expected, actual) { | ||
| return `::warning::electron-passkeys binaries were built from source hash ${actual} but the tree is at ${expected}; the published binaries do not include this branch's native changes`; | ||
| } | ||
|
|
||
| async function main() { | ||
| const [command, ...rest] = process.argv.slice(2); | ||
| const warnOnly = rest.includes('--warn'); | ||
| const positional = rest.filter(arg => !arg.startsWith('--')); | ||
| const hashFile = positional[0] || DEFAULT_HASH_FILE; | ||
| const packageDir = positional[1] || DEFAULT_PACKAGE_DIR; | ||
| const expected = await computeSourceHash(packageDir); | ||
|
|
||
| if (command === 'write') { | ||
| await writeFile(hashFile, `${expected}\n`); | ||
| console.log(`Wrote source hash ${expected} to ${hashFile}`); | ||
| return; | ||
| } | ||
|
|
||
| if (command === 'verify') { | ||
| let actual; | ||
| try { | ||
| actual = (await readFile(hashFile, 'utf8')).trim(); | ||
| } catch { | ||
| console.error( | ||
| `::error::${hashFile} is missing; the downloaded electron-passkeys artifact predates source hashing`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (actual === expected) { | ||
| console.log(`electron-passkeys binaries match source hash ${expected}.`); | ||
| return; | ||
| } | ||
|
|
||
| if (warnOnly) { | ||
| console.warn(formatStaleWarning(expected, actual)); | ||
| return; | ||
| } | ||
|
|
||
| console.error(formatStaleError(expected, actual)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.error(`Usage: electron-passkeys-source-hash.mjs <write|verify> [hashFile] [packageDir] [--warn]`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) { | ||
| await main(); | ||
| } | ||
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,69 @@ | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| import { afterEach, describe, expect, test } from 'vitest'; | ||
|
|
||
| import { computeSourceHash, formatStaleError } from './electron-passkeys-source-hash.mjs'; | ||
|
|
||
| const roots = []; | ||
|
|
||
| async function createPackage(files) { | ||
| const root = await mkdtemp(join(tmpdir(), 'electron-passkeys-source-')); | ||
| roots.push(root); | ||
|
|
||
| const defaults = { | ||
| 'src/lib.rs': 'fn main() {}', | ||
| 'Cargo.toml': '[package]', | ||
| 'Cargo.lock': '', | ||
| 'build.rs': '', | ||
| }; | ||
| for (const [path, content] of Object.entries({ ...defaults, ...files })) { | ||
| await mkdir(join(root, path, '..'), { recursive: true }); | ||
| await writeFile(join(root, path), content); | ||
| } | ||
|
|
||
| return root; | ||
| } | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(roots.splice(0).map(root => rm(root, { force: true, recursive: true }))); | ||
| }); | ||
|
|
||
| describe('computeSourceHash', () => { | ||
| test('is stable across identical trees in different locations', async () => { | ||
| const a = await createPackage({}); | ||
| const b = await createPackage({}); | ||
|
|
||
| await expect(computeSourceHash(a)).resolves.toBe(await computeSourceHash(b)); | ||
| }); | ||
|
|
||
| test('changes when a Rust source file changes', async () => { | ||
| const a = await createPackage({}); | ||
| const b = await createPackage({ 'src/lib.rs': 'fn main() { changed(); }' }); | ||
|
|
||
| expect(await computeSourceHash(a)).not.toBe(await computeSourceHash(b)); | ||
| }); | ||
|
|
||
| test('changes when Cargo.lock changes', async () => { | ||
| const a = await createPackage({}); | ||
| const b = await createPackage({ 'Cargo.lock': 'version = 4' }); | ||
|
|
||
| expect(await computeSourceHash(a)).not.toBe(await computeSourceHash(b)); | ||
| }); | ||
|
|
||
| test('ignores files outside the native inputs', async () => { | ||
| const a = await createPackage({}); | ||
| const b = await createPackage({ 'index.js': 'module.exports = {}', 'npm/darwin-x64/package.json': '{}' }); | ||
|
|
||
| await expect(computeSourceHash(a)).resolves.toBe(await computeSourceHash(b)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('formatStaleError', () => { | ||
| test('names both hashes and the remediation', () => { | ||
| expect(formatStaleError('bbb', 'aaa')).toBe( | ||
| '::error::electron-passkeys binaries were built from source hash aaa but the tree is at bbb; re-run the "Electron Passkeys Native Build" workflow on this commit', | ||
| ); | ||
| }); | ||
| }); |
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Honor
--warnwhen the source-hash file is missing.When
verify --warncannot readhashFile, Lines 64-68 still exit with status 1..github/workflows/release.ymlLines 539-542 use warning mode for snapshot releases. This aborts a snapshot when the downloaded artifact predates source hashing instead of issuing the intended warning.If
warnOnlyis true, print a::warning::message and return. Add a regression test for a missing hash file in warning mode.Proposed fix
} catch { + if (warnOnly) { + console.warn( + `::warning::${hashFile} is missing; the downloaded electron-passkeys artifact predates source hashing`, + ); + return; + } console.error( `::error::${hashFile} is missing; the downloaded electron-passkeys artifact predates source hashing`, );📝 Committable suggestion
🤖 Prompt for AI Agents