Skip to content

Commit

Permalink
feat: Support to install by a specific version (browser-actions#444)
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
ueokande authored Dec 3, 2023
1 parent f318cc2 commit 775b8fb
Show file tree
Hide file tree
Showing 14 changed files with 2,741 additions and 178 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ updates:
- "eslint"
- "eslint-*"
- "prettier"
jest:
patterns:
- "jest"
- "jest-*"
- "ts-jest"
- "@types/jest"
40 changes: 10 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm test
- run: pnpm build
- run: pnpm package
- uses: actions/upload-artifact@v3
Expand All @@ -30,42 +31,21 @@ jobs:
strategy:
matrix:
os: [ubuntu, macos, windows]
version: ["", 827102, 120, dev]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/download-artifact@v3
with:
name: dist

- name: Install with no params
uses: ./
- if: runner.os == 'Linux'
run: chrome --version
- if: runner.os == 'macOS'
run: chromium --version
- if: runner.os == 'Windows'
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
# Unable to run with command-line option on windows

- name: Install with version '827102'
uses: ./
with:
chrome-version: 827102
- if: runner.os == 'Linux'
run: chrome --version
- if: runner.os == 'macOS'
run: chromium --version
- if: runner.os == 'Windows'
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
# Unable to run with command-line option on windows

- name: install with version 'dev'
- name: Install Google Chrome
uses: ./
with:
chrome-version: dev
- if: runner.os == 'Linux'
run: chrome --version
- if: runner.os == 'macOS'
run: chrome --version
chrome-version: ${{ matrix.version }}
id: setup-chrome
- if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
"${{ steps.setup-chrome.outputs.chrome-path }}" --version
- if: runner.os == 'Windows'
run: (Get-Item (Get-Command chrome).Source).VersionInfo.ProductVersion
# Unable to run with command-line option on windows
run: |
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
7 changes: 5 additions & 2 deletions .github/workflows/manual-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm test
- run: pnpm build
- run: pnpm package
- uses: actions/upload-artifact@v3
Expand All @@ -47,6 +48,8 @@ jobs:
chrome-version: ${{ inputs.chrome-version }}
id: setup-chrome
- if: runner.os == 'Linux' || runner.os == 'macOS'
run: ${{ steps.setup-chrome.outputs.chrome-path }} --version
run: |
"${{ steps.setup-chrome.outputs.chrome-path }}" --version
- if: runner.os == 'Windows'
run: (Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
run: |
(Get-Item (Get-Command "${{ steps.setup-chrome.outputs.chrome-path }}").Source).VersionInfo.ProductVersion
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,66 @@ This action sets by Google Chrome/Chromium for use in actions by:
- [X] Install and setup latest Chromium
- [X] Cross platform runner (macOS, Linux, Windows)
- [X] Install Google Chrome by channel (stable, beta, dev, and canary)
- [ ] Install by version number (88.0.4324, or 88.0)
- [X] Install by version number (88.0.4324, or 88.0)

## Usage

See [action.yml](action.yml)

Basic usage:
Here is a basic usage.
The action installs the latest build by default.

```yaml
steps:
- uses: browser-actions/setup-chrome@v1
- run: chrome --version
```
Install Google Chrome Beta
To install a specific channel, use `chrome-version` input.

```yaml
steps:
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: beta
id: setup-chrome
- run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
${{ steps.setup-chrome.outputs.chrome-path }} --version
chrome-version: 120
```

**Note that the installed binary depends on your installation spec.**
### Supported version formats

The installed binary name depends on the version you specify and your platform.
The summarized binary names are the following:
The action supports the following version formats:

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

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

### Installed path

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

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

```sh
CHROMIUM_BIN=$(which chrome) npm run test
```yaml
steps:
- uses: browser-actions/setup-chrome@v1
id: setup-chrome
- run: |
${{ steps.setup-chrome.outputs.chrome-path }} --version
```

## Parameters

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

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

### Outputs

- `chrome-path`: The installed Google Chrome/Chromium binary path.
- `chrome-version`: The installed Google Chrome/Chromium version.

[snapshots]: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html

## License
Expand Down
1 change: 1 addition & 0 deletions __test__/data/known-good-versions-with-downloads.json

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions __test__/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { StaticVersion, VersionSpec } from "../src/version";

describe("StaticVersion", () => {
describe("constructor", () => {
test("new instance", () => {
const version = new StaticVersion({
major: 119,
minor: 0,
build: 6045,
patch: 123,
});

expect(version.major).toBe(119);
expect(version.minor).toBe(0);
expect(version.build).toBe(6045);
expect(version.patch).toBe(123);
});

test("parse", () => {
const version = new StaticVersion("119.0.6045.123");

expect([
version.major,
version.minor,
version.build,
version.patch,
]).toEqual([119, 0, 6045, 123]);
});

test.each([
["119.0.6045.123.456"],
["119.0.6045.-123"],
["119.0.6045.beta"],
["119.0.6045"],
])("throw an error for %s", (version) => {
expect(() => new StaticVersion(version)).toThrow(
`Invalid version: ${version}`,
);
});
});

describe("compare", () => {
test.each`
a | b | equals | greaterThan | lessThan | greaterThanOrEqual | lessThanOrEqual
${"119.0.6045.123"} | ${"119.0.6045.123"} | ${true} | ${false} | ${false} | ${true} | ${true}
${"119.0.6045.123"} | ${"119.0.6045.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
${"119.0.6045.123"} | ${"119.0.6045.200"} | ${false} | ${false} | ${true} | ${false} | ${true}
${"119.0.6045.123"} | ${"119.0.7000.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
${"119.0.6045.123"} | ${"119.0.5000.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
${"119.0.6045.123"} | ${"119.1.6045.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
${"119.0.6045.123"} | ${"120.0.6045.100"} | ${false} | ${false} | ${true} | ${false} | ${true}
${"119.0.6045.123"} | ${"118.0.6045.100"} | ${false} | ${true} | ${false} | ${false} | ${true}
${"119.0.6045.123"} | ${"119.0.6045.122"} | ${false} | ${true} | ${false} | ${false} | ${true}
`('compare "$a" and "$b"', ({ a, b, equals, greaterThan, lessThan }) => {
const v1 = new StaticVersion(a);
const v2 = new StaticVersion(b);
expect(v1.equals(v2)).toBe(equals);
expect(v1.greaterThan(v2)).toBe(greaterThan);
expect(v1.lessThan(v2)).toBe(lessThan);
expect(v1.greaterThanOrEqual(v2)).toBe(greaterThan || equals);
expect(v1.lessThanOrEqual(v2)).toBe(lessThan || equals);
});
});

describe("toString", () => {
test("return stringified version", () => {
const v = new StaticVersion("119.0.6045.123");
expect(v.toString()).toBe("119.0.6045.123");
});
});
});

describe("VersionSpec", () => {
describe("constructor", () => {
test("new instance", () => {
const version = new VersionSpec({
major: 119,
minor: 0,
build: 6045,
patch: 123,
});

expect(version.major).toBe(119);
expect(version.minor).toBe(0);
expect(version.build).toBe(6045);
expect(version.patch).toBe(123);
});

test.each([
["119.0.6045.123", [119, 0, 6045, 123]],
["119.0.6045", [119, 0, 6045]],
["119.0", [119, 0]],
["119", [119]],
["119.0.6045.x", [119, 0, 6045]],
["119.0.x", [119, 0]],
["119.x", [119]],
])("parse %s", (version, expected) => {
const v = new VersionSpec(version);
expect([v.major, v.minor, v.build, v.patch]).toEqual(expected);
});

test.each([
["119.0.6045.beta"],
["119.0.x.123"],
["x"],
["119.0.6045.123.456"],
["119.0.6045.-123"],
[""],
])("throw an error for %s", (version) => {
expect(() => new VersionSpec(version)).toThrow(
`Invalid version: ${version}`,
);
});
});

describe("toString", () => {
test.each([
["119.0.6045.123", "119.0.6045.123"],
["119", "119"],
])("return %s for %s", (expected, version) => {
const v = new VersionSpec(version);
expect(v.toString()).toBe(expected);
});
});

describe("satisfies", () => {
test.each`
spec | version | satisfies
${"119.0.6045.123"} | ${"119.0.6045.123"} | ${true}
${"119.0.6045"} | ${"119.0.6045.123"} | ${true}
${"119"} | ${"119.0.6045.123"} | ${true}
${"119.0.6045.123"} | ${"119.0.6045.100"} | ${false}
${"119.0.6000"} | ${"119.0.6045.100"} | ${false}
${"120"} | ${"119.0.6045.100"} | ${false}
`("return if $spec satisfies $version", ({ spec, version, satisfies }) => {
const s = new VersionSpec(spec);
const v = new StaticVersion(version);
expect(s.satisfies(v)).toBe(satisfies);
});
});
});
Loading

0 comments on commit 775b8fb

Please sign in to comment.