refactor action to use INPUTS_JSON object

This commit is contained in:
David Blass
2025-10-13 16:57:02 -04:00
parent cd20491d22
commit a93c34e61b
10 changed files with 56 additions and 26599 deletions
+1 -5
View File
@@ -2,9 +2,5 @@
echo "🔒 Updating lockfile..."
pnpm install --lockfile-only
# Build the action before committing
echo "🔨 Building action..."
npm run build
# Add the built files and lockfile to the commit
git add entry.cjs pnpm-lock.yaml
git add pnpm-lock.yaml
+3 -4
View File
@@ -10,9 +10,6 @@ inputs:
anthropic_api_key:
description: "Anthropic API key for Claude Code authentication"
required: false
github_token:
description: "GitHub token for repository access"
required: false
github_installation_token:
description: "GitHub App installation token"
required: false
@@ -41,7 +38,9 @@ runs:
run: node entry.ts
shell: bash
working-directory: ${{ github.action_path }}
env:
INPUTS_JSON: ${{ toJSON(inputs) }}
branding:
icon: "code"
color: "orange"
color: "green"
-26451
View File
File diff suppressed because one or more lines are too long
+9 -35
View File
@@ -2,49 +2,26 @@
/**
* Entry point for GitHub Action
* This file is bundled to entry.cjs and called directly by GitHub Actions
*/
import * as core from "@actions/core";
import { type ExecutionInputs, type MainParams, main } from "./main.ts";
import { type } from "arktype";
import { main, Inputs } from "./main.ts";
import packageJson from "./package.json" with { type: "json" };
import { setupGitHubInstallationToken } from "./utils/github.ts";
async function run(): Promise<void> {
try {
console.log(`🐸 Running pullfrog/action@${packageJson.version}...`);
const prompt = core.getInput("prompt", { required: true });
const anthropic_api_key = core.getInput("anthropic_api_key");
if (!prompt) {
throw new Error("prompt is required");
const inputsJson = process.env.INPUTS_JSON;
if (!inputsJson) {
throw new Error("INPUTS_JSON environment variable not found");
}
const inputs: ExecutionInputs = {
prompt,
anthropic_api_key,
};
const parsed = type("string.json.parse").assert(inputsJson);
const inputs = Inputs.assert(parsed);
const githubToken = core.getInput("github_token") || process.env.GITHUB_TOKEN;
if (githubToken) {
inputs.github_token = githubToken;
}
const githubInstallationToken =
core.getInput("github_installation_token") || process.env.GITHUB_INSTALLATION_TOKEN;
if (githubInstallationToken) {
inputs.github_installation_token = githubInstallationToken;
} else {
await setupGitHubInstallationToken();
}
const params: MainParams = {
inputs,
env: {},
cwd: process.cwd(),
};
const result = await main(params);
const result = await main(inputs);
if (!result.success) {
throw new Error(result.error || "Agent execution failed");
@@ -55,7 +32,4 @@ async function run(): Promise<void> {
}
}
run().catch((error) => {
console.error("Action failed:", error);
process.exit(1);
});
await run();
-16
View File
@@ -1,16 +0,0 @@
import { build } from "esbuild";
// Build the GitHub Action bundle only
// For npm package builds, use zshy (pnpm build:npm)
await build({
entryPoints: ["./entry.ts"],
bundle: true,
outfile: "./entry.cjs",
format: "cjs",
platform: "node",
target: "node20",
minify: false,
sourcemap: false,
});
console.log("✅ Build completed successfully!");
+1 -2
View File
@@ -6,8 +6,7 @@
export { ClaudeAgent } from "./agents/claude.ts";
export type { Agent, AgentConfig, AgentResult } from "./agents/types.ts";
export {
type ExecutionInputs,
type MainParams,
type ActionInputs as ExecutionInputs,
type MainResult,
main,
} from "./main.ts";
+9 -27
View File
@@ -1,24 +1,14 @@
import * as core from "@actions/core";
import { type } from "arktype";
import { ClaudeAgent } from "./agents/claude.ts";
export const EXPECTED_INPUTS: string[] = [
"ANTHROPIC_API_KEY",
"GITHUB_TOKEN",
"GITHUB_INSTALLATION_TOKEN",
];
export const Inputs = type({
prompt: "string",
"anthropic_api_key?": "string | undefined",
"github_installation_token?": "string | undefined",
});
export interface ExecutionInputs {
prompt: string;
anthropic_api_key: string;
github_token?: string;
github_installation_token?: string;
}
export interface MainParams {
inputs: ExecutionInputs;
env: Record<string, string>;
cwd: string;
}
export type ActionInputs = typeof Inputs.infer;
export interface MainResult {
success: boolean;
@@ -26,19 +16,11 @@ export interface MainResult {
error?: string | undefined;
}
export async function main(params: MainParams): Promise<MainResult> {
export async function main(inputs: ActionInputs): Promise<MainResult> {
try {
const { inputs, env, cwd } = params;
if (cwd !== process.cwd()) {
process.chdir(cwd);
}
Object.assign(process.env, env);
core.info(`→ Starting agent run with Claude Code`);
const agent = new ClaudeAgent({ apiKey: inputs.anthropic_api_key });
const agent = new ClaudeAgent({ apiKey: inputs.anthropic_api_key! });
await agent.install();
const result = await agent.execute(inputs.prompt);
+8 -16
View File
@@ -1,6 +1,6 @@
{
"name": "@pullfrog/action",
"version": "0.0.40",
"version": "0.0.42",
"type": "module",
"files": [
"index.js",
@@ -12,39 +12,31 @@
"main.js",
"main.d.ts"
],
"directories": {
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"typecheck": "tsc --noEmit",
"build": "node esbuild.config.js",
"build:npm": "zshy",
"build:dev": "node esbuild.config.js",
"prepare": "husky",
"play": "node play.ts",
"upDeps": "pnpm up --latest",
"createLockfile": "pnpm --ignore-workspace install"
},
"dependencies": {
"@ark/fs": "0.49.0",
"@actions/core": "^1.11.1",
"@modelcontextprotocol/sdk": "^1.17.5",
"@ark/fs": "0.49.0",
"@modelcontextprotocol/sdk": "^1.20.0",
"@octokit/rest": "^22.0.0",
"@octokit/webhooks-types": "^7.6.1",
"arktype": "^2.1.22",
"dotenv": "^17.2.2",
"dotenv": "^17.2.3",
"execa": "^9.6.0",
"table": "^6.9.0",
"zod": "^3.24.4"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/node": "^24.7.2",
"arg": "^5.0.2",
"esbuild": "^0.25.9",
"husky": "^9.0.0",
"typescript": "^5.3.0",
"zshy": "^0.4.1"
"husky": "^9.1.7",
"typescript": "^5.9.3"
},
"repository": {
"type": "git",
@@ -52,7 +44,7 @@
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/pullfrog/action/issues"
},
+9 -28
View File
@@ -4,7 +4,7 @@ import { pathToFileURL } from "node:url";
import { fromHere } from "@ark/fs";
import arg from "arg";
import { config } from "dotenv";
import { main } from "./main.ts";
import { type ActionInputs, main } from "./main.ts";
import packageJson from "./package.json" with { type: "json" };
import { runAct } from "./utils/act.ts";
import { setupGitHubInstallationToken } from "./utils/github.ts";
@@ -36,38 +36,19 @@ export async function run(
console.log(prompt);
console.log("─".repeat(50));
const { EXPECTED_INPUTS } = await import("./main.ts");
EXPECTED_INPUTS.forEach((inputName) => {
const value = process.env[inputName];
if (value) {
process.env[`INPUT_${inputName.toLowerCase()}`] = value;
}
});
const inputs: any = {
prompt,
anthropic_api_key: process.env.ANTHROPIC_API_KEY || "",
};
if (process.env.GITHUB_TOKEN) {
inputs.github_token = process.env.GITHUB_TOKEN;
}
console.log("🔑 Setting up GitHub installation token...");
const installationToken = await setupGitHubInstallationToken();
inputs.github_installation_token = installationToken;
process.env.GITHUB_INSTALLATION_TOKEN = installationToken;
console.log("✅ GitHub installation token setup successfully");
const envWithToken = {
...process.env,
GITHUB_INSTALLATION_TOKEN: installationToken,
} as Record<string, string>;
const inputs: ActionInputs = {
prompt,
anthropic_api_key: process.env.ANTHROPIC_API_KEY,
github_installation_token: installationToken,
};
const result = await main({
inputs,
env: envWithToken,
cwd: process.cwd(),
});
const result = await main(inputs);
process.chdir(originalCwd);
+16 -15
View File
@@ -2,21 +2,22 @@
"compilerOptions": {
"outDir": "./dist",
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"lib": ["ESNext"],
"target": "ESNext",
"moduleResolution": "NodeNext",
"lib": ["ESNext"],
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
"skipLibCheck": true,
"strict": true,
"noUncheckedSideEffectImports": true,
"declaration": true,
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"stripInternal": true,
"moduleDetection": "force"
"rewriteRelativeImportExtensions": true,
"skipLibCheck": true,
"strict": true,
"noUncheckedSideEffectImports": true,
"declaration": true,
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"stripInternal": true,
"moduleDetection": "force",
"useUnknownInCatchVariables": true
}
}