-
Notifications
You must be signed in to change notification settings - Fork 2.1k
162 lines (149 loc) · 6.12 KB
/
bazel.yml
File metadata and controls
162 lines (149 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Build and test the library with Bazel.
#
# Bazel's built-in action caching combined with GitHub Actions cache gives
# incremental builds: only changed targets and their dependents are rebuilt.
#
# Cache layers used:
# 1. Repository cache – downloaded JARs / external repositories
# 2. Disk cache – action output cache (build artifacts)
# Repository cache is shared across OS runners; disk cache remains OS-scoped.
name: bazel
on:
push:
branches: ["master", "release-**"]
paths:
- "**/*.java"
- "**/BUILD.bazel"
- "MODULE.bazel"
- "pom.xml"
- "scripts/sync_bazel_dependencies.py"
- ".bazelversion"
- ".bazelrc"
- ".github/workflows/bazel.yml"
pull_request:
branches: ["master", "release-**"]
paths:
- "**/*.java"
- "**/BUILD.bazel"
- "MODULE.bazel"
- "pom.xml"
- "scripts/sync_bazel_dependencies.py"
- ".bazelversion"
- ".bazelrc"
- ".github/workflows/bazel.yml"
jobs:
bazel-build-test:
name: Bazel build & test (Java ${{ matrix.java }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
java: ["11.0.x", "17.0.x", "21.0.x"]
os: [ubuntu-latest, macos-latest, windows-latest]
env:
BAZELISK_SKIP_VERSION_CHECK: "1"
# Prevent MSYS from rewriting Bazel labels (//pkg:target) into paths on
# Windows bash runners.
MSYS2_ARG_CONV_EXCL: "*"
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
- name: Set up Java ${{ matrix.java }}
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: temurin
java-version: ${{ matrix.java }}
# Install Bazelisk which reads the pinned version from .bazelversion.
# Install into $HOME/.local/bin (no root required) and add it to PATH.
- name: Install Bazelisk (Linux)
if: runner.os == 'Linux'
run: |
mkdir -p "$HOME/.local/bin"
curl -fsSL \
https://github.com/bazelbuild/bazelisk/releases/download/v1.24.1/bazelisk-linux-amd64 \
-o "$HOME/.local/bin/bazel"
chmod +x "$HOME/.local/bin/bazel"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Install Bazelisk (macOS)
if: runner.os == 'macOS'
run: |
mkdir -p "$HOME/.local/bin"
ARCH=$(uname -m)
SUFFIX="amd64"
[[ "$ARCH" == "arm64" ]] && SUFFIX="arm64"
curl -fsSL \
"https://github.com/bazelbuild/bazelisk/releases/download/v1.24.1/bazelisk-darwin-${SUFFIX}" \
-o "$HOME/.local/bin/bazel"
chmod +x "$HOME/.local/bin/bazel"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Install Bazelisk (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$dir = Join-Path $HOME ".local\bin"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
Invoke-WebRequest `
-Uri "https://github.com/bazelbuild/bazelisk/releases/download/v1.24.1/bazelisk-windows-amd64.exe" `
-OutFile (Join-Path $dir "bazel.exe")
Add-Content $env:GITHUB_PATH "$dir"
# ----------------------------------------------------------------
# Cache layers
# The disk cache stores compiled action outputs; the repository cache
# stores downloaded external files (JARs, etc.).
# ----------------------------------------------------------------
- name: Restore Bazel repository cache (cross-OS)
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cache/bazel/cache/repos/v1
key: bazel-repos-java${{ matrix.java }}-${{ hashFiles('MODULE.bazel', '.bazelversion', 'maven_install.json') }}
restore-keys: |
bazel-repos-java${{ matrix.java }}-
bazel-repos-
enableCrossOsArchive: true
- name: Restore Bazel disk cache
id: bazel-cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/bazel-disk-cache
~/.cache/bazel/cache/repos/v1
key: bazel-${{ runner.os }}-java${{ matrix.java }}-${{ hashFiles('MODULE.bazel', 'pom.xml', 'scripts/sync_bazel_dependencies.py', '.bazelversion', 'maven_install.json') }}
restore-keys: |
bazel-${{ runner.os }}-java${{ matrix.java }}-
bazel-${{ runner.os }}-
- name: Verify Bazel dependency sync
run: python3 scripts/sync_bazel_dependencies.py --check
# Re-generate the Maven lock file so it is always consistent with
# MODULE.bazel. The __INPUT_ARTIFACTS_HASH in the committed file is
# intentionally set to -1 to signal that the file needs to be regenerated;
# REPIN=1 overwrites it with the correct value. Once the artifact list
# stabilises, subsequent runs where MODULE.bazel has not changed are fast
# because rules_jvm_external short-circuits on an identical artifact list.
- name: Pin Maven dependencies
shell: bash
run: REPIN=1 bazel run @maven//:pin
# ----------------------------------------------------------------
# Build all core modules
# ----------------------------------------------------------------
# Use folded YAML scalars (no shell line-continuation backslashes) so
# the generated script remains portable across Windows/Linux/macOS.
- name: Build
shell: bash
run: >-
bazel build --config=ci
//kubernetes:client-java-api
//proto:client-java-proto
//util:client-java
//fluent:client-java-api-fluent
//extended:client-java-extended
# ----------------------------------------------------------------
# Test — run per-module test suites
# ----------------------------------------------------------------
- name: Test core modules
shell: bash
run: >-
bazel test --config=ci
//kubernetes:tests
//util:tests
//extended:tests