This commit is contained in:
garronej 2021-12-01 13:39:57 +01:00
commit 5297ab00ab
54 changed files with 18162 additions and 0 deletions

View file

@ -0,0 +1,61 @@
import fetch from "node-fetch";
const urlJoin: typeof import("path").join = require("url-join");
import { setOutputFactory } from "./outputHelper";
import { NpmModuleVersion } from "./tools/NpmModuleVersion";
import { getActionParamsFactory } from "./inputHelper";
export const { getActionParams } = getActionParamsFactory({
"inputNameSubset": [
"owner",
"repo",
"branch",
"compare_to_version"
] as const
});
export type Params = ReturnType<typeof getActionParams>;
type CoreLike = {
debug: (message: string) => void;
};
export const { setOutput } = setOutputFactory<"version" | "compare_result">();
export async function action(
_actionName: "get_package_json_version",
params: Params,
core: CoreLike
): Promise<Parameters<typeof setOutput>[0]> {
core.debug(JSON.stringify(params));
const { owner, repo, branch, compare_to_version } = params;
const version = await fetch(
urlJoin(
"https://raw.github.com",
owner,
repo,
branch,
"package.json"
)
)
.then(res => res.text())
.then(text => JSON.parse(text))
.then(({ version }) => version as string)
.catch(() => "")
;
core.debug(`Version on ${owner}/${repo}#${branch} is ${version}`);
return { 
version,
"compare_result": NpmModuleVersion.compare(
NpmModuleVersion.parse(version || "0.0.0"),
NpmModuleVersion.parse(compare_to_version)
).toString()
};
}