forked from actions/toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move platform helper to helpers package
- Loading branch information
1 parent
fdf7eec
commit dcbbbfe
Showing
9 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
#### Platform helper | ||
|
||
Provides shorthands for getting information about platform action is running on. | ||
|
||
```js | ||
import { platform } from '@actions/core' | ||
|
||
platform.platform // 'win32' | ||
platform.arch // 'x64' | ||
platform.isWindows // true | ||
platform.isMacOS // false | ||
platform.isLinux // false | ||
|
||
const { | ||
name, // Microsoft Windows 11 Enterprise | ||
version, // 10.0.22621 | ||
} = await platform.getInfo() | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
export * as platform from './platform' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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 getInfo(): 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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
}, | ||
"include": [ | ||
"./src" | ||
] | ||
, "__tests__" ] | ||
} |