Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ steps:
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: beta
- run: chrome --version
id: setup-chrome
- run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
chrome --version
```

**Note that the installed binary depends on your installation spec.**
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ inputs:
The Google Chrome/Chromium version to install and use.
default: latest
required: false

outputs:
chrome-version:
description: 'The installed Google Chrome/Chromium version. Useful when given a latest version.'
runs:
using: 'node16'
main: 'index.js'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Set up your GitHub Actions workflow with a specific version of chromium",
"main": "dist/index.js",
"dependencies": {
"@actions/core": "^1.9.1",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^1.7.1"
},
Expand Down
51 changes: 41 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as io from "@actions/io";
import * as installer from "./installer";
import { getPlatform, OS } from "./platform";
import { getPlatform, Platform, OS } from "./platform";
import path from "path";

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

const testVersion = async (
platform: Platform,
bin: string
): Promise<string> => {
if (platform.os === OS.WINDOWS) {
const output = await exec.getExecOutput(`powershell`, [
"-Command",
`(Get-Item (Get-Command '${bin}').Source).VersionInfo.ProductVersion`,
]);
if (output.exitCode !== 0) {
throw new Error(
`shell exits with status ${output.exitCode}: ${output.stderr}`
);
}
return output.stdout.trimStart().trimEnd();
}

const output = await exec.getExecOutput(`"${bin}"`, ["--version"], {});
if (output.exitCode !== 0) {
throw new Error(
`chromium exits with status ${output.exitCode}: ${output.stderr}`
);
}
if (
!output.stdout.startsWith("Chromium ") &&
!output.stdout.startsWith("Google Chrome ")
) {
throw new Error(`chromium outputs unexpected results: ${output.stdout}`);
}
return output.stdout
.replace("Chromium ", "")
.replace("Google Chrome ", "")
.split(" ", 1)[0];
};

async function run(): Promise<void> {
try {
const version = core.getInput("chrome-version") || "latest";
Expand All @@ -18,17 +52,14 @@ async function run(): Promise<void> {

const binPath = await installer.install(platform, version);
const installDir = path.dirname(binPath);
const binName = path.basename(binPath);

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

if (platform.os === OS.WINDOWS) {
// Unable to run with command-line option on windows
await io.which("chrome", true);
} else if (platform.os === OS.DARWIN || platform.os === OS.LINUX) {
await exec.exec(binName, ["--version"]);
}
const actualVersion = await testVersion(platform, binPath);

core.info(`Successfully setup chromium version ${actualVersion}`);

core.setOutput("chrome-version", actualVersion);
} catch (error) {
if (hasErrorMessage(error)) {
core.setFailed(error.message);
Expand Down
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
# yarn lockfile v1


"@actions/core@^1.2.6", "@actions/core@^1.9.1":
"@actions/core@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.0.tgz#44551c3c71163949a2f06e94d9ca2157a0cfac4f"
integrity sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==
dependencies:
"@actions/http-client" "^2.0.1"
uuid "^8.3.2"

"@actions/core@^1.2.6":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.9.1.tgz#97c0201b1f9856df4f7c3a375cdcdb0c2a2f750b"
integrity sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==
Expand All @@ -17,6 +25,13 @@
dependencies:
"@actions/io" "^1.0.1"

"@actions/exec@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.1.1.tgz#2e43f28c54022537172819a7cf886c844221a611"
integrity sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==
dependencies:
"@actions/io" "^1.0.1"

"@actions/http-client@^1.0.8":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.9.tgz#af1947d020043dbc6a3b4c5918892095c30ffb52"
Expand Down