Skip to content

Commit 6a6ea3d

Browse files
committed
feat: revert to node action
1 parent 0ec802d commit 6a6ea3d

File tree

6 files changed

+111
-67
lines changed

6 files changed

+111
-67
lines changed

action.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,5 @@ inputs:
1919
required: false
2020

2121
runs:
22-
using: "composite"
23-
steps:
24-
- name: Set GitHub Path
25-
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
26-
shell: bash
27-
env:
28-
GITHUB_ACTION_PATH: ${{ github.action_path }}
29-
- run: action_entrypoint.sh
30-
shell: bash
22+
using: node20
23+
main: dist/cli.js

action_entrypoint.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

dist/cli.js

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@ const svg_1 = require("./svg");
3737
const fs = __importStar(require("fs"));
3838
const path = __importStar(require("path"));
3939
const commander_1 = require("commander");
40+
// Helper to get input from environment variables (for GitHub Actions compatibility)
41+
function getInput(name, fallback) {
42+
// GitHub Actions sets INPUT_<name> (uppercase, underscores)
43+
const envName = `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
44+
return process.env[envName] || fallback;
45+
}
4046
// Create program
4147
const program = new commander_1.Command();
4248
program
4349
.name("github-breakout-cli")
4450
.description("Generate a GitHub Breakout SVG")
45-
.option("--username <github-username>", "GitHub username (or set GITHUB_USERNAME or INPUT_GITHUB_USERNAME env var)", process.env.INPUT_GITHUB_USERNAME || process.env.GITHUB_USERNAME)
46-
.option("--token <github-token>", "GitHub token (or set GITHUB_TOKEN or INPUT_GITHUB_TOKEN env var)", process.env.INPUT_GITHUB_TOKEN || process.env.GITHUB_TOKEN)
51+
.option("--username <github-username>", "GitHub username (or set GITHUB_USERNAME or INPUT_GITHUB_USERNAME env var)", getInput("GITHUB_USERNAME", process.env.GITHUB_USERNAME))
52+
.option("--token <github-token>", "GitHub token (or set GITHUB_TOKEN or INPUT_GITHUB_TOKEN env var)", getInput("GITHUB_TOKEN", process.env.GITHUB_TOKEN))
4753
.option("--dark", "Generate dark mode SVG", false)
48-
.option("--enable-empty-days", "Empty days be used as bricks", false);
54+
.option("--enable-empty-days", "Empty days be used as bricks", !!getInput("ENABLE_EMPTY_DAYS"));
4955
// Parse arguments
5056
program.parse(process.argv);
5157
const options = program.opts();
@@ -61,20 +67,43 @@ const outDir = path.join(process.cwd(), "output");
6167
if (!fs.existsSync(outDir)) {
6268
fs.mkdirSync(outDir, { recursive: true });
6369
}
64-
// Generate file name
65-
const darkMode = !!options.dark;
70+
// Set empty days option
6671
const ignoreEmptyDays = !options.enableEmptyDays;
67-
const outputFile = path.join(outDir, `${darkMode ? "dark" : "light"}.svg`);
68-
// Generate SVG
69-
(0, svg_1.generateSVG)(options.username, options.token, {
70-
darkMode,
71-
ignoreEmptyDays,
72-
})
73-
.then((svg) => {
74-
fs.writeFileSync(outputFile, svg);
75-
console.log(`SVG generated: ${outputFile}`);
76-
})
77-
.catch((err) => {
78-
console.error("Failed to generate SVG:", err);
79-
process.exit(1);
80-
});
72+
// Behavior: If running in GitHub Actions, always generate both light and dark SVGs.
73+
// Otherwise, generate the single requested mode (light by default, dark if --dark is passed).
74+
const isGitHubActions = process.env.GITHUB_ACTIONS === "true";
75+
if (isGitHubActions) {
76+
// Generate both light and dark SVGs for GitHub Actions
77+
const variants = [
78+
{ darkMode: false, name: "light" },
79+
{ darkMode: true, name: "dark" },
80+
];
81+
Promise.all(variants.map(({ darkMode, name }) => (0, svg_1.generateSVG)(options.username, options.token, {
82+
darkMode,
83+
ignoreEmptyDays,
84+
}).then((svg) => {
85+
const outputFile = path.join(outDir, `${name}.svg`);
86+
fs.writeFileSync(outputFile, svg);
87+
console.log(`SVG generated: ${outputFile}`);
88+
}))).catch((err) => {
89+
console.error("Failed to generate SVG(s):", err);
90+
process.exit(1);
91+
});
92+
}
93+
else {
94+
// Generate a single SVG (default: light, or dark if --dark)
95+
const darkMode = !!options.dark;
96+
const outputFile = path.join(outDir, `${darkMode ? "dark" : "light"}.svg`);
97+
(0, svg_1.generateSVG)(options.username, options.token, {
98+
darkMode,
99+
ignoreEmptyDays,
100+
})
101+
.then((svg) => {
102+
fs.writeFileSync(outputFile, svg);
103+
console.log(`SVG generated: ${outputFile}`);
104+
})
105+
.catch((err) => {
106+
console.error("Failed to generate SVG:", err);
107+
process.exit(1);
108+
});
109+
}

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@types/node": "^24.0.14",
1414
"@typescript-eslint/eslint-plugin": "^8.37.0",
1515
"@typescript-eslint/parser": "^8.37.0",
16+
"commander": "^14.0.0",
1617
"eslint": "^9.31.0",
1718
"eslint-config-prettier": "^10.1.5",
1819
"eslint-plugin-prettier": "^5.5.1",
@@ -21,8 +22,5 @@
2122
"ts-node": "^10.9.2",
2223
"typescript": "^5.8.3"
2324
},
24-
"license": "MIT",
25-
"dependencies": {
26-
"commander": "^14.0.0"
27-
}
25+
"license": "MIT"
2826
}

src/cli.ts

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import * as fs from "fs";
33
import * as path from "path";
44
import { Command } from "commander";
55

6+
// Helper to get input from environment variables (for GitHub Actions compatibility)
7+
function getInput(name: string, fallback?: string) {
8+
// GitHub Actions sets INPUT_<name> (uppercase, underscores)
9+
const envName = `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
10+
return process.env[envName] || fallback;
11+
}
12+
613
// Create program
714
const program = new Command();
815
program
@@ -11,15 +18,19 @@ program
1118
.option(
1219
"--username <github-username>",
1320
"GitHub username (or set GITHUB_USERNAME or INPUT_GITHUB_USERNAME env var)",
14-
process.env.INPUT_GITHUB_USERNAME || process.env.GITHUB_USERNAME,
21+
getInput("GITHUB_USERNAME", process.env.GITHUB_USERNAME),
1522
)
1623
.option(
1724
"--token <github-token>",
1825
"GitHub token (or set GITHUB_TOKEN or INPUT_GITHUB_TOKEN env var)",
19-
process.env.INPUT_GITHUB_TOKEN || process.env.GITHUB_TOKEN,
26+
getInput("GITHUB_TOKEN", process.env.GITHUB_TOKEN),
2027
)
2128
.option("--dark", "Generate dark mode SVG", false)
22-
.option("--enable-empty-days", "Empty days be used as bricks", false);
29+
.option(
30+
"--enable-empty-days",
31+
"Empty days be used as bricks",
32+
!!getInput("ENABLE_EMPTY_DAYS"),
33+
);
2334

