-
Notifications
You must be signed in to change notification settings - Fork 459
chore(repo): Build and publish native passkeys binaries on production releases #8955
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
wobsoriano
wants to merge
9
commits into
main
Choose a base branch
from
rob/electron-passkeys-ci-cd
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 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ecc7256
ci(electron-passkeys): build and publish native binaries on productio…
wobsoriano 1258e63
chore(electron-passkeys): add release changeset
wobsoriano ba805d7
Apply suggestions from code review
wobsoriano 9a80889
Merge branch 'main' into rob/electron-passkeys-ci-cd
wobsoriano 3fcfb27
chore: update changeset
wobsoriano ea3cb68
chore: switch to manual trigger
wobsoriano bc8b809
chore: address coderabbit comments
wobsoriano 4246629
chore: clean up
wobsoriano e7caae9
Merge branch 'main' into rob/electron-passkeys-ci-cd
wobsoriano 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
Some comments aren't visible on the classic Files Changed page.
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,5 @@ | ||
| --- | ||
| '@clerk/electron-passkeys': patch | ||
| --- | ||
|
|
||
| Introduce native passkey (WebAuthn) support for Clerk's Electron SDK, with prebuilt binaries for macOS (arm64 and x64) and Windows (arm64 and x64). Installing the package automatically pulls in the matching platform binary, so passkeys work without a local build toolchain. |
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,113 @@ | ||
| name: Electron Passkeys Native Build | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This workflow is manual because native passkey releases are rare. The release workflow consumes the artifact only when publish is pending. |
||
| pull_request: | ||
| paths: | ||
| - 'packages/electron-passkeys/**' | ||
| - '.github/workflows/electron-passkeys.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read | ||
|
|
||
| concurrency: | ||
| group: electron-passkeys-${{ github.head_ref || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
wobsoriano marked this conversation as resolved.
Outdated
|
||
|
|
||
| jobs: | ||
| build: | ||
| name: Build ${{ matrix.settings.target }} | ||
| runs-on: ${{ matrix.settings.host }} | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| settings: | ||
| - host: macos-14 | ||
| target: aarch64-apple-darwin | ||
| - host: macos-14 | ||
| target: x86_64-apple-darwin | ||
| - host: windows-latest | ||
| target: x86_64-pc-windows-msvc | ||
| - host: windows-latest | ||
| target: aarch64-pc-windows-msvc | ||
| defaults: | ||
| run: | ||
| working-directory: packages/electron-passkeys | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - uses: pnpm/action-setup@v4 | ||
|
|
||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.settings.target }} | ||
|
|
||
| - uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| workspaces: packages/electron-passkeys | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --filter @clerk/electron-passkeys... --frozen-lockfile --ignore-scripts | ||
| working-directory: . | ||
|
|
||
| - name: Build native module | ||
| run: pnpm build:native --target ${{ matrix.settings.target }} | ||
|
|
||
| - name: Smoke test (host-native targets only) | ||
| if: matrix.settings.target == 'aarch64-apple-darwin' || matrix.settings.target == 'x86_64-pc-windows-msvc' | ||
| run: node -e "const m = require('./index.js'); console.log('isAvailable:', m.isAvailable(), 'capabilities:', JSON.stringify(m.capabilities())); if (!m.isAvailable()) throw new Error('the loader did not find the freshly built native binary');" | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bindings-${{ matrix.settings.target }} | ||
| path: packages/electron-passkeys/electron-passkeys.*.node | ||
| if-no-files-found: error | ||
|
|
||
| package: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| name: Assemble platform packages | ||
| needs: build | ||
| runs-on: blacksmith-8vcpu-ubuntu-2204 | ||
| timeout-minutes: 10 | ||
| defaults: | ||
| run: | ||
| working-directory: packages/electron-passkeys | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --filter @clerk/electron-passkeys... --frozen-lockfile --ignore-scripts | ||
| working-directory: . | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: packages/electron-passkeys/artifacts | ||
|
|
||
| - name: Move binaries into per-platform npm packages | ||
| run: pnpm artifacts | ||
|
|
||
| - name: Verify every platform package contains its binary | ||
| run: node scripts/check-electron-passkeys-binaries.mjs packages/electron-passkeys/npm | ||
| working-directory: . | ||
|
|
||
| - name: Upload assembled platform binaries | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: electron-passkeys-npm | ||
| path: packages/electron-passkeys/npm/**/*.node | ||
| if-no-files-found: error | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
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,46 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { readdir } from 'node:fs/promises'; | ||
| import { resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| export const DEFAULT_NPM_DIR = 'packages/electron-passkeys/npm'; | ||
|
|
||
| export async function findMissingBinaries(npmDir) { | ||
| const entries = await readdir(npmDir, { withFileTypes: true }); | ||
| const platformDirs = entries.filter(entry => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name)); | ||
| const missing = []; | ||
|
|
||
| for (const platformDir of platformDirs) { | ||
| const dir = resolve(npmDir, platformDir.name); | ||
| const files = await readdir(dir, { withFileTypes: true }); | ||
| const count = files.filter(file => file.isFile() && file.name.endsWith('.node')).length; | ||
|
|
||
| if (count !== 1) { | ||
| missing.push({ dir, count }); | ||
| } | ||
| } | ||
|
|
||
| return missing; | ||
| } | ||
|
|
||
| async function main() { | ||
| const npmDir = process.argv[2] || DEFAULT_NPM_DIR; | ||
| const missing = await findMissingBinaries(npmDir); | ||
|
|
||
| if (missing.length > 0) { | ||
| for (const { dir, count } of missing) { | ||
| console.error( | ||
| `::error::${dir} has ${count} .node binaries (expected exactly 1); publishing it would ship an empty package`, | ||
| ); | ||
| } | ||
|
|
||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log('All electron-passkeys platform packages contain exactly one .node binary.'); | ||
| } | ||
|
|
||
| if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) { | ||
| await main(); | ||
|
wobsoriano marked this conversation as resolved.
|
||
| } | ||
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,52 @@ | ||
| 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 { findMissingBinaries } from './check-electron-passkeys-binaries.mjs'; | ||
|
|
||
| const roots = []; | ||
|
|
||
| async function createRoot() { | ||
| const root = await mkdtemp(join(tmpdir(), 'electron-passkeys-binaries-')); | ||
| roots.push(root); | ||
| return root; | ||
| } | ||
|
|
||
| async function createPlatformDir(root, name, nodeFiles) { | ||
| const dir = join(root, name); | ||
| await mkdir(dir, { recursive: true }); | ||
|
|
||
| await Promise.all(nodeFiles.map(file => writeFile(join(dir, file), ''))); | ||
|
|
||
| return dir; | ||
| } | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(roots.splice(0).map(root => rm(root, { force: true, recursive: true }))); | ||
| }); | ||
|
|
||
| describe('findMissingBinaries', () => { | ||
| test('returns [] when every platform dir has exactly one .node', async () => { | ||
| const root = await createRoot(); | ||
| await createPlatformDir(root, 'darwin-arm64', ['passkeys.node']); | ||
| await createPlatformDir(root, 'linux-x64', ['passkeys.node']); | ||
|
|
||
| await expect(findMissingBinaries(root)).resolves.toEqual([]); | ||
| }); | ||
|
|
||
| test('flags a dir with no .node files', async () => { | ||
| const root = await createRoot(); | ||
| await createPlatformDir(root, 'darwin-arm64', ['README.md']); | ||
|
|
||
| await expect(findMissingBinaries(root)).resolves.toEqual([{ dir: join(root, 'darwin-arm64'), count: 0 }]); | ||
| }); | ||
|
|
||
| test('flags a dir with more than one .node file', async () => { | ||
| const root = await createRoot(); | ||
| await createPlatformDir(root, 'darwin-arm64', ['passkeys.node', 'other.node']); | ||
|
|
||
| await expect(findMissingBinaries(root)).resolves.toEqual([{ dir: join(root, 'darwin-arm64'), count: 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { execFile } from 'node:child_process'; | ||
| import { readFile } from 'node:fs/promises'; | ||
| import { resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
|
|
||
| const WRAPPER_PACKAGE = '@clerk/electron-passkeys'; | ||
| const WRAPPER_MANIFEST = 'packages/electron-passkeys/package.json'; | ||
|
|
||
| async function readInTreeVersion() { | ||
| const manifest = JSON.parse(await readFile(WRAPPER_MANIFEST, 'utf8')); | ||
| return manifest.version; | ||
| } | ||
|
|
||
| async function readLatestPublishedVersion() { | ||
| try { | ||
| const { stdout } = await execFileAsync('npm', ['view', WRAPPER_PACKAGE, 'version']); | ||
| return stdout.trim(); | ||
| } catch { | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| const inTreeVersion = await readInTreeVersion(); | ||
| const latestPublishedVersion = await readLatestPublishedVersion(); | ||
| // npm versions are immutable, so a differing in-tree version means a publish is pending and needs binaries. | ||
| const shouldBuild = inTreeVersion !== latestPublishedVersion; | ||
|
|
||
| console.log(`should-build=${shouldBuild}`); | ||
| } | ||
|
|
||
| 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
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.
all five packages must publish at the same version number. The four platform packages are
optionalDependenciesof the wrapper at an exact version, and napi-rs's native loader matches the.nodebinary by the package version it was built with