ci: build the flake and guard the version literal #136
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| # Skipped on windows: gofmt's output is platform-independent and the | |
| # same bytes are already checked on ubuntu/macos, so running it a third | |
| # time adds no coverage. (.gitattributes now forces an LF checkout | |
| # everywhere, so this is no longer about CRLF false positives.) | |
| - name: gofmt | |
| if: runner.os != 'Windows' | |
| run: | | |
| unformatted=$(gofmt -l .) | |
| if [ -n "$unformatted" ]; then | |
| echo "These files are not gofmt-clean:" | |
| echo "$unformatted" | |
| exit 1 | |
| fi | |
| - name: go vet | |
| run: go vet ./... | |
| # ubuntu-latest ships google-chrome-stable, so the live-Chrome integration | |
| # test runs there; on macOS (no Chrome) it skips itself gracefully. | |
| - name: Test | |
| if: runner.os != 'Windows' | |
| run: go test -race ./... | |
| # windows-latest has no cgo toolchain wired for -race, and no Chrome to | |
| # run the live suite against, so it gets the short suite only. | |
| - name: Test (short) | |
| if: runner.os == 'Windows' | |
| shell: bash | |
| run: go test -short ./... | |
| - name: Build | |
| run: go build ./... | |
| # The npm shim is the install path for `npx @sanketsudake/chrome-cdp`, and | |
| # its tests are the only guard on the postinstall script. They used to run | |
| # in the release job alone — immediately before `npm publish` — so a | |
| # regression stayed invisible through review and surfaced mid-release: | |
| # 0.3.0 shipped a postinstall that died on every install while the Go CI | |
| # above was green. Running them here makes an installer break a red PR. | |
| # | |
| # ubuntu-only on purpose: these are pure-function and subprocess tests that | |
| # take the platform as a parameter (assetName covers win32), so a matrix | |
| # would re-run identical assertions. | |
| npm: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| - name: Test the npm installer shim | |
| run: cd npm && node --test | |
| # The flake is how this CLI reaches nix users (sanketsudake/dotfiles installs | |
| # it that way), and its vendorHash goes stale whenever go.sum moves. Building | |
| # it here makes the PR that moves go.sum go red, instead of the break landing | |
| # on a machine downstream. | |
| nix: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: cachix/install-nix-action@v31 | |
| with: | |
| extra_nix_config: "experimental-features = nix-command flakes" | |
| - name: Build the flake package | |
| run: nix build .#chrome-cdp --print-build-logs | |
| - name: Smoke-test the built binary | |
| run: ./result/bin/chrome-cdp --version |