Skip to content

Commit c17d6b8

Browse files
committed
✨ avoid bundling @actions/core
1 parent 24b99d6 commit c17d6b8

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

packages/action/github-action.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as os from "node:os";
2+
3+
/**
4+
* re-export getInput from "@actions/core" without the bloat
5+
*/
6+
export const getInput = (name: string) =>
7+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
8+
9+
/**
10+
* re-export setFailed from "@actions/core" without the bloat
11+
*/
12+
export const setFailed = (message: string) => {
13+
process.exitCode = 1;
14+
process.stdout.write(`::error::${escapeData(message)}::${os.EOL}`);
15+
};
16+
17+
function escapeData(s: string): string {
18+
return s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
19+
}

packages/action/index.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import * as fs from "fs";
2-
import * as path from "path";
3-
import * as core from "@actions/core";
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
43
import { parseOutputsOption } from "./outputsOptions";
4+
import * as githubAction from "./github-action";
55

66
(async () => {
77
try {
8-
const userName = core.getInput("github_user_name");
9-
const outputs = parseOutputsOption(
10-
core.getMultilineInput("outputs") ?? [
11-
core.getInput("gif_out_path"),
12-
core.getInput("svg_out_path"),
13-
],
14-
);
8+
const userName = githubAction.getInput("github_user_name");
9+
const outputsRaw = [
10+
...githubAction.getInput("outputs").split("\n"),
11+
//
12+
// legacy
13+
githubAction.getInput("gif_out_path"),
14+
githubAction.getInput("svg_out_path"),
15+
]
16+
.map((x) => x.trim())
17+
.filter(Boolean);
18+
19+
const outputs = parseOutputsOption(outputsRaw);
1520
const githubToken =
16-
process.env.GITHUB_TOKEN ?? core.getInput("github_token");
21+
process.env.GITHUB_TOKEN ?? githubAction.getInput("github_token");
1722

1823
const { generateContributionSnake } = await import(
1924
"./generateContributionSnake"
@@ -31,6 +36,6 @@ import { parseOutputsOption } from "./outputsOptions";
3136
}
3237
});
3338
} catch (e: any) {
34-
core.setFailed(`Action failed with "${e.message}"`);
39+
githubAction.setFailed(`Action failed with "${e.message}"`);
3540
}
3641
})();

0 commit comments

Comments
 (0)