blob: 743b1f91f49fa4a07dc9e00be324763e0ead0cb6 [file] [edit]
name: Shared - Bazel
on:
workflow_call:
inputs:
name:
description: Name of workflow
required: false
type: string
ref:
description: Git ref to checkout (branch, tag, or SHA)
required: false
type: string
default: ''
run:
description: Bazel command to run
required: true
type: string
os:
description: One of ubuntu, windows or macos
required: false
type: string
default: ubuntu
needs-display:
description: Whether this job drives a browser and needs display/driver setup
required: false
type: boolean
default: false
safari-preview:
description: Whether this job needs Safari Technology Preview installed (macos only)
required: false
type: boolean
default: false
node-version:
description: Custom Node version to use
required: false
type: string
default: ''
python-version:
description: Custom Python version to use
required: false
type: string
default: ''
ruby-version:
description: Custom Ruby version to use
required: false
type: string
default: ''
download-artifact-name:
description: Name of an artifact to download into the workspace before running
required: false
type: string
default: ''
artifact-name:
description: Name of artifact to upload
required: false
type: string
default: ''
artifact-path:
description: Path/glob of files to upload (if empty, uploads git diff as changes.patch)
required: false
type: string
default: ''
rerun-with-debug:
description: Rerun failing tests with debugging enabled
required: false
type: boolean
default: false
cache-name:
description: Name for cache restore (restores {name}.gz with key {name}-)
required: false
type: string
default: ''
cache-save:
description: Save the Bazel cache after the run (avoids multiple jobs clobbering it)
required: false
type: boolean
default: false
remote-cache:
description: Read the EngFlow remote cache (the nightly also writes it)
required: false
type: boolean
default: false
use-cache:
description: Restore the Bazel repository cache
required: false
type: boolean
default: true
gem-trusted-publishing:
description: Exchange GitHub OIDC token for a RubyGems API token (requires trusted publisher configured on rubygems.org)
required: false
type: boolean
default: false
outputs:
output:
description: Value the run script writes to $GITHUB_OUTPUT as "output=..."; empty when unused
value: ${{ jobs.bazel.outputs.output }}
jobs:
bazel:
name: ${{ inputs.name }}
runs-on: ${{ contains(inputs.os, '-') && inputs.os || format('{0}-latest', inputs.os) }}
outputs:
output: ${{ steps.run-bazel.outputs.output }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEL_M2_USER: ${{ secrets.SEL_M2_USER }}
SEL_M2_PASS: ${{ secrets.SEL_M2_PASS }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_NIGHTLY_PASSWORD: ${{ secrets.TWINE_NIGHTLY_PASSWORD }}
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
MSYS_NO_PATHCONV: 1
MSYS2_ARG_CONV_EXCL: "*"
steps:
- name: Configure Selenium Manager cache path
shell: bash
run: echo "SE_CACHE_PATH=$RUNNER_TEMP/selenium-cache" >> "$GITHUB_ENV"
- name: Calculate fetch depth
id: depth
shell: bash
env:
PR_COMMITS: ${{ github.event.pull_request.commits }}
run: |
# For PRs, use commit count plus buffer for merge base
if [ -n "$PR_COMMITS" ]; then
echo "val=$((PR_COMMITS + 2))" >> "$GITHUB_OUTPUT"
else
COMMIT_COUNT=$(jq -e '.commits | length // 0' "$GITHUB_EVENT_PATH" 2>/dev/null) || COMMIT_COUNT=0
echo "val=$((COMMIT_COUNT + 1))" >> "$GITHUB_OUTPUT"
fi
- name: Checkout source tree
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref || github.ref }}
fetch-depth: ${{ steps.depth.outputs.val }}
- name: Delete browsers and drivers
if: startsWith(inputs.os, 'ubuntu') || inputs.os == 'macos'
run: ./scripts/github-actions/delete-browsers-drivers.sh
- name: Delete drivers (Windows)
if: inputs.os == 'windows'
shell: pwsh
run: ./scripts/github-actions/delete-browsers-drivers.ps1
- name: Free disk space
if: contains(inputs.os, 'ubuntu')
shell: bash
run: |
. ./scripts/github-actions/disk-status.sh
if [ "$AVAIL_GB" -lt 25 ]; then
./scripts/github-actions/free-disk-space.sh
fi
- name: Disk status before cache restore
if: inputs.os != 'macos'
shell: bash
run: . ./scripts/github-actions/disk-status.sh
- name: Restore cache
if: inputs.cache-name != ''
uses: actions/cache/restore@v5
with:
path: ${{ inputs.cache-name }}
key: ${{ inputs.cache-name }}-
restore-keys: ${{ inputs.cache-name }}-
- name: Download artifact
if: inputs.download-artifact-name != ''
uses: actions/download-artifact@v8
with:
name: ${{ inputs.download-artifact-name }}
continue-on-error: true
- name: Set Python version
if: inputs.python-version != ''
run: echo '${{ inputs.python-version }}' > py/.python-version
- name: Set Ruby version
if: inputs.ruby-version != ''
run: echo '${{ inputs.ruby-version }}' > rb/.ruby-version
- name: Set Node version
if: inputs.node-version != ''
run: echo '${{ inputs.node-version }}' > .nvmrc
- name: Setup Bazel with caching
continue-on-error: true
timeout-minutes: 10
uses: bazel-contrib/setup-bazel@0.19.0
with:
cache-save: ${{ inputs.cache-save }}
bazelisk-cache: true
bazelrc: |
common --color=yes
${{ inputs.remote-cache && github.repository_owner == 'SeleniumHQ' && (github.event_name == 'schedule' && 'build --config=remote-cache-write --noremote_accept_cached' || 'build --config=remote-cache') || '' }}
# Workaround for long path issues: https://github.com/bazelbuild/bazel/pull/22532
output-base: ${{ inputs.os == 'windows' && 'D://b' || '' }}
disk-cache: false
external-cache: false
# Keep the key files in sync with the paths filter in gh-cache.yml
repository-cache: ${{ inputs.use-cache && '[MODULE.bazel, multitool.lock.json, pnpm-lock.yaml, rust/Cargo.lock, java/maven_install.json, py/requirements_lock.txt, rb/Gemfile.lock, dotnet/paket.lock, common/selenium_manager.bzl]' || 'false' }}
- name: Disk status after cache restore
if: inputs.os != 'macos'
shell: bash
run: . ./scripts/github-actions/disk-status.sh
- name: Clear old repository cache
if: inputs.cache-save
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then rm -rf /d/b-repo; else rm -rf "$HOME/.cache/bazel-repo"; fi
- name: Setup Fluxbox and Xvfb
if: inputs.needs-display && contains(inputs.os, 'ubuntu')
run: |
sudo apt-get update && sudo apt-get -y install fluxbox x11-utils
Xvfb :99 &
# X server must start before fluxbox
for _ in $(seq 1 30); do
xdpyinfo -display :99 >/dev/null 2>&1 && break
sleep 0.5
done
xdpyinfo -display :99 >/dev/null 2>&1 || { echo "::error::X server :99 failed to start"; exit 1; }
fluxbox -display :99 &
echo "DISPLAY=:99" >> "$GITHUB_ENV"
- name: Set resolution
if: inputs.needs-display && inputs.os == 'windows'
run: Set-DisplayResolution -Width 1920 -Height 1080 -Force
- name: Disable 8dot3 short names
if: inputs.os == 'windows'
run: fsutil 8dot3name set 0
- name: Setup Safari
if: inputs.needs-display && inputs.os == 'macos'
run: sudo safaridriver --enable
- name: Setup Safari Technology Preview
if: inputs.safari-preview && inputs.os == 'macos'
run: |
brew update --quiet
brew install --cask safari-technology-preview
sudo "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver" --enable
- name: Configure RubyGems credentials via OIDC
if: inputs.gem-trusted-publishing
uses: rubygems/configure-rubygems-credentials@v2.1.0
- name: Run Bazel
id: run-bazel
continue-on-error: true
shell: bash
run: |
mkdir -p build
{
${{ inputs.run }}
} 2>&1 | tee build/bazel-console.log
- name: Retry transient download failure
id: retry-transient
if: steps.run-bazel.outcome == 'failure'
continue-on-error: true
shell: bash
run: ./scripts/github-actions/retry-transient-download.sh '${{ inputs.run }}'
- name: Rerun failures with debug
id: rerun-failures
if: steps.run-bazel.outcome == 'failure' && (steps.retry-transient.outputs.retried != 'true' || steps.retry-transient.outcome == 'failure')
shell: bash
run: ./scripts/github-actions/rerun-failures.sh '${{ inputs.run }}' '${{ inputs.rerun-with-debug }}'
# The following two steps can be removed after collecting data evaluating effectiveness of remote caching
- name: Summarize remote cache use
id: remote-cache-summary
if: always() && inputs.remote-cache && github.repository_owner == 'SeleniumHQ'
continue-on-error: true
shell: bash
env:
JOB_NAME: ${{ inputs.name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: ./scripts/github-actions/remote-cache-summary.sh
- name: Upload remote cache record
if: always() && steps.remote-cache-summary.outputs.record == 'true'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: remote-cache-${{ inputs.os }}-${{ job.check_run_id }}-${{ github.run_attempt }}
retention-days: 60
path: build/remote-cache/record.jsonl
- name: Collect failed logs
if: always() && steps.run-bazel.outcome == 'failure'
shell: bash
run: ./scripts/github-actions/collect-failed-logs.sh
- name: Upload failed logs
if: always() && steps.run-bazel.outcome == 'failure'
uses: actions/upload-artifact@v7
with:
name: test-logs-${{ inputs.os }}-${{ inputs.name }}-${{ job.check_run_id }}-${{ github.run_attempt }}
retention-days: 7
path: build/failures/**
- name: Parse flaky results
id: parse-flaky
if: ${{ !cancelled() && inputs.rerun-with-debug && github.event_name == 'schedule' && github.ref == 'refs/heads/trunk' }}
continue-on-error: true
shell: bash
env:
JOB_ID: ${{ job.check_run_id }}
run: ./scripts/github-actions/parse-flaky-results.sh
- name: Upload flaky results
if: always() && steps.parse-flaky.outputs.results == 'true'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: flaky-${{ inputs.os }}-${{ inputs.name }}-${{ job.check_run_id }}-${{ github.run_attempt }}
retention-days: 60
path: build/failures/results.jsonl
- name: Start SSH session
if: failure() && runner.debug == '1'
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: false
- name: Save git diff
if: always() && inputs.artifact-name != '' && inputs.artifact-path == ''
shell: bash
run: |
git add -A && git diff --binary --staged > changes.patch
[ -s changes.patch ] || rm -f changes.patch
- name: Upload artifact
if: always() && inputs.artifact-name != ''
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.artifact-path || 'changes.patch' }}
retention-days: 6
overwrite: true
if-no-files-found: ${{ inputs.artifact-path != '' && 'error' || 'ignore' }}
- name: Low Disk Warning
if: always()
shell: bash
run: |
. ./scripts/github-actions/disk-status.sh
if [ "$AVAIL_GB" -lt 5 ]; then
echo "::warning::Low disk space: ${AVAIL_GB}GB remaining"
fi