Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ jobs:
- name: Playwright version
id: playwright
run: |
export PLAYWRIGHT_GO_VERSION=$(go list -m all | grep github.com/playwright-community/playwright-go | awk '{print $2}')
set -euo pipefail
PLAYWRIGHT_GO_VERSION=$(go list -m -f '{{.Version}}' github.com/mxschmitt/playwright-go)
PLAYWRIGHT_VERSION=$(go run ./internal/cmd/playwrightversion)
if [ -z "$PLAYWRIGHT_GO_VERSION" ] || [ -z "$PLAYWRIGHT_VERSION" ]; then
echo "could not determine playwright versions (go: '$PLAYWRIGHT_GO_VERSION', playwright: '$PLAYWRIGHT_VERSION')" >&2
exit 1
fi
echo "playwright_go_version=$PLAYWRIGHT_GO_VERSION" >> "$GITHUB_OUTPUT"
echo "version="$(go run github.com/playwright-community/playwright-go/cmd/playwright@$PLAYWRIGHT_GO_VERSION --version |cut -d " " -f 2) >> "$GITHUB_OUTPUT"
echo "version=$PLAYWRIGHT_VERSION" >> "$GITHUB_OUTPUT"

- name: Install Docker
if: ${{ matrix.runner == 'macos-13' }}
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ jobs:
- name: Playwright version
id: playwright
run: |
export PLAYWRIGHT_GO_VERSION=$(go list -m all | grep github.com/playwright-community/playwright-go | awk '{print $2}')
set -euo pipefail
PLAYWRIGHT_GO_VERSION=$(go list -m -f '{{.Version}}' github.com/mxschmitt/playwright-go)
Comment on lines 45 to +49
PLAYWRIGHT_VERSION=$(go run ./internal/cmd/playwrightversion)
if [ -z "$PLAYWRIGHT_GO_VERSION" ] || [ -z "$PLAYWRIGHT_VERSION" ]; then
echo "could not determine playwright versions (go: '$PLAYWRIGHT_GO_VERSION', playwright: '$PLAYWRIGHT_VERSION')" >&2
exit 1
fi
echo "playwright_go_version=$PLAYWRIGHT_GO_VERSION" >> "$GITHUB_OUTPUT"
echo "version="$(go run github.com/playwright-community/playwright-go/cmd/playwright@$PLAYWRIGHT_GO_VERSION --version |cut -d " " -f 2) >> "$GITHUB_OUTPUT"
echo "version=$PLAYWRIGHT_VERSION" >> "$GITHUB_OUTPUT"

- name: Get Next Version
id: semver
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ jobs:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Download failed test artifacts
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go')
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go')
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
name: "Failed tests on amd64"
path: testdata/failed/

- name: Handle Dependabot Playwright Go test failures
id: handle-dependabot-failures
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go')
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:

# Thanks https://github.com/stefanzweifel/git-auto-commit-action/discussions/334
- name: "Import GPG key"
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go')
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go')
id: import-gpg
uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd
with:
Expand All @@ -136,7 +136,7 @@ jobs:

- name: "Commit and push changes"
id: commit-screenshots
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go')
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go')
env:
TOKEN: ${{ secrets.DEPENDABOT_PAT }}
run: |
Expand All @@ -155,7 +155,7 @@ jobs:
fi

- name: Find existing screenshot comment
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
id: find-comment
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad
with:
Expand All @@ -165,7 +165,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create comment body
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
env:
COMMIT_SHA: ${{ steps.commit-screenshots.outputs.commit_hash }}
run: |
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
echo "Commit: https://github.com/mountain-reverie/playwright-ci-go/commit/$COMMIT_SHA" >> comment.md

- name: Create or update comment on PR with updated screenshots
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
Expand All @@ -203,7 +203,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Add breaking label to PR
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/playwright-community/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'github.com/mxschmitt/playwright-go') && steps.commit-screenshots.outputs.changes_detected == 'true' && steps.commit-screenshots.outputs.commit_hash != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The library uses Docker containers with:

### Dependencies

