From 08791372c394e8bdc65ae99d643a61cdb1fb160e Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 19 Apr 2024 10:04:49 -0400 Subject: [PATCH] test platform --- dist/index.js | 107 +++++++++++++++++++++++++++++++++++++++++++++ dist/platform.d.ts | 15 +++++++ dist/platform.js | 56 ++++++++++++++++++++++++ src/index.ts | 6 +++ src/platform.ts | 94 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 278 insertions(+) create mode 100644 dist/platform.d.ts create mode 100644 dist/platform.js create mode 100644 src/platform.ts diff --git a/dist/index.js b/dist/index.js index 202dd0b..685708a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -87434,6 +87434,34 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; @@ -87443,6 +87471,18 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { +// NAMESPACE OBJECT: ./dist/platform.js +var dist_platform_namespaceObject = {}; +__nccwpck_require__.r(dist_platform_namespaceObject); +__nccwpck_require__.d(dist_platform_namespaceObject, { + "arch": () => (arch), + "getDetails": () => (getDetails), + "isLinux": () => (isLinux), + "isMacOS": () => (isMacOS), + "isWindows": () => (isWindows), + "platform": () => (platform) +}); + ;// CONCATENATED MODULE: external "node:fs/promises" const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs/promises"); // EXTERNAL MODULE: external "node:os" @@ -95085,6 +95125,68 @@ function mungeDiagnosticEndpoint(inputUrl) { +// EXTERNAL MODULE: external "os" +var external_os_ = __nccwpck_require__(2037); +// EXTERNAL MODULE: ./node_modules/.pnpm/@actions+exec@1.1.1/node_modules/@actions/exec/lib/exec.js +var exec = __nccwpck_require__(7775); +;// CONCATENATED MODULE: ./dist/platform.js +// MIT, lifted from https://github.com/actions/toolkit/blob/5a736647a123ecf8582376bdaee833fbae5b3847/packages/core/src/platform.ts +// since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19 + + +const getWindowsInfo = async () => { + const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, { + silent: true, + }); + const { stdout: name } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', undefined, { + silent: true, + }); + return { + name: name.trim(), + version: version.trim(), + }; +}; +const getMacOsInfo = async () => { + const { stdout } = await exec.getExecOutput("sw_vers", undefined, { + silent: true, + }); + const version = stdout.match(/ProductVersion:\s*(.+)/)?.[1] ?? ""; + const name = stdout.match(/ProductName:\s*(.+)/)?.[1] ?? ""; + return { + name, + version, + }; +}; +const getLinuxInfo = async () => { + const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], { + silent: true, + }); + const [name, version] = stdout.trim().split("\n"); + return { + name, + version, + }; +}; +const platform = external_os_.platform(); +const arch = external_os_.arch(); +const isWindows = platform === "win32"; +const isMacOS = platform === "darwin"; +const isLinux = platform === "linux"; +async function getDetails() { + return { + ...(await (isWindows + ? getWindowsInfo() + : isMacOS + ? getMacOsInfo() + : getLinuxInfo())), + platform, + arch, + isWindows, + isMacOS, + isLinux, + }; +} + ;// CONCATENATED MODULE: ./dist/index.js @@ -95097,6 +95199,7 @@ function mungeDiagnosticEndpoint(inputUrl) { + const ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR"; const gotClient = got_dist_source.extend({ retry: { @@ -95350,6 +95453,10 @@ const idslib = new IdsToolbox({ requireNix: "warn", }); idslib.onMain(async () => { + // eslint-disable-next-line no-console + console.log(dist_platform_namespaceObject); + // eslint-disable-next-line no-console + console.log(getDetails()); await setUpAutoCache(idslib); await notifyAutoCache(); }); diff --git a/dist/platform.d.ts b/dist/platform.d.ts new file mode 100644 index 0000000..3d6ecd1 --- /dev/null +++ b/dist/platform.d.ts @@ -0,0 +1,15 @@ +/// +export declare const platform: NodeJS.Platform; +export declare const arch: string; +export declare const isWindows: boolean; +export declare const isMacOS: boolean; +export declare const isLinux: boolean; +export declare function getDetails(): Promise<{ + name: string; + platform: string; + arch: string; + version: string; + isWindows: boolean; + isMacOS: boolean; + isLinux: boolean; +}>; diff --git a/dist/platform.js b/dist/platform.js new file mode 100644 index 0000000..4c3c322 --- /dev/null +++ b/dist/platform.js @@ -0,0 +1,56 @@ +// MIT, lifted from https://github.com/actions/toolkit/blob/5a736647a123ecf8582376bdaee833fbae5b3847/packages/core/src/platform.ts +// 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"; +const getWindowsInfo = async () => { + const { stdout: version } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', undefined, { + silent: true, + }); + const { stdout: name } = await exec.getExecOutput('powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', undefined, { + silent: true, + }); + return { + name: name.trim(), + version: version.trim(), + }; +}; +const getMacOsInfo = async () => { + const { stdout } = await exec.getExecOutput("sw_vers", undefined, { + silent: true, + }); + const version = stdout.match(/ProductVersion:\s*(.+)/)?.[1] ?? ""; + const name = stdout.match(/ProductName:\s*(.+)/)?.[1] ?? ""; + return { + name, + version, + }; +}; +const getLinuxInfo = async () => { + const { stdout } = await exec.getExecOutput("lsb_release", ["-i", "-r", "-s"], { + silent: true, + }); + const [name, version] = stdout.trim().split("\n"); + return { + name, + version, + }; +}; +export const platform = os.platform(); +export const arch = os.arch(); +export const isWindows = platform === "win32"; +export const isMacOS = platform === "darwin"; +export const isLinux = platform === "linux"; +export async function getDetails() { + return { + ...(await (isWindows + ? getWindowsInfo() + : isMacOS + ? getMacOsInfo() + : getLinuxInfo())), + platform, + arch, + isWindows, + isMacOS, + isLinux, + }; +} diff --git a/src/index.ts b/src/index.ts index 169b441..4d53681 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import * as core from "@actions/core"; import { Tail } from "tail"; import got from "got"; import { IdsToolbox } from "detsys-ts"; +import * as platform from "./platform.js"; const ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR"; @@ -309,6 +310,11 @@ const idslib = new IdsToolbox({ }); idslib.onMain(async () => { + // eslint-disable-next-line no-console + console.log(platform); + + // eslint-disable-next-line no-console + console.log(platform.getDetails()); await setUpAutoCache(idslib); await notifyAutoCache(); }); diff --git a/src/platform.ts b/src/platform.ts new file mode 100644 index 0000000..b04befc --- /dev/null +++ b/src/platform.ts @@ -0,0 +1,94 @@ +// MIT, lifted from https://github.com/actions/toolkit/blob/5a736647a123ecf8582376bdaee833fbae5b3847/packages/core/src/platform.ts +// 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"; + +const getWindowsInfo = async (): Promise<{ name: string; version: string }> => { + const { stdout: version } = await exec.getExecOutput( + 'powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"', + undefined, + { + silent: true, + }, + ); + + const { stdout: name } = await exec.getExecOutput( + 'powershell -command "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"', + undefined, + { + silent: true, + }, + ); + + return { + name: name.trim(), + version: version.trim(), + }; +}; + +const getMacOsInfo = async (): Promise<{ + name: string; + version: string; +}> => { + const { stdout } = await exec.getExecOutput("sw_vers", undefined, { + silent: true, + }); + + const version = stdout.match(/ProductVersion:\s*(.+)/)?.[1] ?? ""; + const name = stdout.match(/ProductName:\s*(.+)/)?.[1] ?? ""; + + return { + name, + version, + }; +}; + +const getLinuxInfo = async (): Promise<{ + name: string; + version: string; +}> => { + const { stdout } = await exec.getExecOutput( + "lsb_release", + ["-i", "-r", "-s"], + { + silent: true, + }, + ); + + const [name, version] = stdout.trim().split("\n"); + + return { + name, + version, + }; +}; + +export const platform = os.platform(); +export const arch = os.arch(); +export const isWindows = platform === "win32"; +export const isMacOS = platform === "darwin"; +export const isLinux = platform === "linux"; + +export async function getDetails(): Promise<{ + name: string; + platform: string; + arch: string; + version: string; + isWindows: boolean; + isMacOS: boolean; + isLinux: boolean; +}> { + return { + ...(await (isWindows + ? getWindowsInfo() + : isMacOS + ? getMacOsInfo() + : getLinuxInfo())), + platform, + arch, + isWindows, + isMacOS, + isLinux, + }; +}