Skip to content

Commit 775b8fb

Browse files
authored
feat: Support to install by a specific version (#444)
This supports to install the browser by a specific version. It is helpful to check the compatibility between major versions. User can specific the version by a major version like `119`, or more specific version including minor, patch, and build version like `120.0.6099` or `121.0.6100.0`. Available versions are published in [Chrome for Testing][] and the version is resolved from them. [Chrome for Testing]: https://googlechromelabs.github.io/chrome-for-testing/
1 parent f318cc2 commit 775b8fb

14 files changed

+2741
-178
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ updates:
2020
- "eslint"
2121
- "eslint-*"
2222
- "prettier"
23+
jest:
24+
patterns:
25+
- "jest"
26+
- "jest-*"
27+
- "ts-jest"
28+
- "@types/jest"

.github/workflows/build.yml

+10-30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
cache: 'pnpm'
1919
- run: pnpm install --frozen-lockfile
2020
- run: pnpm lint
21+
- run: pnpm test
2122
- run: pnpm build
2223
- run: pnpm package
2324
- uses: actions/upload-artifact@v3
@@ -30,42 +31,21 @@ jobs:
3031
strategy:
3132
matrix:
3233
os: [ubuntu, macos, windows]
34+
version: ["", 827102, 120, dev]
3335
runs-on: ${{ matrix.os }}-latest
3436
steps:
3537
- uses: actions/download-artifact@v3
3638
with:
3739
name: dist
3840

39-
- name: Install with no params
40-
uses: ./
41-
- if: runner.os == 'Linux'
42-
run: chrome --version
43-
- if: runner.os == 'macOS'
44-
run: chromium --version
45-
- if: runner.os == 'Windows'
46-
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
47-
# Unable to run with command-line option on windows
48-
49-
- name: Install with version '827102'
50-
uses: ./
51-
with:
52-
chrome-version: 827102
53-
- if: runner.os == 'Linux'
54-
run: chrome --version
55-
- if: runner.os == 'macOS'
56-
run: chromium --version
57-
- if: runner.os == 'Windows'
58-
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
59-
# Unable to run with command-line option on windows
60-
61-
- name: install with version 'dev'
41+
- name: Install Google Chrome
6242
uses: ./
6343
with:
64-
chrome-version: dev
65-
- if: runner.os == 'Linux'
66-
run: chrome --version
67-
- if: runner.os == 'macOS'
68-
run: chrome --version
44+
chrome-version: ${{ matrix.version }}
45+
id: setup-chrome
46+
- if: runner.os == 'Linux' || runner.os == 'macOS'
47+
run: |
48+
"${{ steps.setup-chrome.outputs.chrome-path }}" --version
6949
- if: runner.os == 'Windows'
70-
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
71-
# Unable to run with command-line option on windows
50+
run: |
51+
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion

.github/workflows/manual-test.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
cache: 'pnpm'
2828
- run: pnpm install --frozen-lockfile
2929
- run: pnpm lint
30+
- run: pnpm test
3031
- run: pnpm build
3132
- run: pnpm package
3233
- uses: actions/upload-artifact@v3
@@ -47,6 +48,8 @@ jobs:
4748
chrome-version: ${{ inputs.chrome-version }}
4849
id: setup-chrome
4950
- if: runner.os == 'Linux' || runner.os == 'macOS'
50-
run: ${{ steps.setup-chrome.outputs.chrome-path }} --version
51+
run: |
52+
"${{ steps.setup-chrome.outputs.chrome-path }}" --version
5153
- if: runner.os == 'Windows'
52-
run: (Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
54+
run: |
55+
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion

README.md

+30-27
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,66 @@ This action sets by Google Chrome/Chromium for use in actions by:
99
- [X] Install and setup latest Chromium
1010
- [X] Cross platform runner (macOS, Linux, Windows)
1111
- [X] Install Google Chrome by channel (stable, beta, dev, and canary)
12-
- [ ] Install by version number (88.0.4324, or 88.0)
12+
- [X] Install by version number (88.0.4324, or 88.0)
1313

1414
## Usage
1515

16-
See [action.yml](action.yml)
17-
18-
Basic usage:
16+
Here is a basic usage.
17+
The action installs the latest build by default.
1918

2019
```yaml
2120
steps:
2221
- uses: browser-actions/setup-chrome@v1
2322
- run: chrome --version
2423
```
2524
26-
Install Google Chrome Beta
25+
To install a specific channel, use `chrome-version` input.
26+
2727
```yaml
2828
steps:
2929
- uses: browser-actions/setup-chrome@v1
3030
with:
31-
chrome-version: beta
32-
id: setup-chrome
33-
- run: |
34-
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
35-
${{ steps.setup-chrome.outputs.chrome-path }} --version
31+
chrome-version: 120
3632
```
3733

38-
**Note that the installed binary depends on your installation spec.**
34+
### Supported version formats
3935

40-
The installed binary name depends on the version you specify and your platform.
41-
The summarized binary names are the following:
36+
The action supports the following version formats:
4237

43-
| OS \ installed version | `latest` (default) | commit position (e.g. `848897`) | channel name (e.g. `dev`) |
44-
| --- | --- | --- | --- |
45-
| Windows | chrome | chrome | chrome |
46-
| macOS | chromium | chromium | chrome |
47-
| Linux | chrome | chrome | chrome |
38+
- The latest snapshot `latest` (default).
39+
- Commit positions like `848897`. You can find commit positions from [here][snapshots].
40+
- Google Chrome release channels: `stable`, `beta`, `dev` and `canary`
41+
- Specific versions: `119`, `120.0.6099`, `121.0.6100.0`. The version are resolved by [Chrome for Testing][].
4842

43+
[Chrome for Testing]: https://googlechromelabs.github.io/chrome-for-testing/
4944

45+
### Installed path
5046

51-
Be sure to pass a full-path to `chrome` or `chromium` to your test system if
52-
the system expects that `chromium` exists in PATH such as [karma-chromium-runner][]:
47+
The installed binary name is not always `chrome` or `chromium`.
48+
It depends on your installation spec and OS.
5349

54-
[karma-chromium-runner]: https://github.com/karma-runner/karma-chrome-launcher
50+
To get the installed binary path, use `chrome-path` output of the action:
5551

56-
```sh
57-
CHROMIUM_BIN=$(which chrome) npm run test
52+
```yaml
53+
steps:
54+
- uses: browser-actions/setup-chrome@v1
55+
id: setup-chrome
56+
- run: |
57+
${{ steps.setup-chrome.outputs.chrome-path }} --version
5858
```
5959

6060
## Parameters
6161

62-
- `chrome-version`: *(Optional)* The Google Chrome/Chromium version to be installed. Available value is one of the following:
63-
- Chromium by a commit position like `848897`. You can find commit positions from [here][snapshots].
64-
- Chromium latest snapshot `latest`
65-
- Google Chrome release channels: `stable`, `beta`, `dev` and `canary`
62+
### Inputs
6663

64+
- `chrome-version`: *(Optional)* The Google Chrome/Chromium version to be installed.
6765
Default: `latest`
6866

67+
### Outputs
68+
69+
- `chrome-path`: The installed Google Chrome/Chromium binary path.
70+
- `chrome-version`: The installed Google Chrome/Chromium version.
71+
6972
[snapshots]: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html
7073

7174
## License

__test__/data/known-good-versions-with-downloads.json

+1
Large diffs are not rendered by default.

__test__/version.test.ts

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { StaticVersion, VersionSpec } from "../src/version";
2+
3+
describe("StaticVersion", () => {
4+
describe("constructor", () => {
5+
test("new instance", () => {
6+
const version = new StaticVersion({
7+
major: 119,
8+
minor: 0,
9+
build: 6045,
10+
patch: 123,
11+
});
12+
13+
expect(version.major).toBe(119);
14+
expect(version.minor).toBe(0);
15+
expect(version.build).toBe(6045);
16+
expect(version.patch).toBe(123);
17+
});
18+
19+
test("parse", () => {
20+
const version = new StaticVersion("119.0.6045.123");
21+
22+
expect([
23+
version.major,
24+
version.minor,
25+
version.build,
26+
version.patch,
27+
]).toEqual([119, 0, 6045, 123]);
28+
});
29+
30+
test.each([
31+
["119.0.6045.123.456"],
32+
["119.0.6045.-123"],
33+
["119.0.6045.beta"],
34+
["119.0.6045"],
35+
])("throw an error for %s", (version) => {
36+
expect(() => new StaticVersion(version)).toThrow(
37+
`Invalid version: ${version}`,
38+
);
39+
});
40+
});
41+
42+
describe("compare", () => {
43+
test.each`
44+
a | b | equals | greaterThan | lessThan | greaterThanOrEqual | lessThanOrEqual
45+
${"119.0.6045.123"} | ${"119.0.6045.123"} | ${true} | ${false} | ${false} | ${true} | ${true}
46+
${"119.0.6045.123"} | ${"119.0.6045.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
47+
${"119.0.6045.123"} | ${"119.0.6045.200"} | ${false} | ${false} | ${true} | ${false} | ${true}
48+
${"119.0.6045.123"} | ${"119.0.7000.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
49+
${"119.0.6045.123"} | ${"119.0.5000.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
50+
${"119.0.6045.123"} | ${"119.1.6045.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
51+
${"119.0.6045.123"} | ${"120.0.6045.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
52+
${"119.0.6045.123"} | ${"118.0.6045.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
53+
${"119.0.6045.123"} | ${"119.0.6045.122"} | ${false} | ${true} | ${false} | ${false} | ${true}
54+
`('compare "$a" and "$b"', ({ a, b, equals, greaterThan, lessThan }) => {
55+
const v1 = new StaticVersion(a);
56+
const v2 = new StaticVersion(b);
57+
expect(v1.equals(v2)).toBe(equals);
58+
expect(v1.greaterThan(v2)).toBe(greaterThan);
59+
expect(v1.lessThan(v2)).toBe(lessThan);
60+
expect(v1.greaterThanOrEqual(v2)).toBe(greaterThan || equals);
61+
expect(v1.lessThanOrEqual(v2)).toBe(lessThan || equals);
62+
});
63+
});
64+
65+
describe("toString", () => {
66+
test("return stringified version", () => {
67+
const v = new StaticVersion("119.0.6045.123");
68+
expect(v.toString()).toBe("119.0.6045.123");
69+
});
70+
});
71+
});
72+
73+
describe("VersionSpec", () => {
74+
describe("constructor", () => {
75+
test("new instance", () => {
76+
const version = new VersionSpec({
77+
major: 119,
78+
minor: 0,
79+
build: 6045,
80+
patch: 123,
81+
});
82+
83+
expect(version.major).toBe(119);
84+
expect(version.minor).toBe(0);
85+
expect(version.build).toBe(6045);
86+
expect(version.patch).toBe(123);
87+
});
88+
89+
test.each([
90+
["119.0.6045.123", [119, 0, 6045, 123]],
91+
["119.0.6045", [119, 0, 6045]],
92+
["119.0", [119, 0]],
93+
["119", [119]],
94+
["119.0.6045.x", [119, 0, 6045]],
95+
["119.0.x", [119, 0]],
96+
["119.x", [119]],
97+
])("parse %s", (version, expected) => {
98+
const v = new VersionSpec(version);
99+
expect([v.major, v.minor, v.build, v.patch]).toEqual(expected);
100+
});
101+
102+
test.each([
103+
["119.0.6045.beta"],
104+
["119.0.x.123"],
105+
["x"],
106+
["119.0.6045.123.456"],
107+
["119.0.6045.-123"],
108+
[""],
109+
])("throw an error for %s", (version) => {
110+
expect(() => new VersionSpec(version)).toThrow(
111+
`Invalid version: ${version}`,
112+
);
113+
});
114+
});
115+
116+
describe("toString", () => {
117+
test.each([
118+
["119.0.6045.123", "119.0.6045.123"],
119+
["119", "119"],
120+
])("return %s for %s", (expected, version) => {
121+
const v = new VersionSpec(version);
122+
expect(v.toString()).toBe(expected);
123+
});
124+
});
125+
126+
describe("satisfies", () => {
127+
test.each`
128+
spec | version | satisfies
129+
${"119.0.6045.123"} | ${"119.0.6045.123"} | ${true}
130+
${"119.0.6045"} | ${"119.0.6045.123"} | ${true}
131+
${"119"} | ${"119.0.6045.123"} | ${true}
132+
${"119.0.6045.123"} | ${"119.0.6045.100"} | ${false}
133+
${"119.0.6000"} | ${"119.0.6045.100"} | ${false}
134+
${"120"} | ${"119.0.6045.100"} | ${false}
135+
`("return if $spec satisfies $version", ({ spec, version, satisfies }) => {
136+
const s = new VersionSpec(spec);
137+
const v = new StaticVersion(version);
138+
expect(s.satisfies(v)).toBe(satisfies);
139+
});
140+
});
141+
});

0 commit comments

Comments
 (0)