mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 17:30:34 +01:00
Collect some specific lsb_release info
This commit is contained in:
parent
c4f84c57ff
commit
cd56eca96b
4 changed files with 112 additions and 33 deletions
39
dist/index.js
generated
vendored
39
dist/index.js
generated
vendored
|
@ -95296,6 +95296,7 @@ var linux_release_info_dist = __nccwpck_require__(7540);
|
|||
|
||||
|
||||
|
||||
|
||||
const getWindowsInfo = async () => {
|
||||
const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, {
|
||||
silent: true,
|
||||
|
@ -95319,17 +95320,37 @@ const getMacOsInfo = async () => {
|
|||
version,
|
||||
};
|
||||
};
|
||||
function getPropertyViaWithDefault(data, names, defaultValue) {
|
||||
for (const name of names) {
|
||||
const ret = getPropertyWithDefault(data, name, undefined);
|
||||
if (ret !== undefined) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
function getPropertyWithDefault(data, name, defaultValue) {
|
||||
if (!data.hasOwnProperty(name)) {
|
||||
return defaultValue;
|
||||
}
|
||||
const value = data[name];
|
||||
// NB. this check won't work for object instances
|
||||
if (typeof value !== typeof defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const getLinuxInfo = async () => {
|
||||
const data = (0,linux_release_info_dist/* releaseInfo */.o)({ mode: "sync" });
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], {
|
||||
silent: true,
|
||||
});
|
||||
const [name, version] = stdout.trim().split("\n");
|
||||
let data = {};
|
||||
try {
|
||||
data = (0,linux_release_info_dist/* releaseInfo */.o)({ mode: "sync" });
|
||||
}
|
||||
catch (e) {
|
||||
core.debug(`Error collecting release info: ${e}`);
|
||||
}
|
||||
return {
|
||||
name,
|
||||
version,
|
||||
name: getPropertyViaWithDefault(data, ["id", "name", "pretty_name", "id_like"], "unknown"),
|
||||
version: getPropertyViaWithDefault(data, ["version_id", "version", "version_codename"], "unknown"),
|
||||
};
|
||||
};
|
||||
const platform = external_os_.platform();
|
||||
|
|
39
dist/platform.js
generated
vendored
39
dist/platform.js
generated
vendored
|
@ -2,6 +2,7 @@
|
|||
// since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19
|
||||
import os from "os";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as core from "@actions/core";
|
||||
import { releaseInfo } from "linux-release-info";
|
||||
const getWindowsInfo = async () => {
|
||||
const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, {
|
||||
|
@ -26,17 +27,37 @@ const getMacOsInfo = async () => {
|
|||
version,
|
||||
};
|
||||
};
|
||||
function getPropertyViaWithDefault(data, names, defaultValue) {
|
||||
for (const name of names) {
|
||||
const ret = getPropertyWithDefault(data, name, undefined);
|
||||
if (ret !== undefined) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
function getPropertyWithDefault(data, name, defaultValue) {
|
||||
if (!data.hasOwnProperty(name)) {
|
||||
return defaultValue;
|
||||
}
|
||||
const value = data[name];
|
||||
// NB. this check won't work for object instances
|
||||
if (typeof value !== typeof defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const getLinuxInfo = async () => {
|
||||
const data = releaseInfo({ mode: "sync" });
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], {
|
||||
silent: true,
|
||||
});
|
||||
const [name, version] = stdout.trim().split("\n");
|
||||
let data = {};
|
||||
try {
|
||||
data = releaseInfo({ mode: "sync" });
|
||||
}
|
||||
catch (e) {
|
||||
core.debug(`Error collecting release info: ${e}`);
|
||||
}
|
||||
return {
|
||||
name,
|
||||
version,
|
||||
name: getPropertyViaWithDefault(data, ["id", "name", "pretty_name", "id_like"], "unknown"),
|
||||
version: getPropertyViaWithDefault(data, ["version_id", "version", "version_codename"], "unknown"),
|
||||
};
|
||||
};
|
||||
export const platform = os.platform();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
import os from "os";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as core from "@actions/core";
|
||||
import { releaseInfo } from "linux-release-info";
|
||||
|
||||
const getWindowsInfo = async (): Promise<{ name: string; version: string }> => {
|
||||
|
@ -45,27 +46,63 @@ const getMacOsInfo = async (): Promise<{
|
|||
};
|
||||
};
|
||||
|
||||
function getPropertyViaWithDefault<T, Property extends string>(
|
||||
data: object,
|
||||
names: Property[],
|
||||
defaultValue: T,
|
||||
): T {
|
||||
for (const name of names) {
|
||||
const ret: T | undefined = getPropertyWithDefault(data, name, undefined);
|
||||
if (ret !== undefined) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
function getPropertyWithDefault<T, Property extends string>(
|
||||
data: object,
|
||||
name: Property,
|
||||
defaultValue: T,
|
||||
): T {
|
||||
if (!data.hasOwnProperty(name)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
const value = (data as { [K in Property]: T })[name];
|
||||
|
||||
// NB. this check won't work for object instances
|
||||
if (typeof value !== typeof defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const getLinuxInfo = async (): Promise<{
|
||||
name: string;
|
||||
version: string;
|
||||
}> => {
|
||||
const data = releaseInfo({ mode: "sync" });
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
let data: object = {};
|
||||
|
||||
const { stdout } = await exec.getExecOutput(
|
||||
"lsb_release",
|
||||
["-i", "-r", "-s"],
|
||||
{
|
||||
silent: true,
|
||||
},
|
||||
);
|
||||
|
||||
const [name, version] = stdout.trim().split("\n");
|
||||
try {
|
||||
data = releaseInfo({ mode: "sync" });
|
||||
} catch (e) {
|
||||
core.debug(`Error collecting release info: ${e}`);
|
||||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
version,
|
||||
name: getPropertyViaWithDefault(
|
||||
data,
|
||||
["id", "name", "pretty_name", "id_like"],
|
||||
"unknown",
|
||||
),
|
||||
version: getPropertyViaWithDefault(
|
||||
data,
|
||||
["version_id", "version", "version_codename"],
|
||||
"unknown",
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue