@@ -25,14 +25,74 @@ jobs:
2525 components : rustfmt
2626 - run : cargo fmt --all --check
2727
28+ build-protoc-plugin :
29+ runs-on : ${{ matrix.os }}
30+ strategy :
31+ matrix :
32+ os : [ubuntu-latest, macOS-latest, windows-latest]
33+ outputs :
34+ cache-hit : ${{ steps.cache-plugin.outputs.cache-hit }}
35+ steps :
36+ - uses : actions/checkout@v4
37+ - name : Cache protoc plugin
38+ id : cache-plugin
39+ uses : actions/cache@v4
40+ with :
41+ path : ${{ runner.temp }}/protoc-plugin
42+ # The key changes only when plugin source files change
43+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
44+ - name : Install Bazel
45+ if : steps.cache-plugin.outputs.cache-hit != 'true'
46+ uses : bazel-contrib/setup-bazel@0.15.0
47+ with :
48+ # Avoid downloading Bazel every time.
49+ bazelisk-cache : true
50+ # Store build cache per workflow.
51+ disk-cache : ${{ github.workflow }}
52+ # Share repository cache between workflows.
53+ repository-cache : true
54+ module-root : ./protoc-gen-rust-grpc
55+ # Building the protoc plugin from scratch takes 6–14 minutes, depending on
56+ # the OS. This delays the execution of workflows that use the plugin in
57+ # build.rs files. We try to avoid rebuilding the plugin if it hasn't
58+ # changed.
59+ - name : Build protoc plugin
60+ if : steps.cache-plugin.outputs.cache-hit != 'true'
61+ working-directory : ./protoc-gen-rust-grpc
62+ shell : bash
63+ run : |
64+ set -e
65+ # On windows, the "//src" gets converted to "/". Disable this path
66+ # conversion.
67+ export MSYS_NO_PATHCONV=1
68+ export MSYS2_ARG_CONV_EXCL="*"
69+
70+ bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
71+
72+ # The target path needs to match the cache config.
73+ TARGET_PATH="${{ runner.temp }}/protoc-plugin"
74+ mkdir -p "${TARGET_PATH}"
75+ cp bazel-bin/src/protoc-gen-rust-grpc "${TARGET_PATH}"
76+
2877 clippy :
2978 runs-on : ubuntu-latest
79+ needs : build-protoc-plugin
3080 steps :
3181 - uses : actions/checkout@v4
3282 - uses : hecrj/setup-rust-action@v2
3383 with :
3484 components : clippy
3585 - uses : taiki-e/install-action@protoc
86+ - name : Restore protoc plugin from cache
87+ id : cache-plugin
88+ uses : actions/cache@v4
89+ with :
90+ path : ${{ runner.temp }}/protoc-plugin
91+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
92+ - name : Add protoc plugin to PATH
93+ shell : bash
94+ run : |
95+ echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
3696 - uses : Swatinem/rust-cache@v2
3797 - run : cargo clippy --workspace --all-features --all-targets
3898
47107
48108 udeps :
49109 runs-on : ubuntu-latest
110+ needs : build-protoc-plugin
50111 steps :
51112 - uses : actions/checkout@v4
52113 - uses : dtolnay/rust-toolchain@master
@@ -55,6 +116,16 @@ jobs:
55116 - uses : taiki-e/install-action@cargo-hack
56117 - uses : taiki-e/install-action@cargo-udeps
57118 - uses : taiki-e/install-action@protoc
119+ - name : Restore protoc plugin from cache
120+ id : cache-plugin
121+ uses : actions/cache@v4
122+ with :
123+ path : ${{ runner.temp }}/protoc-plugin
124+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
125+ - name : Add protoc plugin to PATH
126+ shell : bash
127+ run : |
128+ echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
58129 - uses : Swatinem/rust-cache@v2
59130 - run : cargo hack udeps --workspace --exclude-features=_tls-any,tls,tls-aws-lc,tls-ring --each-feature
60131 - run : cargo udeps --package tonic --features tls-ring,transport
66137
67138 check :
68139 runs-on : ${{ matrix.os }}
140+ needs : build-protoc-plugin
69141 strategy :
70142 matrix :
71143 os : [ubuntu-latest, macOS-latest, windows-latest]
@@ -76,6 +148,16 @@ jobs:
76148 - uses : hecrj/setup-rust-action@v2
77149 - uses : taiki-e/install-action@cargo-hack
78150 - uses : taiki-e/install-action@protoc
151+ - name : Restore protoc plugin from cache
152+ id : cache-plugin
153+ uses : actions/cache@v4
154+ with :
155+ path : ${{ runner.temp }}/protoc-plugin
156+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
157+ - name : Add protoc plugin to PATH
158+ shell : bash
159+ run : |
160+ echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
79161 - uses : Swatinem/rust-cache@v2
80162 - name : Check features
81163 run : cargo hack check --workspace --no-private --each-feature --no-dev-deps
@@ -108,13 +190,24 @@ jobs:
108190
109191 test :
110192 runs-on : ${{ matrix.os }}
193+ needs : build-protoc-plugin
111194 strategy :
112195 matrix :
113196 os : [ubuntu-latest, macOS-latest, windows-latest]
114197 steps :
115198 - uses : actions/checkout@v4
116199 - uses : hecrj/setup-rust-action@v2
117200 - uses : taiki-e/install-action@protoc
201+ - name : Restore protoc plugin from cache
202+ id : cache-plugin
203+ uses : actions/cache@v4
204+ with :
205+ path : ${{ runner.temp }}/protoc-plugin
206+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
207+ - name : Add protoc plugin to PATH
208+ shell : bash
209+ run : |
210+ echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
118211 - uses : taiki-e/install-action@cargo-hack
119212 - uses : taiki-e/install-action@cargo-nextest
120213 - uses : Swatinem/rust-cache@v2
@@ -134,13 +227,24 @@ jobs:
134227 interop :
135228 name : Interop Tests
136229 runs-on : ${{ matrix.os }}
230+ needs : build-protoc-plugin
137231 strategy :
138232 matrix :
139233 os : [ubuntu-latest, macOS-latest, windows-latest]
140234 steps :
141235 - uses : actions/checkout@v4
142236 - uses : hecrj/setup-rust-action@v2
143237 - uses : taiki-e/install-action@protoc
238+ - name : Restore protoc plugin from cache
239+ id : cache-plugin
240+ uses : actions/cache@v4
241+ with :
242+ path : ${{ runner.temp }}/protoc-plugin
243+ key : ${{ runner.os }}-protoc-plugin-${{ hashFiles('protoc-gen-rust-grpc/src/**', 'protoc-gen-rust-grpc/.bazelrc', 'protoc-gen-rust-grpc/MODULE.bazel') }}
244+ - name : Add protoc plugin to PATH
245+ shell : bash
246+ run : |
247+ echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
144248 - uses : Swatinem/rust-cache@v2
145249 - name : Run interop tests
146250 run : ./interop/test.sh
0 commit comments