Skip to content

Commit 01ba6fc

Browse files
authored
feat: Output version (browser-actions#319)
1 parent a5f9494 commit 01ba6fc

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ steps:
2929
- uses: browser-actions/setup-chrome@v1
3030
with:
3131
chrome-version: beta
32-
- run: chrome --version
32+
id: setup-chrome
33+
- run: |
34+
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
35+
chrome --version
3336
```
3437
3538
**Note that the installed binary depends on your installation spec.**

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ inputs:
77
The Google Chrome/Chromium version to install and use.
88
default: latest
99
required: false
10-
10+
outputs:
11+
chrome-version:
12+
description: 'The installed Google Chrome/Chromium version. Useful when given a latest version.'
1113
runs:
1214
using: 'node16'
1315
main: 'index.js'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Set up your GitHub Actions workflow with a specific version of chromium",
55
"main": "dist/index.js",
66
"dependencies": {
7-
"@actions/core": "^1.9.1",
7+
"@actions/core": "^1.10.0",
8+
"@actions/exec": "^1.1.1",
89
"@actions/io": "^1.1.2",
910
"@actions/tool-cache": "^1.7.1"
1011
},

src/index.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
11
import * as core from "@actions/core";
22
import * as exec from "@actions/exec";
3-
import * as io from "@actions/io";
43
import * as installer from "./installer";
5-
import { getPlatform, OS } from "./platform";
4+
import { getPlatform, Platform, OS } from "./platform";
65
import path from "path";
76

87
const hasErrorMessage = (e: unknown): e is { message: string | Error } => {
98
return typeof e === "object" && e !== null && "message" in e;
109
};
1110

11+
const testVersion = async (
12+
platform: Platform,
13+
bin: string
14+
): Promise<string> => {
15+
if (platform.os === OS.WINDOWS) {
16+
const output = await exec.getExecOutput(`powershell`, [
17+
"-Command",
18+
`(Get-Item (Get-Command '${bin}').Source).VersionInfo.ProductVersion`,
19+
]);
20+
if (output.exitCode !== 0) {
21+
throw new Error(
22+
`shell exits with status ${output.exitCode}: ${output.stderr}`
23+
);
24+
}
25+
return output.stdout.trimStart().trimEnd();
26+
}
27+
28+
const output = await exec.getExecOutput(`"${bin}"`, ["--version"], {});
29+
if (output.exitCode !== 0) {
30+
throw new Error(
31+
`chromium exits with status ${output.exitCode}: ${output.stderr}`
32+
);
33+
}
34+
if (
35+
!output.stdout.startsWith("Chromium ") &&
36+
!output.stdout.startsWith("Google Chrome ")
37+
) {
38+
throw new Error(`chromium outputs unexpected results: ${output.stdout}`);
39+
}
40+
return output.stdout
41+
.replace("Chromium ", "")
42+
.replace("Google Chrome ", "")
43+
.split(" ", 1)[0];
44+
};
45+
1246
async function run(): Promise<void> {
1347
try {
1448
const version = core.getInput("chrome-version") || "latest";
@@ -18,17 +52,14 @@ async function run(): Promise<void> {
1852

1953
const binPath = await installer.install(platform, version);
2054
const installDir = path.dirname(binPath);
21-
const binName = path.basename(binPath);
2255

2356
core.addPath(path.join(installDir));
24-
core.info(`Successfully setup chromium version ${version}`);
2557

26-
if (platform.os === OS.WINDOWS) {
27-
// Unable to run with command-line option on windows
28-
await io.which("chrome", true);
29-
} else if (platform.os === OS.DARWIN || platform.os === OS.LINUX) {
30-
await exec.exec(binName, ["--version"]);
31-
}
58+
const actualVersion = await testVersion(platform, binPath);
59+
60+
core.info(`Successfully setup chromium version ${actualVersion}`);
61+
62+
core.setOutput("chrome-version", actualVersion);
3263
} catch (error) {
3364
if (hasErrorMessage(error)) {
3465
core.setFailed(error.message);

yarn.lock

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
# yarn lockfile v1
33

44

5-
"@actions/core@^1.2.6", "@actions/core@^1.9.1":
5+
"@actions/core@^1.10.0":
6+
version "1.10.0"
7+
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.0.tgz#44551c3c71163949a2f06e94d9ca2157a0cfac4f"
8+
integrity sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==
9+
dependencies:
10+
"@actions/http-client" "^2.0.1"
11+
uuid "^8.3.2"
12+
13+
"@actions/core@^1.2.6":
614
version "1.9.1"
715
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.9.1.tgz#97c0201b1f9856df4f7c3a375cdcdb0c2a2f750b"
816
integrity sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==
@@ -17,6 +25,13 @@
1725
dependencies:
1826
"@actions/io" "^1.0.1"
1927

28+
"@actions/exec@^1.1.1":
29+
version "1.1.1"
30+
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.1.1.tgz#2e43f28c54022537172819a7cf886c844221a611"
31+
integrity sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==
32+
dependencies:
33+
"@actions/io" "^1.0.1"
34+
2035
"@actions/http-client@^1.0.8":
2136
version "1.0.9"
2237
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.9.tgz#af1947d020043dbc6a3b4c5918892095c30ffb52"

0 commit comments

Comments
 (0)