- `github.com/playwright-community/playwright-go` - Core Playwright Go bindings
- `github.com/mxschmitt/playwright-go` - Core Playwright Go bindings
- `github.com/testcontainers/testcontainers-go` - Container management
- `github.com/docker/go-connections` - Docker networking utilities
- `github.com/elazarl/goproxy` - HTTP proxy implementation
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://github.com/mountain-reverie/playwright-ci-go/actions/workflows/main.yml/badge.svg)](https://github.com/mountain-reverie/playwright-ci-go/actions)

Reproducible browser testing with [Playwright for Go](https://github.com/playwright-community/playwright-go) using containerization for consistent CI environments.
Reproducible browser testing with [Playwright for Go](https://github.com/mxschmitt/playwright-go) using containerization for consistent CI environments.

This package enables you to run Playwright browser tests in Go with predictable behavior across different CI/CD platforms by leveraging containers.

Expand Down
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

playwrightcigo "github.com/mountain-reverie/playwright-ci-go"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)

func BenchmarkPageChromium(b *testing.B) {
Expand Down
2 changes: 1 addition & 1 deletion browsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"sync"

"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)

var mutexBrowser sync.Mutex
Expand Down
136 changes: 64 additions & 72 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type module struct {
Main bool
}

func new(version string, opts ...Option) (*container, error) {
func new(opts ...Option) (*container, error) {
c := &config{
timeout: 5 * time.Minute,
sleeping: 200 * time.Millisecond,
Expand All @@ -56,7 +56,7 @@ func new(version string, opts ...Option) (*container, error) {
}

if c.tag == "" {
tag, err := noTagVersion(version, c.verbose)
tag, err := noTagVersion(c.verbose)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -165,25 +165,23 @@ func port(ctx context.Context, container testcontainers.Container, host string,
return int(p.Num()), nil
}

func noTagVersion(version string, verbose bool) (string, error) {
splitted := strings.Split(version, ".")
if len(splitted) != 3 {
return "", fmt.Errorf("invalid version format: %s", version)
// noTagVersion resolves which playwright-ci-go image to pull when the caller
// did not pin one with WithRepository.
//
// Both strategies read versions the Go toolchain already knows, so neither
// guesses. Build info covers consumers of this library; go list covers
// development inside this repository, where the test binary carries no
// dependency info.
func noTagVersion(verbose bool) (string, error) {
if imageVersion, found := getPlaywrightCIGoFromBuildInfo(verbose); found {
return imageVersion, nil
}

imageVersion := fmt.Sprintf("v0.%s%02s.0", splitted[1], splitted[2])
if imageVersion == "v0.5101.0" {
// Workaround our CI having failed publishing this version
imageVersion = "v0.5101.1"
if imageVersion, found := getPlaywrightCIGoFromGoList(verbose); found {
return imageVersion, nil
}

found := false

found, imageVersion = getPlaywrightCIGoFromBuildInfo(imageVersion, verbose)
if !found {
_, imageVersion = getPlaywrightCIGoFromGoList(imageVersion, verbose)
}
return imageVersion, nil
return "", fmt.Errorf("could not determine which %s image to use: no version found in build info or go list; pass one explicitly with WithRepository", playwrightCIGoModule)
}

func filterVersion(version string) string {
Expand All @@ -195,63 +193,58 @@ func filterVersion(version string) string {
return version
}

func getPlaywrightCIGoGitVersion(imageVersion string, verbose bool) (bool, string) {
func getPlaywrightCIGoGitVersion(verbose bool) (string, bool) {
cmd := exec.Command("git", "describe", "--tags")
output, err := cmd.Output()
if err != nil {
if verbose {
log.Printf("could not get git version: %v\n", err)
}
return false, imageVersion
return "", false
}
imageVersion = filterVersion(strings.TrimSpace(string(output)))
imageVersion := filterVersion(strings.TrimSpace(string(output)))
if verbose {
log.Println("Using version from git:", imageVersion)
}
return true, imageVersion
return imageVersion, true
}

func getPlaywrightCIGoFromBuildInfo(imageVersion string, verbose bool) (bool, string) {
if info, ok := debug.ReadBuildInfo(); !ok {
for _, deps := range info.Deps {
if strings.Contains(deps.Path, "github.com/mountain-reverie/playwright-ci-go") {
if len(deps.Version) > 0 && deps.Version[0] == 'v' {
if verbose {
log.Println("Using version from build info:", deps.Version)
}
return true, deps.Version
}
}
func getPlaywrightCIGoFromBuildInfo(verbose bool) (string, bool) {
info, ok := debug.ReadBuildInfo()
if !ok {
if verbose {
log.Println("no build info available")
}
return "", false
}

return false, imageVersion
return versionFromBuildInfo(info, verbose)
}

func getPlaywrightCIGoFromGoList(imageVersion string, verbose bool) (bool, string) {
func getPlaywrightCIGoFromGoList(verbose bool) (string, bool) {
cmd := exec.Command("go", "list", "-json", "-m", "all")
output, err := cmd.StdoutPipe()
if err != nil {
if verbose {
log.Printf("could not get stdout pipe: %v\n", err)
}
return false, imageVersion
return "", false
}

if err := cmd.Start(); err != nil {
if verbose {
log.Printf("could not start command: %v\n", err)
}
return false, imageVersion
return "", false
}
defer func() {
_ = cmd.Wait()
}()

return parseGoListJSONStream(output, imageVersion, verbose)
return parseGoListJSONStream(output, verbose)
}

func parseGoListJSONStream(output io.Reader, imageVersion string, verbose bool) (bool, string) {
func parseGoListJSONStream(output io.Reader, verbose bool) (string, bool) {
decoder := json.NewDecoder(output)

defer func() {
Expand All @@ -272,7 +265,7 @@ func parseGoListJSONStream(output io.Reader, imageVersion string, verbose bool)
if verbose {
log.Printf("could not decode module: %v\n", err)
}
return false, imageVersion
return "", false
}

if !strings.Contains(mod.Path, "playwright") {
Expand All @@ -290,61 +283,60 @@ func parseGoListJSONStream(output io.Reader, imageVersion string, verbose bool)
modules[mod.Path] = mod
}

version := ""
if mod, exists := modules["github.com/playwright-community/playwright-go"]; exists {
// The release line implied by playwright-go, used whenever we cannot read
// a published playwright-ci-go version directly.
line := ""
mod, exists := modules[playwrightGoModule]
if !exists {
// playwright-go moved back to the mxschmitt org in v0.6100.0; a
// consumer still pinning the archived playwright-community path
// should keep resolving.
mod, exists = modules[playwrightGoArchivedModule]
}
if exists {
if verbose {
log.Println("Found playwright-go module:", mod.Path, "Version:", mod.Version)
}
if len(mod.Version) > 0 && mod.Version[0] == 'v' {
if verbose {
log.Println("Found playwright-go version:", mod.Version)
}
version = mod.Version
if tag, ok := playwrightGoTagLine(mod.Version); ok {
line = tag
}
}

if mod, exists := modules["github.com/mountain-reverie/playwright-ci-go"]; exists {
if mod, exists := modules[playwrightCIGoModule]; exists {
if verbose {
log.Println("Found playwright-ci-go module:", mod.Path, "Version:", mod.Version)
}

// Developing in this repository: there is no published version of
// ourselves to use, so fall back to the line, then to the git tag.
if mod.Main {
if version != "" {
if verbose {
log.Println("Using version from playwright-go module:", version)
}
return true, version
if line != "" {
return line, true
}
return getPlaywrightCIGoGitVersion(imageVersion, verbose)
} else if len(mod.Version) > 0 && mod.Version[0] == 'v' {
return getPlaywrightCIGoGitVersion(verbose)
}

if len(mod.Version) > 0 && mod.Version[0] == 'v' {
if verbose {
log.Println("Using version from go list:", mod.Version)
}
return true, mod.Version
} else {
if verbose {
log.Println("No version found in go list for playwright-ci-go module")
}
if version != "" {
if verbose {
log.Println("Using version from playwright-go module:", version)
}
return false, version
} else {
return false, imageVersion
}
return mod.Version, true
}

if verbose {
log.Println("No version found in go list for playwright-ci-go module")
}
}

if version != "" {
if line != "" {
if verbose {
log.Println("Using version from playwright-go module:", version)
log.Println("Using release line from playwright-go module:", line)
}
return false, version
return line, true
}

if verbose {
log.Println("No build, module or git info found. Keeping version as:", imageVersion)
log.Println("No build, module or git info found")
}
return false, imageVersion
return "", false
}
Loading
Loading