Skip to content

Commit eb94e7c

Browse files
committed
fix: use github action env var in cli.ts
1 parent ce0eeee commit eb94e7c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

dist/cli.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3636
const svg_1 = require("./svg");
3737
const fs = __importStar(require("fs"));
3838
const path = __importStar(require("path"));
39-
// Get the GitHub username and token from command line arguments or environment variables
40-
const username = process.argv[2] || process.env.GITHUB_USERNAME;
41-
const token = process.argv[3] || process.env.GITHUB_TOKEN;
39+
// Prefer environment variables (GitHub Actions), fallback to CLI args for local dev
40+
const username = process.env.INPUT_GITHUB_USERNAME ||
41+
process.argv[2] ||
42+
process.env.GITHUB_USERNAME;
43+
const token = process.env.INPUT_GITHUB_TOKEN || process.argv[3] || process.env.GITHUB_TOKEN;
4244
// If no token or username is provided, print usage and exit
4345
if (!username || !token) {
4446
console.error("Usage: node cli.js <github-username> <github-token>\n" +
45-
"Or set GITHUB_USERNAME and GITHUB_TOKEN as environment variables.");
47+
"Or set GITHUB_USERNAME and GITHUB_TOKEN as environment variables.\n" +
48+
"Or use in GitHub Actions with 'github_username' and 'github_token' inputs.");
4649
process.exit(1);
4750
}
4851
// Ensure output directory exists

src/cli.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import { generateSVG } from "./svg";
22
import * as fs from "fs";
33
import * as path from "path";
44

5-
// Get the GitHub username and token from command line arguments or environment variables
6-
const username = process.argv[2] || process.env.GITHUB_USERNAME;
7-
const token = process.argv[3] || process.env.GITHUB_TOKEN;
5+
// Prefer environment variables (GitHub Actions), fallback to CLI args for local dev
6+
const username =
7+
process.env.INPUT_GITHUB_USERNAME ||
8+
process.argv[2] ||
9+
process.env.GITHUB_USERNAME;
10+
const token =
11+
process.env.INPUT_GITHUB_TOKEN || process.argv[3] || process.env.GITHUB_TOKEN;
812

913
// If no token or username is provided, print usage and exit
1014
if (!username || !token) {
1115
console.error(
1216
"Usage: node cli.js <github-username> <github-token>\n" +
13-
"Or set GITHUB_USERNAME and GITHUB_TOKEN as environment variables.",
17+
"Or set GITHUB_USERNAME and GITHUB_TOKEN as environment variables.\n" +
18+
"Or use in GitHub Actions with 'github_username' and 'github_token' inputs.",
1419
);
1520
process.exit(1);
1621
}

0 commit comments

Comments
 (0)