1- name : CI
2- on : [pull_request]
1+ name : CI Unit
2+ on :
3+ pull_request :
4+ branches : [ main, preview ]
35
46concurrency :
57 group : ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
68 cancel-in-progress : true
79
810jobs :
9- # =========================================================
10- # 1. DISCOVERY
11- # =========================================================
11+ # ==========================================
12+ # 1. DISCOVERY & BUCKETING
13+ # ==========================================
1214 discover :
1315 runs-on : ubuntu-latest
1416 outputs :
15- packages : ${{ steps.parse .outputs.packages }}
17+ buckets : ${{ steps.generate-matrix .outputs.buckets }}
1618 steps :
1719 - uses : actions/checkout@v4
18- - id : changes
20+
21+ - name : Detect Changed Packages
22+ id : changes
1923 uses : tj-actions/changed-files@v44
2024 with :
2125 files : packages/**
26+ dir_names : true
27+ dir_names_max_depth : 2
28+ matrix : false
2229
23- # Bulletproof directory extraction (ignores file names)
24- - id : parse
25- name : Extract Package Directories
30+ - name : Generate Balanced Buckets
31+ id : generate-matrix
2632 env :
27- ALL_FILES : ${{ steps.changes.outputs.all_changed_files }}
28- run : |
29- PKGS=$(echo "$ALL_FILES" | tr ' ' '\n' | cut -d'/' -f1,2 | sort -u | tr '\n' ' ')
30- echo "packages=$PKGS" >> $GITHUB_OUTPUT
33+ CHANGED_DIRS : ${{ steps.changes.outputs.all_changed_files }}
34+ run : python .github/scripts/matrix_generator.py --matrix-multiplier 6 --max-vms 40
3135
32- # =========================================================
33- # 2. EXECUTION (Parallelized internally via xargs)
34- # =========================================================
35- unit :
36+ # ==========================================
37+ # 2. HORIZONTAL EXECUTION
38+ # ==========================================
39+ unit-tests :
3640 needs : discover
37- if : ${{ needs.discover.outputs.packages != '' }}
41+ if : ${{ needs.discover.outputs.buckets != '[] ' }}
3842 runs-on : ubuntu-latest
3943 strategy :
4044 fail-fast : false
45+ max-parallel : 60
4146 matrix :
42- # Exactly 5 Jobs total. Never violates GitHub limits.
43- python : ["3.9", "3.10", "3.11", "3.12", "3.14"]
47+ chunk : ${{ fromJSON(needs.discover.outputs.buckets) }}
48+ python : ["3.9", "3.10", "3.11", "3.12", "3.13", "3. 14"]
4449
45- name : Unit (Python ${{ matrix.python }})
50+ name : Unit (Py ${{ matrix.python }})
4651 steps :
4752 - uses : actions/checkout@v4
4853 - uses : astral-sh/setup-uv@v5
4954 with :
5055 python-version : ${{ matrix.python }}
5156 enable-cache : true
52-
53- - name : Run Tests Concurrently
57+
58+ - name : Optimize Core Dependencies
59+ run : git config --global url."${GITHUB_WORKSPACE}".insteadOf "https://github.com/googleapis/google-cloud-python"
60+
61+ - name : Execute Chunk
5462 run : |
5563 export NOX_DEFAULT_VENV_BACKEND=uv
56- export UV_PRERELEASE=allow
64+ FAILED=0
5765
58- # Dropped -n 1 to fix the xargs warning.
59- echo "${{ needs.discover.outputs.packages }}" | tr ' ' '\n' | xargs -P 4 -I {} sh -c '
60- if [ -f "{}/noxfile.py" ]; then
61- cd {}
62-
63- # Run test and capture output
64- uvx --with "nox[uv]" nox -s "unit-${{ matrix.python }}" > nox_output.log 2>&1
65- STATUS=$?
66-
67- # Print output cleanly inside a GitHub group
68- echo "::group::Testing {} (Python ${{ matrix.python }})"
66+ for pkg in ${{ matrix.chunk }}; do
67+ echo "::group::Testing $pkg (Python ${{ matrix.python }})"
68+ cd "$pkg"
69+
70+ # Run test, pipe to log for clean UI folding
71+ if uvx --with 'nox[uv]' nox -s "unit-${{ matrix.python }}" > nox_output.log 2>&1; then
72+ cat nox_output.log
73+ else
6974 cat nox_output.log
70-
71- if [ $STATUS -ne 0 ]; then
72- # Check if it failed just because the Python version isn"t supported by this package
73- if grep -q "Sessions not found:" nox_output.log; then
74- echo "⏭️ Session unit-${{ matrix.python }} is not defined for this package. Safely skipping."
75- else
76- echo "❌ Tests failed in {}!"
77- echo "::endgroup::"
78- # Exit 1 allows other packages to finish testing, but ensures the workflow fails
79- exit 1
80- fi
81- fi
82-
83- echo "::endgroup::"
75+ # Gracefully skip if the Python version isn't supported by this legacy package
76+ grep -q "Sessions not found:" nox_output.log || FAILED=1
8477 fi
85- '
78+
79+ cd "$GITHUB_WORKSPACE"
80+ echo "::endgroup::"
81+ done
82+
83+ exit $FAILED
84+
85+ # ==========================================
86+ # 3. GATEKEEPER
87+ # ==========================================
88+ presubmit-passed :
89+ if : always()
90+ needs : [discover, unit-tests]
91+ runs-on : ubuntu-latest
92+ steps :
93+ - name : Evaluate Pipeline Status
94+ run : |
95+ if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
96+ echo "::error::One or more required CI jobs failed or were cancelled."
97+ exit 1
98+ fi
99+ echo "All dynamically generated CI jobs completed successfully."
0 commit comments