From d8844069c13ea4f626f7af16623c1c4c8c18756c Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 12 Dec 2024 15:18:48 +0200 Subject: [PATCH] Add running browser examples in CI as it did in xk6-browser --- .github/workflows/browser_e2e.yml | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/browser_e2e.yml diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml new file mode 100644 index 00000000000..02fed479a0f --- /dev/null +++ b/.github/workflows/browser_e2e.yml @@ -0,0 +1,70 @@ +name: E2E +on: + # Enable manually triggering this workflow via the API or web UI + workflow_dispatch: + push: + branches: + - main + pull_request: + schedule: + # At 06:00 AM UTC from Monday through Friday + - cron: '0 6 * * 1-5' + +defaults: + run: + shell: bash + +jobs: + test: + strategy: + matrix: + go: [stable, tip] + platform: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout code + if: matrix.go != 'tip' || matrix.platform != 'windows-latest' + uses: actions/checkout@v4 + - name: Install Go + if: matrix.go != 'tip' || matrix.platform != 'windows-latest' + uses: actions/setup-go@v5 + with: + go-version: 1.x + - name: Install Go tip + if: matrix.go == 'tip' && matrix.platform != 'windows-latest' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release download ${{ matrix.platform }} --repo grafana/gotip --pattern 'go.zip' + unzip go.zip -d $HOME/sdk + echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" + echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" + echo "$HOME/go/bin" >> "$GITHUB_PATH" + echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" + - name: Build k6 + if: matrix.go != 'tip' || matrix.platform != 'windows-latest' + run: | + which go + go version + + go build . + ./k6 version + - name: Run E2E tests + if: matrix.go != 'tip' || matrix.platform != 'windows-latest' + run: | + set -x + if [ "$RUNNER_OS" == "Linux" ]; then + export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome + fi + export K6_BROWSER_HEADLESS=true + for f in examples/browser/*.js; do + if [ "$f" == "examples/browser/hosts.js" ] && [ "$RUNNER_OS" == "Windows" ]; then + echo "skipping $f on Windows" + continue + fi + ./k6 run -q "$f" + done + - name: Check screenshot + if: matrix.go != 'tip' || matrix.platform != 'windows-latest' + # TODO: Do something more sophisticated? + run: test -s screenshot.png