| name: CI | |
| on: | |
| pull_request: | |
| paths-ignore: | |
| - 'docs/decisions/**' | |
| push: | |
| branches: | |
| - trunk | |
| schedule: | |
| - cron: "0 4 * * *" | |
| workflow_dispatch: | |
| workflow_call: | |
| concurrency: | |
| group: ci-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| permissions: | |
| contents: read | |
| packages: read | |
| jobs: | |
| build-index: | |
| name: Build Index | |
| if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/trunk' | |
| uses: ./.github/workflows/ci-build-index.yml | |
| lint: | |
| name: Lint | |
| uses: ./.github/workflows/bazel.yml | |
| with: | |
| name: Check Workflows and Shell | |
| run: ./go lint_workflows && ./go lint_shell | |
| format: | |
| name: Format | |
| uses: ./.github/workflows/bazel.yml | |
| with: | |
| name: Check Format | |
| run: | | |
| ./go format | |
| if ! git diff --quiet; then | |
| echo "::error::Code needs formatting. Run './go format' locally and push changes." | |
| git diff | |
| exit 1 | |
| fi | |
| # Everything but the release PR holds its binding jobs while trunk is locked, so macOS runners stay free for the release. | |
| wait-for-unlock: | |
| name: Wait for Trunk Unlock | |
| if: ${{ !(startsWith(github.head_ref, 'release-preparation-') && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| while gh api "repos/$GITHUB_REPOSITORY/rulesets" --jq 'any(.[]; .name == "Release: Restrict Trunk")' | grep -q true; do | |
| echo "Trunk is locked for a release; waiting" | |
| sleep 60 | |
| done | |
| targets-mode: | |
| name: Targets Mode | |
| runs-on: ubuntu-latest | |
| outputs: | |
| mode: ${{ steps.mode.outputs.mode }} | |
| steps: | |
| - name: Decide whether to compute affected targets | |
| id: mode | |
| run: | | |
| if [ "${{ github.event.repository.fork }}" = "true" ]; then | |
| mode=none | |
| elif { [ "${{ github.event_name }}" != "pull_request" ] && [ "${{ github.event_name }}" != "push" ]; } || [ "${{ startsWith(github.head_ref, 'release-preparation-') && github.event.pull_request.head.repo.full_name == github.repository }}" = "true" ]; then | |
| mode=all | |
| else | |
| mode=check | |
| fi | |
| echo "mode=$mode" >> "$GITHUB_OUTPUT" | |
| check: | |
| name: Check Targets | |
| needs: targets-mode | |
| if: needs.targets-mode.outputs.mode == 'check' | |
| uses: ./.github/workflows/bazel.yml | |
| with: | |
| name: Check Targets | |
| cache-name: bazel-test-file-index | |
| run: | | |
| if [ -n "${{ github.event.pull_request.base.sha }}" ]; then | |
| BASE_SHA="HEAD^1" | |
| elif [ "${{ github.ref }}" = "refs/heads/trunk" ]; then | |
| BASE_SHA="${{ github.event.before }}" | |
| else | |
| ahead=$(gh api "repos/${{ github.repository }}/compare/trunk...${{ github.ref_name }}" --jq .ahead_by) | |
| git fetch --no-tags --depth=$((ahead + 1)) origin "${{ github.ref_name }}" | |
| BASE_SHA="HEAD~$ahead" | |
| fi | |
| if git cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then | |
| ./go bazel:affected_targets "${BASE_SHA}..HEAD" bazel-test-file-index | |
| else | |
| ./go bazel:affected_targets bazel-test-file-index | |
| fi | |
| artifact-name: check-targets | |
| artifact-path: | | |
| build/bazel-targets.txt | |
| build/selenium-manager-changed.txt | |
| read-targets: | |
| name: Read Targets | |
| needs: [targets-mode, check] | |
| if: "!cancelled() && (needs.targets-mode.outputs.mode == 'all' || needs.check.result == 'success')" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| java: ${{ steps.read.outputs.java }} | |
| py: ${{ steps.read.outputs.py }} | |
| rb: ${{ steps.read.outputs.rb }} | |
| dotnet: ${{ steps.read.outputs.dotnet }} | |
| rust: ${{ steps.read.outputs.rust }} | |
| js: ${{ steps.read.outputs.js }} | |
| compile-manager: ${{ steps.read.outputs.compile-manager }} | |
| steps: | |
| - name: Download targets | |
| if: needs.targets-mode.outputs.mode == 'check' | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: check-targets | |
| path: build | |
| - name: Use every target | |
| if: needs.targets-mode.outputs.mode == 'all' | |
| run: mkdir -p build && echo "//java/... //py/... //rb/... //dotnet/... //rust/... //javascript/..." > build/bazel-targets.txt | |
| - name: Read targets | |
| id: read | |
| env: | |
| COMMIT_MESSAGES: ${{ join(github.event.commits.*.message, ' ') }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| targets=$(cat build/bazel-targets.txt 2>/dev/null || echo "") | |
| if [ "$(cat build/selenium-manager-changed.txt 2>/dev/null)" = "true" ]; then | |
| echo "compile-manager=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| check_binding() { | |
| local pattern=$1 tag=$2 | |
| if [[ "$targets" == *"${pattern}/"* ]] || [[ "$targets" == *"${pattern}:"* ]] || [[ "$COMMIT_MESSAGES" == *"[$tag]"* ]] || [[ "$PR_TITLE" == *"[$tag]"* ]]; then | |
| echo "$tag=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| } | |
| process_binding() { | |
| local pattern=$1 tag=$2 | |
| local lang_targets | |
| lang_targets=$(echo "$targets" | tr ' ' '\n' | awk -v p="^${pattern}[:/]" '$0 ~ p') | |
| if [ -n "$lang_targets" ]; then | |
| echo "$tag=true" >> "$GITHUB_OUTPUT" | |
| echo "$lang_targets" > "bazel-targets-${tag}.txt" | |
| fi | |
| } | |
| process_binding "//java" "java" | |
| check_binding "//dotnet" "dotnet" | |
| check_binding "//rust" "rust" | |
| process_binding "//rb" "rb" | |
| process_binding "//py" "py" | |
| process_binding "//javascript" "js" | |
| - name: Upload target files | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: targets | |
| path: bazel-targets-*.txt | |
| if-no-files-found: ignore | |
| dotnet: | |
| name: .NET | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-dotnet.yml | |
| if: "!cancelled() && needs.read-targets.outputs.dotnet != ''" | |
| with: | |
| compile-manager: ${{ needs.read-targets.outputs.compile-manager == 'true' }} | |
| java: | |
| name: Java | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-java.yml | |
| if: "!cancelled() && needs.read-targets.outputs.java != ''" | |
| with: | |
| compile-manager: ${{ needs.read-targets.outputs.compile-manager == 'true' }} | |
| python: | |
| name: Python | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-python.yml | |
| if: "!cancelled() && needs.read-targets.outputs.py != ''" | |
| with: | |
| compile-manager: ${{ needs.read-targets.outputs.compile-manager == 'true' }} | |
| smoke: ${{ !(github.head_ref == 'pinned-browser-updates' && contains(github.event.pull_request.title, '(major)')) }} | |
| ruby: | |
| name: Ruby | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-ruby.yml | |
| if: "!cancelled() && needs.read-targets.outputs.rb != ''" | |
| with: | |
| compile-manager: ${{ needs.read-targets.outputs.compile-manager == 'true' }} | |
| smoke: ${{ !(github.head_ref == 'pinned-browser-updates' && contains(github.event.pull_request.title, '(major)')) }} | |
| rust: | |
| name: Rust | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-rust.yml | |
| if: "!cancelled() && needs.read-targets.outputs.rust != ''" | |
| javascript: | |
| name: JavaScript | |
| needs: [read-targets, wait-for-unlock] | |
| uses: ./.github/workflows/ci-javascript.yml | |
| if: "!cancelled() && needs.read-targets.outputs.js != ''" | |
| with: | |
| compile-manager: ${{ needs.read-targets.outputs.compile-manager == 'true' }} | |
| merge-flaky-results: | |
| name: Merge Flaky Results | |
| if: always() && github.event_name == 'schedule' && github.ref == 'refs/heads/trunk' | |
| needs: [dotnet, java, python, ruby, rust, javascript] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source tree | |
| uses: actions/checkout@v6 | |
| - name: Download results | |
| uses: actions/download-artifact@v8 | |
| continue-on-error: true | |
| with: | |
| pattern: flaky-* | |
| path: build/flaky-artifacts | |
| - name: Merge results | |
| id: merge | |
| shell: bash | |
| run: ./scripts/github-actions/merge-flaky-results.sh | |
| - name: Upload results | |
| if: steps.merge.outputs.results == 'true' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: merged-flaky-results-${{ github.run_id }} | |
| retention-days: 60 | |
| path: build/flaky/results.jsonl | |
| overwrite: true | |
| ci-success: | |
| name: CI Success | |
| if: always() | |
| needs: [lint, format, targets-mode, check, read-targets, dotnet, java, python, ruby, rust, javascript] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Verify required jobs succeeded | |
| run: | | |
| if ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}; then | |
| echo "One or more required jobs failed" | |
| exit 1 | |
| fi |