Skip to content

Commit d153c9f

Browse files
committed
(refactor) (openai/gpt-5.5, reviewed T, tested T) move register workflow template to yaml
1 parent ba3996a commit d153c9f

5 files changed

Lines changed: 51 additions & 33 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ release path. They mutate `cli/package.json`.
5959
by the CLI `init` command.
6060
- `local-rpc.sh`: root helper that starts Anvil, deploys a contract, prints the
6161
RPC URL/private key/owner/contract address, and waits until interrupted.
62-
- `cli/src/index.ts`: Commander CLI entrypoint and workflow template.
62+
- `cli/src/index.ts`: Commander CLI entrypoint.
63+
- `cli/templates/fcf-register.yml`: workflow template emitted by CLI `init`.
6364
- `cli/src/oidc.ts`: JWT base64url helpers, parsing, and GitHub `kid` hashing.
6465
- `cli/src/importAbi.ts`: loads the committed static ABI by default.
6566
- `cli/src/abi/RIK.json`: committed generated ABI used by the published CLI.
@@ -97,7 +98,7 @@ release path. They mutate `cli/package.json`.
9798
JWT payloads.
9899
- `cli/src/importAbi.ts` defaults to the committed static ABI. `SKIP_STATIC_ABI`
99100
switches to the Foundry artifact path for local development.
100-
- Keep `cli/src/index.ts`'s `REGISTER_WORKFLOW` template and
101+
- Keep `cli/templates/fcf-register.yml` and
101102
`.github/workflows/fcf-register.yml` behavior in sync when registration
102103
workflow semantics change.
103104
- Contract ABI changes must be followed by `cd cli && pnpm abi` so the packaged

cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"files": [
1010
"dist",
11-
"src/abi/RIK.json"
11+
"src/abi/RIK.json",
12+
"templates"
1213
],
1314
"publishConfig": {
1415
"access": "public"

cli/src/index.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { sepolia, foundry } from "viem/chains";
77
import { importAbi } from "@/importAbi.js";
88
import packageJson from "../package.json" with { type: "json" };
99
import { exit } from "node:process";
10-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
10+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
1111
import { dirname } from "node:path";
1212
import { b64urlToHex, jwtKid, parseJwt } from "./oidc.js";
1313

@@ -16,35 +16,8 @@ const COMMAND_DESCRIPTION = "FCF CLI tool."
1616
const VERSION = packageJson?.version || "v0.0.1";
1717
const GITHUB_ISSUER = "https://token.actions.githubusercontent.com";
1818
const REGISTER_WORKFLOW_PATH = ".github/workflows/fcf-register.yml";
19+
const REGISTER_WORKFLOW_TEMPLATE_PATH = new URL("../templates/fcf-register.yml", import.meta.url);
1920
const DEFAULT_LIST_BLOCK_RANGE = 50_000n;
20-
const REGISTER_WORKFLOW = `name: Register Repository
21-
22-
on:
23-
workflow_dispatch:
24-
25-
permissions:
26-
contents: read
27-
id-token: write
28-
29-
jobs:
30-
register:
31-
runs-on: ubuntu-latest
32-
steps:
33-
- uses: actions/checkout@v6
34-
35-
- uses: actions/setup-node@v6
36-
with:
37-
node-version: 24
38-
39-
- name: Register repository
40-
env:
41-
PRIVATE_KEY: \${{ secrets.FCF_PRIVATE_KEY }}
42-
RPC_URL: \${{ vars.FCF_RPC_URL }}
43-
FCF_CONTRACT: \${{ vars.FCF_CONTRACT }}
44-
run: |
45-
npm exec --yes --package=@freecodexyz/cli@alpha -- fcf register \\
46-
--contract "$FCF_CONTRACT"
47-
`;
4821

4922
function die(err: any): never {
5023
let error = "unknown error";
@@ -116,8 +89,15 @@ program
11689
die(new Error(`${REGISTER_WORKFLOW_PATH} already exists`));
11790
}
11891

92+
let registerWorkflow: string;
93+
try {
94+
registerWorkflow = readFileSync(REGISTER_WORKFLOW_TEMPLATE_PATH, "utf8");
95+
} catch (err) {
96+
die(err);
97+
}
98+
11999
mkdirSync(dirname(REGISTER_WORKFLOW_PATH), { recursive: true });
120-
writeFileSync(REGISTER_WORKFLOW_PATH, REGISTER_WORKFLOW);
100+
writeFileSync(REGISTER_WORKFLOW_PATH, registerWorkflow);
121101
console.log(`created: ${REGISTER_WORKFLOW_PATH}`);
122102
});
123103

cli/templates/fcf-register.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Register Repository
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
id-token: write
9+
10+
jobs:
11+
register:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
16+
- uses: actions/setup-node@v6
17+
with:
18+
node-version: 24
19+
20+
- name: Register repository
21+
env:
22+
PRIVATE_KEY: ${{ secrets.FCF_PRIVATE_KEY }}
23+
RPC_URL: ${{ vars.FCF_RPC_URL }}
24+
FCF_CONTRACT: ${{ vars.FCF_CONTRACT }}
25+
run: |
26+
npm exec --yes --package=@freecodexyz/cli@alpha -- fcf register \
27+
--contract "$FCF_CONTRACT"

cli/test/workflow-template.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { readFileSync } from "node:fs";
2+
import { test, expect } from "vitest";
3+
4+
test("registration workflow template matches checked-in workflow", () => {
5+
const template = readFileSync(new URL("../templates/fcf-register.yml", import.meta.url), "utf8");
6+
const workflow = readFileSync(new URL("../../.github/workflows/fcf-register.yml", import.meta.url), "utf8");
7+
8+
expect(template).toBe(workflow);
9+
});

0 commit comments

Comments
 (0)