Repository navigation
Dispatch add-auth evals after stable Clerk CLI releases #539
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,24 @@ jobs: | |
| ARTIFACTS_DIR: ${{ github.workspace }}/dist/artifacts | ||
| GH_TOKEN: ${{ github.token }} | ||
|
|
||
| dispatch-add-auth-eval: | ||
| needs: [versioning, publish-npm] | ||
| if: needs.versioning.outputs.release_created == 'true' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: oven-sh/setup-bun@v2 | ||
| - name: Notify clerk-evals of the stable release | ||
| run: bun scripts/dispatch-evals.ts | ||
| env: | ||
| CLERK_CLI_VERSION: ${{ needs.versioning.outputs.version }} | ||
| CLERK_EVALS_DISPATCH_TOKEN: ${{ secrets.CLERK_EVALS_DISPATCH_TOKEN }} | ||
|
|
||
| publish-github: | ||
| needs: [versioning, build, sign-macos, smoke-test, publish-npm] | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -175,7 +193,7 @@ jobs: | |
| always() && | ||
| needs.versioning.outputs.release_created == 'true' && | ||
| contains(needs.*.result, 'failure') | ||
| needs: [versioning, build, sign-macos, smoke-test, publish-npm, publish-github, homebrew] | ||
| needs: [versioning, build, sign-macos, smoke-test, publish-npm, publish-github, homebrew, dispatch-add-auth-eval] | ||
|
Contributor
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. If publishing succeeds and the dispatch fails, this posts "Stable release failed" while Maybe give the dispatch its own failure alert instead, like the |
||
| uses: ./.github/workflows/notify-failure.yml | ||
| with: | ||
| workflow-name: Stable release | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { assertStableVersion, sendCliReleaseDispatch } from "./dispatch-evals.ts"; | ||
|
|
||
| describe("stable CLI eval dispatch", () => { | ||
| test("rejects canary and snapshot versions", () => { | ||
| expect(() => assertStableVersion("3.5.0-canary.1")).toThrow("stable"); | ||
| expect(() => assertStableVersion("3.5.0-snapshot.1")).toThrow("stable"); | ||
| expect(() => assertStableVersion("3.5.0")).not.toThrow(); | ||
| }); | ||
|
|
||
| test("sends the released version as a repository dispatch", async () => { | ||
| let request: { url: string; init?: RequestInit } | undefined; | ||
| await sendCliReleaseDispatch("3.5.0", "test-token", async (url, init) => { | ||
| request = { url, init }; | ||
| return new Response(null, { status: 204 }); | ||
| }); | ||
| expect(request?.url).toBe("https://api.github.com/repos/clerk/clerk-evals/dispatches"); | ||
| expect(request?.init?.method).toBe("POST"); | ||
| expect(JSON.parse(String(request?.init?.body))).toEqual({ | ||
| event_type: "clerk_cli_released", | ||
| client_payload: { version: "3.5.0" }, | ||
| }); | ||
| }); | ||
|
|
||
| test("requires the dedicated credential and reports API rejection", async () => { | ||
| await expect(sendCliReleaseDispatch("3.5.0", "")).rejects.toThrow("CLERK_EVALS_DISPATCH_TOKEN"); | ||
| await expect( | ||
| sendCliReleaseDispatch( | ||
| "3.5.0", | ||
| "test-token", | ||
| async () => new Response('{"message":"Forbidden"}', { status: 403 }), | ||
| ), | ||
| ).rejects.toThrow("HTTP 403"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||
| /** Notify the add-auth eval receiver after a stable CLI release is published. */ | ||||
|
|
||||
| type Fetch = (input: string, init?: RequestInit) => Promise<Response>; | ||||
|
|
||||
| export function assertStableVersion(version: string): void { | ||||
| if (!/^\d+\.\d+\.\d+$/.test(version)) { | ||||
| throw new Error(`Expected a stable Clerk CLI version, got ${JSON.stringify(version)}`); | ||||
| } | ||||
| } | ||||
|
|
||||
| export async function sendCliReleaseDispatch( | ||||
| version: string, | ||||
| token: string, | ||||
| fetchImpl: Fetch = fetch, | ||||
| ): Promise<void> { | ||||
| assertStableVersion(version); | ||||
| if (!token) throw new Error("CLERK_EVALS_DISPATCH_TOKEN is not configured"); | ||||
|
|
||||
| const response = await fetchImpl("https://api.github.com/repos/clerk/clerk-evals/dispatches", { | ||||
| method: "POST", | ||||
| headers: { | ||||
| accept: "application/vnd.github+json", | ||||
| authorization: `Bearer ${token}`, | ||||
| "content-type": "application/json", | ||||
| "x-github-api-version": "2022-11-28", | ||||
| }, | ||||
| body: JSON.stringify({ event_type: "clerk_cli_released", client_payload: { version } }), | ||||
| signal: AbortSignal.timeout(15_000), | ||||
| }); | ||||
| if (response.status !== 204) { | ||||
| const detail = (await response.text().catch(() => "")).slice(0, 200); | ||||
| throw new Error( | ||||
| `clerk-evals dispatch returned HTTP ${response.status}${detail ? `: ${detail}` : ""}`, | ||||
| ); | ||||
| } | ||||
| } | ||||
|
|
||||
| if (import.meta.main) { | ||||
| const version = process.env.CLERK_CLI_VERSION ?? ""; | ||||
| const token = process.env.CLERK_EVALS_DISPATCH_TOKEN ?? ""; | ||||
| if (!token) throw new Error("CLERK_EVALS_DISPATCH_TOKEN is not configured"); | ||||
|
Contributor
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.
Suggested change
|
||||
| await sendCliReleaseDispatch(version, token); | ||||
| console.log(`Sent clerk_cli_released for clerk@${version} to clerk/clerk-evals`); | ||||
| } | ||||
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.
This job sends
clerk_cli_released, which is already a generic event. The job and script names describe what clerk-evals does with it today, not what this workflow does.clerk/skills has the same kind of sender, and it's named after its event:
dispatch-skills-updated.ymlanddispatch-skills-update.mjs. It sends one event to clerk, dashboard, and clerk-evals, so adding a receiver is a one-line change.Could we match that here?
dispatch-cli-releasedfor the job andscripts/dispatch-cli-released.tsfor the script, with the step name and thedocs/releasing.mdparagraph to match.Same idea for the secret while it doesn't exist yet:
CLERK_CLI_DISPATCH_TOKENwould follow theCLERK_SKILLS_DISPATCH_TOKENnaming. Your call on that one.That way none of it is tied to evals, and anything interested in CLI releases can use this.