2435
// Parse arguments
2536
program.parse(process.argv);
@@ -41,21 +52,49 @@ if (!fs.existsSync(outDir)) {
4152
fs.mkdirSync(outDir, { recursive: true });
4253
}
4354

44-
// Generate file name
45-
const darkMode = !!options.dark;
55+
// Set empty days option
4656
const ignoreEmptyDays = !options.enableEmptyDays;
47-
const outputFile = path.join(outDir, `${darkMode ? "dark" : "light"}.svg`);
48-
49-
// Generate SVG
50-
generateSVG(options.username, options.token, {
51-
darkMode,
52-
ignoreEmptyDays,
53-
})
54-
.then((svg) => {
55-
fs.writeFileSync(outputFile, svg);
56-
console.log(`SVG generated: ${outputFile}`);
57-
})
58-
.catch((err) => {
59-
console.error("Failed to generate SVG:", err);
57+
58+
// Behavior: If running in GitHub Actions, always generate both light and dark SVGs.
59+
// Otherwise, generate the single requested mode (light by default, dark if --dark is passed).
60+
const isGitHubActions = process.env.GITHUB_ACTIONS === "true";
61+
62+
if (isGitHubActions) {
63+
// Generate both light and dark SVGs for GitHub Actions
64+
const variants = [
65+
{ darkMode: false, name: "light" },
66+
{ darkMode: true, name: "dark" },
67+
];
68+
69+
Promise.all(
70+
variants.map(({ darkMode, name }) =>
71+
generateSVG(options.username, options.token, {
72+
darkMode,
73+
ignoreEmptyDays,
74+
}).then((svg) => {
75+
const outputFile = path.join(outDir, `${name}.svg`);
76+
fs.writeFileSync(outputFile, svg);
77+
console.log(`SVG generated: ${outputFile}`);
78+
}),
79+
),
80+
).catch((err) => {
81+
console.error("Failed to generate SVG(s):", err);
6082
process.exit(1);
6183
});
84+
} else {
85+
// Generate a single SVG (default: light, or dark if --dark)
86+
const darkMode = !!options.dark;
87+
const outputFile = path.join(outDir, `${darkMode ? "dark" : "light"}.svg`);
88+
generateSVG(options.username, options.token, {
89+
darkMode,
90+
ignoreEmptyDays,
91+
})
92+
.then((svg) => {
93+
fs.writeFileSync(outputFile, svg);
94+
console.log(`SVG generated: ${outputFile}`);
95+
})
96+
.catch((err) => {
97+
console.error("Failed to generate SVG:", err);
98+
process.exit(1);
99+
});
100+
}

0 commit comments

Comments
 (0)