Collect some specific lsb_release info

This commit is contained in:
Graham Christensen 2024-04-19 11:43:40 -04:00
parent c4f84c57ff
commit cd56eca96b
4 changed files with 112 additions and 33 deletions

39
dist/index.js generated vendored
View file

@ -95296,6 +95296,7 @@ var linux_release_info_dist = __nccwpck_require__(7540);
const getWindowsInfo = async () => { const getWindowsInfo = async () => {
const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, { const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, {
silent: true, silent: true,
@ -95319,17 +95320,37 @@ const getMacOsInfo = async () => {
version, 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 getLinuxInfo = async () => {
const data = (0,linux_release_info_dist/* releaseInfo */.o)({ mode: "sync" }); let data = {};
// eslint-disable-next-line no-console try {
console.log(data); data = (0,linux_release_info_dist/* releaseInfo */.o)({ mode: "sync" });
const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], { }
silent: true, catch (e) {
}); core.debug(`Error collecting release info: ${e}`);
const [name, version] = stdout.trim().split("\n"); }
return { return {
name, name: getPropertyViaWithDefault(data, ["id", "name", "pretty_name", "id_like"], "unknown"),
version, version: getPropertyViaWithDefault(data, ["version_id", "version", "version_codename"], "unknown"),
}; };
}; };
const platform = external_os_.platform(); const platform = external_os_.platform();

39
dist/platform.js generated vendored
View file

@ -2,6 +2,7 @@
// since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19 // since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19
import os from "os"; import os from "os";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as core from "@actions/core";
import { releaseInfo } from "linux-release-info"; import { releaseInfo } from "linux-release-info";
const getWindowsInfo = async () => { const getWindowsInfo = async () => {
const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, { const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, {
@ -26,17 +27,37 @@ const getMacOsInfo = async () => {
version, 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 getLinuxInfo = async () => {
const data = releaseInfo({ mode: "sync" }); let data = {};
// eslint-disable-next-line no-console try {
console.log(data); data = releaseInfo({ mode: "sync" });
const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], { }
silent: true, catch (e) {
}); core.debug(`Error collecting release info: ${e}`);
const [name, version] = stdout.trim().split("\n"); }
return { return {
name, name: getPropertyViaWithDefault(data, ["id", "name", "pretty_name", "id_like"], "unknown"),
version, version: getPropertyViaWithDefault(data, ["version_id", "version", "version_codename"], "unknown"),
}; };
}; };
export const platform = os.platform(); export const platform = os.platform();

View file

@ -50,4 +50,4 @@
"prettier": "^3.2.5", "prettier": "^3.2.5",
"typescript": "^5.4.5" "typescript": "^5.4.5"
} }
} }

View file

@ -3,6 +3,7 @@
import os from "os"; import os from "os";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as core from "@actions/core";
import { releaseInfo } from "linux-release-info"; import { releaseInfo } from "linux-release-info";
const getWindowsInfo = async (): Promise<{ name: string; version: string }> => { 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<{ const getLinuxInfo = async (): Promise<{
name: string; name: string;
version: string; version: string;
}> => { }> => {
const data = releaseInfo({ mode: "sync" }); let data: object = {};
// eslint-disable-next-line no-console
console.log(data);
const { stdout } = await exec.getExecOutput( try {
"lsb_release", data = releaseInfo({ mode: "sync" });
["-i", "-r", "-s"], } catch (e) {
{ core.debug(`Error collecting release info: ${e}`);
silent: true, }
},
);
const [name, version] = stdout.trim().split("\n");
return { return {
name, name: getPropertyViaWithDefault(
version, data,
["id", "name", "pretty_name", "id_like"],
"unknown",
),
version: getPropertyViaWithDefault(
data,
["version_id", "version", "version_codename"],
"unknown",
),
}; };
}; };