mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
Follow up from https://github.com/garronej/github_actions_toolkit
This commit is contained in:
commit
5297ab00ab
54 changed files with 18162 additions and 0 deletions
61
src/get_package_json_version.ts
Normal file
61
src/get_package_json_version.ts
Normal 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()
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue