Skip to content

Commit f9b9392

Browse files
chore: fix parallelism in library compilation (#26395)
* chore: fix parallelism in library compilation * trigger on pull request (temporarily) * do not use awk * try running command without piping output * move to script file * chore: add vim files to .gitignore * chore: skip enforcer in verification script * specify working directory * parallelize on variant * fix "run" step * do not cancel parallel jobs if one fails * parallelize by alphabet letter * use explicit letters * correct matrix config * add runs-on to print_results job * test against current variant only * fix output file reference * fix error handling * add output consumption config * use official recommendation for parallel job output handling * correct output reference * print results from parallel jobs * fix sed command * fail on error * do not use xtrace on print results job * improve error message
1 parent 5d5c9f3 commit f9b9392

File tree

4 files changed

+102
-56
lines changed

4 files changed

+102
-56
lines changed

.github/workflows/verify.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
set -ex
2+
export repo_dir=$(realpath $(dirname "${BASH_SOURCE[0]}")/../../)
3+
pushd "${repo_dir}/clients"
4+
5+
# We only test against the latest variant
6+
readonly CURRENT_VARIANT="2.0.0"
7+
8+
# An optional argument to only compile libraries starting with this letter
9+
starting_letter="$1"
10+
11+
# find all generated clients' pom.xml
12+
find . -wholename "*${CURRENT_VARIANT}/pom.xml" -not -path '*/target/*' > pom_list_raw
13+
cat pom_list_raw
14+
15+
# trim down to those starting with "${starting_letter}"
16+
cat pom_list_raw | { grep "google-api-services-${starting_letter}" || true; } > pom_list
17+
cat pom_list
18+
19+
20+
# format result to list of Maven modules
21+
cat pom_list | cut -d'/' -f2-4 \
22+
| sed 's/\(.*\)/<module>\1<\/module>/' > module_list
23+
cat module_list
24+
25+
# produce a temporary pom with the modules
26+
(echo "<project><modelVersion>4.0.0</modelVersion><groupId>temp</groupId><artifactId>temp</artifactId><version>1.0</version><packaging>pom</packaging><modules>"; cat module_list; echo "</modules></project>") > pom.xml
27+
cat pom.xml
28+
29+
# use generated pom to test compilation
30+
mvn clean compile -T 1.5C -Dmaven.testSkip=true -Denforcer.skip -fae --fail-at-end 2>&1 | tee out
31+
cat out | grep 'rev20' | grep 's]' | { grep 'FAILURE' || true; } > errors
32+
if [[ $(cat errors | wc -l) -gt 0 ]]; then
33+
echo "Compilation errors found in the following libraries:"
34+
cat errors
35+
# send to GH output
36+
if [[ -f "${GITHUB_OUTPUT}" ]]; then
37+
echo "failed_libraries_${starting_letter}=$(cat errors | tr '\n' ',')" > "${GITHUB_OUTPUT}"
38+
fi
39+
fi
40+
echo "No compilation errors found"

.github/workflows/verify.yaml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,48 @@ on:
33
# Runs at 04:00 am
44
- cron: '0 4 * * *'
55
workflow_dispatch:
6+
# delete this before merging the PR
7+
pull_request:
68
# Generates a list of libraries that cannot be
79
# compiled (printed to the action stdout)
810
name: Verify libraries compilation
911
jobs:
1012
verify:
1113
runs-on: 'ubuntu-24.04'
14+
continue-on-error: true
15+
strategy:
16+
matrix:
17+
# We will parallelize by alphabet letter
18+
letter: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
19+
fail-fast: false
20+
outputs:
21+
# follows official example from https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/passing-information-between-jobs#using-job-outputs-in-a-matrix-job
22+
failed_libraries_a: ${{ steps.compile.outputs.failed_libraries_a }}
23+
failed_libraries_b: ${{ steps.compile.outputs.failed_libraries_b }}
24+
failed_libraries_c: ${{ steps.compile.outputs.failed_libraries_c }}
25+
failed_libraries_d: ${{ steps.compile.outputs.failed_libraries_d }}
26+
failed_libraries_e: ${{ steps.compile.outputs.failed_libraries_e }}
27+
failed_libraries_f: ${{ steps.compile.outputs.failed_libraries_f }}
28+
failed_libraries_g: ${{ steps.compile.outputs.failed_libraries_g }}
29+
failed_libraries_h: ${{ steps.compile.outputs.failed_libraries_h }}
30+
failed_libraries_i: ${{ steps.compile.outputs.failed_libraries_i }}
31+
failed_libraries_j: ${{ steps.compile.outputs.failed_libraries_j }}
32+
failed_libraries_k: ${{ steps.compile.outputs.failed_libraries_k }}
33+
failed_libraries_l: ${{ steps.compile.outputs.failed_libraries_l }}
34+
failed_libraries_m: ${{ steps.compile.outputs.failed_libraries_m }}
35+
failed_libraries_n: ${{ steps.compile.outputs.failed_libraries_n }}
36+
failed_libraries_o: ${{ steps.compile.outputs.failed_libraries_o }}
37+
failed_libraries_p: ${{ steps.compile.outputs.failed_libraries_p }}
38+
failed_libraries_q: ${{ steps.compile.outputs.failed_libraries_q }}
39+
failed_libraries_r: ${{ steps.compile.outputs.failed_libraries_r }}
40+
failed_libraries_s: ${{ steps.compile.outputs.failed_libraries_s }}
41+
failed_libraries_t: ${{ steps.compile.outputs.failed_libraries_t }}
42+
failed_libraries_u: ${{ steps.compile.outputs.failed_libraries_u }}
43+
failed_libraries_v: ${{ steps.compile.outputs.failed_libraries_v }}
44+
failed_libraries_w: ${{ steps.compile.outputs.failed_libraries_w }}
45+
failed_libraries_x: ${{ steps.compile.outputs.failed_libraries_x }}
46+
failed_libraries_y: ${{ steps.compile.outputs.failed_libraries_y }}
47+
failed_libraries_z: ${{ steps.compile.outputs.failed_libraries_z }}
1248
steps:
1349
- uses: actions/setup-java@v3
1450
with:
@@ -17,8 +53,27 @@ jobs:
1753
- uses: actions/checkout@v2
1854
with:
1955
path: google-api-java-client-services
20-
# we install the moreutils `parallel` command
21-
- run: sudo apt-get install moreutils
22-
- working-directory: google-api-java-client-services
23-
run: bash .github/workflows/verify_compilation.sh
56+
57+
- id: compile
58+
working-directory: google-api-java-client-services
59+
run: |
60+
set -ex
61+
bash .github/workflows/verify.sh "${{matrix.letter}}"
62+
print_results:
63+
runs-on: 'ubuntu-24.04'
64+
needs: [verify]
65+
steps:
66+
- run: |
67+
set -e
68+
echo '${{ toJSON(needs.verify.outputs) }}' \
69+
| jq -j 'to_entries[] | select(.key | startswith("failed_libraries_")) | .value' \
70+
| sed 's/,/\n/g' > failed_libs
71+
72+
if [[ $(cat failed_libs | wc -l) -gt 0 ]]; then
73+
echo "The following libraries cannot be compiled:"
74+
cat failed_libs
75+
exit 1
76+
fi
77+
echo "All libraries of the current variant are compilable!"
78+
2479

.github/workflows/verify_compilation.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.gitignore
22

3+
# Vim files
4+
*.swp
5+
36
# Packages
47
dist
58
build

0 commit comments

Comments
 (0)