Skip to content

Commit 3bb0bd6

Browse files
authored
feat!: Use chrome for testing as default (#632)
This PR introduces significant changes to improve stability and maintainability by switching to Chrome for Testing as the default browser. ### 1. Installer Changes on Channel Name Installs This update replaces previous Chromium builds with the official Chrome for Testing browser on channel name installs. The installation process is simplified by using a standardized Chrome for Testing distribution. The action previously installed the browser to `C:\Program Files` using the official installer on Windows, or to `$RUNNER_TOOL_CACHE` on Linux and macOS with the official archive. Now, the action will install the browser to `$RUNNER_TOOL_CACHE` from [Chrome for Testing][]. [Chrome for Testing]: https://googlechromelabs.github.io/chrome-for-testing/ ### 2. Cache Directory Changes This update introduces a new cache directory structure for the Chrome for Testing browser. The cache directory is now named `chrome` instead of `chromium`. ### 3. Default Version Changes Previously, the action installed the *latest* snapshot version. Now, the action will install the *stable* version of Chrome for Testing by default. ## Migration Guide ### 1. Installer Changes on Channel Name Installs If you are using the channel name (`stable`, `beta`, `dev`, or `canary`) to install the browser, the new version of the action installs the browser from [Chrome for Testing][] instead of the official installer. Please check if your workflow is using the expected browser binary version with the new version of the action. The installed browser binary with the channel name is as follows: | Platform | New Binary Path | |----------|----------------| | Linux | `chrome` | | macOS | `Google Chrome for Testing` | | Windows | `chrome.exe` | On Windows runner, the installed location is changed from `C:\Program Files` to `$RUNNER_TOOL_CACHE`. ### 2. Cache Directory Changes If you are self-hosted runner and installing the browser with the channel name to speed up the runner setup, please update your cache directory on your runners. The cache directory has been changed from `chromium` to `chrome` and ensure that your workflow is using the new cache directory. ### 3. Default Version Changes If you don't specify `chrome-version` parameter in your workflow, please ensure that your workflow will install the expected version of Chrome for Testing. The default version is the *stable* channel version of Chrome for Testing instead of the *latest* version. To install the *latest* version, you need to specify `chrome-version: latest` in your workflow. ```yaml # v1 - name: Install the stable version of Chrome for Testing uses: browser-actions/setup-chrome@v1 with: chrome-version: stable - name: Install the latest version of Chrome for Testing uses: browser-actions/setup-chrome@v1 # v2 - name: Install the stable version of Chrome for Testing uses: browser-actions/setup-chrome@v2 - name: Install the latest version of Chrome for Testing uses: browser-actions/setup-chrome@v2 with: chrome-version: latest ```
1 parent f657ed6 commit 3bb0bd6

16 files changed

+146
-287
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
matrix:
3232
os: [ubuntu, macos, windows]
33-
version: ["", 1295939, 120, dev]
33+
version: ["", 1295939, 120, dev, latest]
3434
runs-on: ${{ matrix.os }}-latest
3535
steps:
3636
- uses: actions/download-artifact@v4

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This action sets-up Google Chrome/Chromium for GitHub Actions. This action suppo
1414
## Usage
1515

1616
Here is a basic usage.
17-
The action installs the latest build by default.
17+
The action installs the stable version of Chrome for Testing by default.
1818

1919
```yaml
2020
steps:
@@ -58,9 +58,9 @@ steps:
5858

5959
The action supports the following version formats:
6060

61-
- The latest snapshot `latest` (default).
61+
- The latest snapshot `latest`.
6262
- Commit positions like `1295939`. You can find commit positions from [here][snapshots].
63-
- Google Chrome release channels: `stable`, `beta`, `dev` and `canary`
63+
- Google Chrome release channels: `stable` (default), `beta`, `dev` and `canary`
6464
- Specific versions: `119`, `120.0.6099`, `121.0.6100.0`. The version are resolved by [Chrome for Testing][].
6565

6666
[Chrome for Testing]: https://googlechromelabs.github.io/chrome-for-testing/

__test__/channel_linux.test.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as fs from "node:fs";
2-
import * as exec from "@actions/exec";
31
import * as tc from "@actions/tool-cache";
42
import { afterEach, describe, expect, test, vi } from "vitest";
53
import * as cache from "../src/cache";
@@ -9,9 +7,6 @@ const cacheFindSpy = vi.spyOn(cache, "find");
97
const cacheCacheDirSpy = vi.spyOn(cache, "cacheDir");
108
const tcDownloadToolSpy = vi.spyOn(tc, "downloadTool");
119
const tcExtractZipSpy = vi.spyOn(tc, "extractZip");
12-
const execSpy = vi.spyOn(exec, "exec");
13-
const fsMkdtempSpy = vi.spyOn(fs.promises, "mkdtemp");
14-
const fsUnlinkSpy = vi.spyOn(fs.promises, "unlink");
1510

1611
afterEach(() => {
1712
vi.resetAllMocks();
@@ -30,11 +25,11 @@ describe("LinuxChannelInstaller", () => {
3025
});
3126

3227
test("return install result if installed", async () => {
33-
cacheFindSpy.mockResolvedValue("/path/to/chromium");
28+
cacheFindSpy.mockResolvedValue("/path/to/chrome");
3429

3530
const result = await installer.checkInstalledBrowser("stable");
3631

37-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
32+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
3833
});
3934
});
4035

@@ -45,12 +40,6 @@ describe("LinuxChannelInstaller", () => {
4540
);
4641
});
4742

48-
test("throw error if version is canary", async () => {
49-
await expect(installer.downloadBrowser("canary")).rejects.toThrowError(
50-
"Chrome canary not supported for platform linux amd64",
51-
);
52-
});
53-
5443
test("download stable version", async () => {
5544
tcDownloadToolSpy.mockResolvedValue("/path/to/downloaded.deb");
5645

@@ -64,31 +53,23 @@ describe("LinuxChannelInstaller", () => {
6453
describe("installBrowser", () => {
6554
test("throw error if version is not release channel", async () => {
6655
await expect(
67-
installer.installBrowser("foo", "/path/to/downloaded.deb"),
56+
installer.installBrowser("foo", "/path/to/downloaded.zip"),
6857
).rejects.toThrowError("Unexpected version: foo");
6958
});
7059

71-
test("throw error if version is canary", async () => {
72-
await expect(
73-
installer.installBrowser("canary", "/path/to/downloaded.deb"),
74-
).rejects.toThrowError("Chrome canary not supported for Linux");
75-
});
76-
7760
test("install stable version", async () => {
78-
fsMkdtempSpy.mockResolvedValue("/deb-abcdef");
79-
fsUnlinkSpy.mockResolvedValue(undefined);
80-
execSpy.mockResolvedValue(0);
81-
cacheCacheDirSpy.mockResolvedValue("/path/to/chromium");
61+
tcExtractZipSpy.mockResolvedValue("/deb-abcdef");
62+
cacheCacheDirSpy.mockResolvedValue("/path/to/chrome");
8263

8364
const result = await installer.installBrowser(
8465
"stable",
8566
"/path/to/downloaded.deb",
8667
);
8768

88-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
69+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
8970
expect(cacheCacheDirSpy).toHaveBeenCalledWith(
90-
"/deb-abcdef",
91-
"chromium",
71+
"/deb-abcdef/chrome-linux64",
72+
"chrome",
9273
"stable",
9374
);
9475
});

__test__/channel_macos.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as fs from "node:fs";
2-
import * as exec from "@actions/exec";
31
import * as tc from "@actions/tool-cache";
42
import { afterEach, describe, expect, test, vi } from "vitest";
53
import * as cache from "../src/cache";
@@ -9,8 +7,6 @@ const cacheFindSpy = vi.spyOn(cache, "find");
97
const cacheCacheDirSpy = vi.spyOn(cache, "cacheDir");
108
const tcDownloadToolSpy = vi.spyOn(tc, "downloadTool");
119
const tcExtractZipSpy = vi.spyOn(tc, "extractZip");
12-
const fsSymlinkSpy = vi.spyOn(fs.promises, "symlink");
13-
const execSpy = vi.spyOn(exec, "exec");
1410

1511
afterEach(() => {
1612
vi.resetAllMocks();
@@ -38,7 +34,7 @@ describe("MacOSChannelInstaller", () => {
3834

3935
expect(result).toEqual({
4036
root: "/path/to/Chromium.app",
41-
bin: "Contents/MacOS/chrome",
37+
bin: "Contents/MacOS/Google Chrome for Testing",
4238
});
4339
});
4440
});
@@ -67,22 +63,21 @@ describe("MacOSChannelInstaller", () => {
6763
});
6864

6965
test("install stable version", async () => {
70-
execSpy.mockResolvedValue(0);
71-
fsSymlinkSpy.mockResolvedValue();
72-
cacheCacheDirSpy.mockResolvedValue("/path/to/Chromium.app");
66+
tcExtractZipSpy.mockResolvedValue("/path/to/archive");
67+
cacheCacheDirSpy.mockResolvedValue("/path/to/Chromium for Testing.app");
7368

7469
const result = await installer.installBrowser(
7570
"stable",
7671
"/path/to/downloaded.dmg",
7772
);
7873

7974
expect(result).toEqual({
80-
root: "/path/to/Chromium.app",
81-
bin: "Contents/MacOS/chrome",
75+
root: "/path/to/Chromium for Testing.app",
76+
bin: "Contents/MacOS/Google Chrome for Testing",
8277
});
8378
expect(cacheCacheDirSpy).toHaveBeenCalledWith(
84-
"/Volumes/downloaded.dmg/Google Chrome.app",
85-
"chromium",
79+
"/path/to/archive/chrome-mac-x64/Google Chrome for Testing.app",
80+
"chrome",
8681
"stable",
8782
);
8883
});

__test__/channel_windows.test.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import * as fs from "node:fs";
2-
import * as exec from "@actions/exec";
32
import * as tc from "@actions/tool-cache";
43
import { afterEach, describe, expect, test, vi } from "vitest";
54
import * as cache from "../src/cache";
65
import { WindowsChannelInstaller } from "../src/channel_windows";
76

8-
const fsStatSpy = vi.spyOn(fs.promises, "stat");
97
const fsRenameSpy = vi.spyOn(fs.promises, "rename");
108
const tcDownloadToolSpy = vi.spyOn(tc, "downloadTool");
119
const tcExtractZipSpy = vi.spyOn(tc, "extractZip");
1210
const cacheFindSpy = vi.spyOn(cache, "find");
1311
const cacheCacheDirSpy = vi.spyOn(cache, "cacheDir");
14-
const execSpy = vi.spyOn(exec, "exec");
1512

1613
afterEach(() => {
1714
vi.resetAllMocks();
@@ -25,21 +22,20 @@ describe("WindowsChannelInstaller", () => {
2522

2623
describe("checkInstalledBrowser", () => {
2724
test("returns undefined if the root directory does not exist", async () => {
25+
cacheFindSpy.mockResolvedValue(undefined);
26+
2827
const result = await installer.checkInstalledBrowser("stable");
2928
expect(result).toBe(undefined);
3029
});
3130

3231
test("returns the root directory and bin path if the root directory exists", async () => {
33-
fsStatSpy.mockResolvedValue(undefined);
32+
cacheFindSpy.mockResolvedValue("C:\\path\\to\\chrome");
3433

3534
const result = await installer.checkInstalledBrowser("stable");
3635
expect(result).toEqual({
37-
root: "C:\\Program Files\\Google\\Chrome\\Application",
36+
root: "C:\\path\\to\\chrome",
3837
bin: "chrome.exe",
3938
});
40-
expect(fsStatSpy).toHaveBeenCalledWith(
41-
"C:\\Program Files\\Google\\Chrome\\Application",
42-
);
4339
});
4440
});
4541

@@ -70,21 +66,17 @@ describe("WindowsChannelInstaller", () => {
7066
});
7167

7268
test("install the stable version of Chrome", async () => {
73-
execSpy.mockResolvedValue(undefined);
74-
fsRenameSpy.mockResolvedValue(undefined);
69+
tcExtractZipSpy.mockResolvedValue("C:\\path\\to\\extract\\directory");
70+
cacheCacheDirSpy.mockResolvedValue("C:\\path\\to\\chrome");
7571

7672
const result = await installer.installBrowser(
7773
"stable",
78-
"C:\\path\\to\\downloaded\\installer.exe",
74+
"C:\\path\\to\\downloaded\\file.zip",
7975
);
8076
expect(result).toEqual({
81-
root: "C:\\Program Files\\Google\\Chrome\\Application",
77+
root: "C:\\path\\to\\chrome",
8278
bin: "chrome.exe",
8379
});
84-
expect(execSpy).toHaveBeenCalledWith(
85-
"C:\\path\\to\\downloaded\\installer.exe",
86-
["/silent", "/install"],
87-
);
8880
});
8981
});
9082

@@ -97,11 +89,11 @@ describe("WindowsChannelInstaller", () => {
9789
});
9890

9991
test("return install result if installed", async () => {
100-
cacheFindSpy.mockResolvedValue("/path/to/chromedriver");
92+
cacheFindSpy.mockResolvedValue("C:\\path\\to\\chromedriver");
10193

10294
const result = await installer.checkInstalledDriver("stable");
10395
expect(result).toEqual({
104-
root: "/path/to/chromedriver",
96+
root: "C:\\path\\to\\chromedriver",
10597
bin: "chromedriver",
10698
});
10799
});

__test__/latest_installer.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ describe("LatestInstaller", () => {
2626

2727
const result = await installer.checkInstalledBrowser("latest");
2828
expect(result).toBe(undefined);
29-
expect(cacheFindSpy).toHaveBeenCalledWith("chromium", "123456");
29+
expect(cacheFindSpy).toHaveBeenCalledWith("chrome", "123456");
3030
});
3131

3232
test("returns install result if installed", async () => {
33-
cacheFindSpy.mockResolvedValue("/path/to/chromium");
33+
cacheFindSpy.mockResolvedValue("/path/to/chrome");
3434

3535
const result = await installer.checkInstalledBrowser("latest");
36-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
36+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
3737
});
3838
});
3939

@@ -52,17 +52,17 @@ describe("LatestInstaller", () => {
5252
describe("installBrowser", () => {
5353
test("installs the browser", async () => {
5454
tcExtractZipSpy.mockResolvedValue("/path/to/ext");
55-
cacheCacheDirSpy.mockResolvedValue("/path/to/chromium");
55+
cacheCacheDirSpy.mockResolvedValue("/path/to/chrome");
5656

5757
const result = await installer.installBrowser(
5858
"latest",
5959
"/tmp/chrome.zip",
6060
);
61-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
61+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
6262
expect(tcExtractZipSpy).toHaveBeenCalled();
6363
expect(cacheCacheDirSpy).toHaveBeenCalledWith(
6464
"/path/to/ext/chrome-linux",
65-
"chromium",
65+
"chrome",
6666
"123456",
6767
);
6868
});

__test__/snapshot_installer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ describe("SnapshotInstaller", () => {
2424
});
2525

2626
test("returns install result if installed", async () => {
27-
cacheFindSpy.mockResolvedValue("/path/to/chromium");
27+
cacheFindSpy.mockResolvedValue("/path/to/chrome");
2828

2929
const result = await installer.checkInstalledBrowser("123456");
30-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
30+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
3131
});
3232
});
3333

@@ -44,13 +44,13 @@ describe("SnapshotInstaller", () => {
4444
describe("installBrowser", () => {
4545
test("installs the browser", async () => {
4646
tcExtractZipSpy.mockResolvedValue("/path/to/ext");
47-
cacheCacheDirSpy.mockResolvedValue("/path/to/chromium");
47+
cacheCacheDirSpy.mockResolvedValue("/path/to/chrome");
4848

4949
const result = await installer.installBrowser(
5050
"123456",
5151
"/tmp/chrome.zip",
5252
);
53-
expect(result).toEqual({ root: "/path/to/chromium", bin: "chrome" });
53+
expect(result).toEqual({ root: "/path/to/chrome", bin: "chrome" });
5454
expect(tcExtractZipSpy).toHaveBeenCalled();
5555
expect(cacheCacheDirSpy).toHaveBeenCalled();
5656
});

__test__/version_installer.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,36 @@ describe("KnownGoodVersionInstaller", () => {
4242

4343
test("checkInstalledBrowser should return installed path if installed", async () => {
4444
cacheFindSpy.mockResolvedValue(
45-
"/opt/hostedtoolcache/setup-chrome/chromium/120.0.6099.56/x64",
45+
"/opt/hostedtoolcache/setup-chrome/chrome/120.0.6099.56/x64",
4646
);
4747

4848
const installed = await installer.checkInstalledBrowser("120.0.6099.x");
4949
expect(installed?.root).toEqual(
50-
"/opt/hostedtoolcache/setup-chrome/chromium/120.0.6099.56/x64",
50+
"/opt/hostedtoolcache/setup-chrome/chrome/120.0.6099.56/x64",
5151
);
52-
expect(cacheFindSpy).toHaveBeenCalledWith("chromium", "120.0.6099.x");
52+
expect(cacheFindSpy).toHaveBeenCalledWith("chrome", "120.0.6099.x");
5353
});
5454

5555
test("downloadBrowser should download browser archive", async () => {
56-
tcDownloadToolSpy.mockImplementation(async () => "/tmp/chromium.zip");
56+
tcDownloadToolSpy.mockImplementation(async () => "/tmp/chrome.zip");
5757

5858
const downloaded = await installer.downloadBrowser("120.0.6099.x");
59-
expect(downloaded?.archive).toEqual("/tmp/chromium.zip");
59+
expect(downloaded?.archive).toEqual("/tmp/chrome.zip");
6060
expect(tcDownloadToolSpy).toHaveBeenCalled();
6161
});
6262

6363
test("installDriver should install browser", async () => {
6464
tcExtractZipSpy.mockImplementation(async () => "/tmp/extracted");
65-
cacheCacheDirSpy.mockImplementation(async () => "/path/to/chromium");
65+
cacheCacheDirSpy.mockImplementation(async () => "/path/to/chrome");
6666

6767
const installed = await installer.installBrowser(
6868
"120.0.6099.x",
69-
"/tmp/chromium.zip",
69+
"/tmp/chrome.zip",
7070
);
71-
expect(installed).toEqual({ root: "/path/to/chromium", bin: "chrome" });
71+
expect(installed).toEqual({ root: "/path/to/chrome", bin: "chrome" });
7272
expect(cacheCacheDirSpy).toHaveBeenCalledWith(
7373
"/tmp/extracted/chrome-linux64",
74-
"chromium",
74+
"chrome",
7575
"120.0.6099.56",
7676
);
7777
});

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
chrome-version:
66
description: |-
77
The Google Chrome/Chromium version to install and use.
8-
default: latest
8+
default: stable
99
required: false
1010
install-dependencies:
1111
description: |-

0 commit comments

Comments
 (0)