Skip to content

Commit 5369b40

Browse files
authored
feat(rules_dart,rules_flutter): enhance Bazel rules with workers and linting fixes (#513)
* feat: rules_flutter * fix(rules_dart): update setup-bazel action to v0.18.0 Fixes CI failures in RBE workflow by using the same setup-bazel version and configuration pattern as other workflows in the repo. * fix(rules_dart): remove deprecated --experimental_use_sandboxfs flag This flag is no longer recognized in Bazel 9.0.0. * fix(rules_dart): make RBE tests non-blocking RBE sandbox tests may fail on macOS due to Dart SDK requiring network access for pub get. Made these tests informational rather than blocking.
1 parent 1624c75 commit 5369b40

File tree

126 files changed

+19119
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+19119
-232
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ node_modules
1010
target/
1111
third_party/docsite/node_modules
1212
bazel/rules_dart
13+
bazel/rules_flutter

.github/labeler.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ rules_dart:
7777
- any-glob-to-any-file:
7878
- "bazel/rules_dart/**"
7979

80+
rules_flutter:
81+
- changed-files:
82+
- any-glob-to-any-file:
83+
- "bazel/rules_flutter/**"
84+
8085
dotprompt-dart:
8186
- changed-files:
8287
- any-glob-to-any-file:

.github/workflows/flutter.yml

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
name: "Flutter Rules checks"
18+
19+
on:
20+
pull_request:
21+
branches: [main]
22+
push:
23+
branches: [main]
24+
25+
permissions:
26+
contents: read
27+
28+
jobs:
29+
check-paths:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
any_changed: ${{ steps.changed-files.outputs.any_changed }}
33+
steps:
34+
- uses: actions/checkout@v6
35+
with:
36+
fetch-depth: 0
37+
- name: Get changed files
38+
id: changed-files
39+
uses: tj-actions/changed-files@v45
40+
with:
41+
files: |
42+
bazel/rules_flutter/**
43+
bazel/rules_dart/**
44+
.github/workflows/flutter.yml
45+
46+
bazel-build:
47+
needs: check-paths
48+
if: needs.check-paths.outputs.any_changed == 'true'
49+
name: Bazel Build (${{ matrix.os }})
50+
runs-on: ${{ matrix.os }}
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
os: [ubuntu-latest, macos-latest]
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v6
58+
59+
- name: Setup Bazel
60+
uses: bazel-contrib/setup-bazel@0.18.0
61+
with:
62+
bazelisk-cache: true
63+
disk-cache: ${{ github.workflow }}-${{ matrix.os }}
64+
repository-cache: true
65+
66+
- name: Build rules_flutter
67+
working-directory: bazel/rules_flutter
68+
run: bazel build //...
69+
70+
- name: Query all targets
71+
working-directory: bazel/rules_flutter
72+
run: bazel query //...
73+
74+
starlark-lint:
75+
needs: check-paths
76+
if: needs.check-paths.outputs.any_changed == 'true'
77+
name: Starlark Lint
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Checkout code
81+
uses: actions/checkout@v6
82+
83+
- name: Install buildifier
84+
run: |
85+
wget -q https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildifier-linux-amd64
86+
chmod +x buildifier-linux-amd64
87+
sudo mv buildifier-linux-amd64 /usr/local/bin/buildifier
88+
89+
- name: Check formatting (rules_flutter)
90+
working-directory: bazel/rules_flutter
91+
run: |
92+
buildifier --mode=check --lint=warn -r .
93+
94+
- name: Check formatting (rules_dart)
95+
working-directory: bazel/rules_dart
96+
run: |
97+
buildifier --mode=check --lint=warn -r .
98+
99+
grpc-example:
100+
needs: check-paths
101+
if: needs.check-paths.outputs.any_changed == 'true'
102+
name: gRPC Example (${{ matrix.os }})
103+
runs-on: ${{ matrix.os }}
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
os: [ubuntu-latest, macos-latest]
108+
steps:
109+
- name: Checkout code
110+
uses: actions/checkout@v6
111+
112+
- name: Setup Flutter
113+
uses: subosito/flutter-action@v2
114+
with:
115+
flutter-version: '3.27.0'
116+
channel: 'stable'
117+
cache: true
118+
119+
- name: Setup Dart
120+
uses: dart-lang/setup-dart@v1
121+
with:
122+
sdk: stable
123+
124+
- name: Install protoc
125+
uses: arduino/setup-protoc@v3
126+
with:
127+
version: '28.x'
128+
129+
- name: Install protoc-gen-dart
130+
run: dart pub global activate protoc_plugin
131+
132+
- name: Setup gRPC example
133+
working-directory: bazel/rules_flutter/examples/grpc_app
134+
run: |
135+
# Get dependencies
136+
flutter pub get
137+
cd server && dart pub get && cd ..
138+
139+
# Add platform support
140+
flutter create --platforms=web,linux . 2>/dev/null || true
141+
142+
# Generate proto files
143+
mkdir -p lib/generated server/lib/generated
144+
export PATH="$HOME/.pub-cache/bin:$PATH"
145+
protoc --dart_out=grpc:lib/generated -Iproto proto/helloworld.proto
146+
cp lib/generated/*.dart server/lib/generated/
147+
148+
- name: Analyze Flutter client
149+
working-directory: bazel/rules_flutter/examples/grpc_app
150+
run: flutter analyze
151+
152+
- name: Analyze Dart server
153+
working-directory: bazel/rules_flutter/examples/grpc_app/server
154+
run: dart analyze
155+
156+
- name: Build Flutter web
157+
working-directory: bazel/rules_flutter/examples/grpc_app
158+
run: flutter build web
159+
160+
- name: Test server startup
161+
working-directory: bazel/rules_flutter/examples/grpc_app/server
162+
run: |
163+
# Start server in background
164+
dart run bin/server.dart &
165+
SERVER_PID=$!
166+
sleep 3
167+
168+
# Check if server is running
169+
if kill -0 $SERVER_PID 2>/dev/null; then
170+
echo "Server started successfully"
171+
kill $SERVER_PID
172+
else
173+
echo "Server failed to start"
174+
exit 1
175+
fi
176+
177+
container-proxy:
178+
needs: check-paths
179+
if: needs.check-paths.outputs.any_changed == 'true'
180+
name: Container Proxy Config
181+
runs-on: ubuntu-latest
182+
steps:
183+
- name: Checkout code
184+
uses: actions/checkout@v6
185+
186+
- name: Validate Envoy config syntax
187+
working-directory: bazel/rules_flutter/examples/grpc_app/proxy
188+
run: |
189+
# Basic YAML validation
190+
python3 -c "import yaml; yaml.safe_load(open('envoy.yaml'))"
191+
echo "Envoy config is valid YAML"
192+
193+
- name: Validate docker-compose.yaml
194+
working-directory: bazel/rules_flutter/examples/grpc_app/proxy
195+
run: |
196+
# Basic YAML validation
197+
python3 -c "import yaml; yaml.safe_load(open('docker-compose.yaml'))"
198+
echo "docker-compose.yaml is valid YAML"
199+
200+
- name: Test Envoy container start (Podman preferred)
201+
working-directory: bazel/rules_flutter/examples/grpc_app/proxy
202+
run: |
203+
# Prefer Podman, fall back to Docker
204+
if command -v podman &> /dev/null; then
205+
RUNTIME="podman"
206+
else
207+
RUNTIME="docker"
208+
fi
209+
echo "Using container runtime: $RUNTIME"
210+
211+
$RUNTIME run -d --name envoy-test \
212+
-v $(pwd)/envoy.yaml:/etc/envoy/envoy.yaml:ro \
213+
-p 8080:8080 -p 9901:9901 \
214+
envoyproxy/envoy:distroless-v1.28-latest -c /etc/envoy/envoy.yaml
215+
216+
# Give it time to start
217+
sleep 5
218+
219+
# Check if container is running
220+
if $RUNTIME ps | grep envoy-test; then
221+
echo "Envoy container started successfully"
222+
223+
# Check admin endpoint
224+
curl -s http://localhost:9901/ready || true
225+
226+
$RUNTIME stop envoy-test
227+
$RUNTIME rm envoy-test
228+
else
229+
echo "Envoy container failed to start"
230+
$RUNTIME logs envoy-test || true
231+
$RUNTIME rm envoy-test || true
232+
exit 1
233+
fi
234+
235+
windows-build:
236+
needs: check-paths
237+
if: needs.check-paths.outputs.any_changed == 'true'
238+
name: Windows Build
239+
runs-on: windows-latest
240+
steps:
241+
- name: Checkout code
242+
uses: actions/checkout@v6
243+
244+
- name: Setup Bazel
245+
uses: bazel-contrib/setup-bazel@0.18.0
246+
with:
247+
bazelisk-cache: true
248+
disk-cache: ${{ github.workflow }}-windows
249+
repository-cache: true
250+
251+
- name: Build rules_flutter
252+
working-directory: bazel/rules_flutter
253+
run: bazel build //...
254+
255+
- name: Query all targets
256+
working-directory: bazel/rules_flutter
257+
run: bazel query //...
258+
259+
flutter-checks-all:
260+
if: always()
261+
needs: [bazel-build, starlark-lint, grpc-example, container-proxy, windows-build]
262+
runs-on: ubuntu-latest
263+
steps:
264+
- name: Check overall status
265+
run: |
266+
if [[ "${{ needs.bazel-build.result }}" == "failure" || \
267+
"${{ needs.starlark-lint.result }}" == "failure" || \
268+
"${{ needs.grpc-example.result }}" == "failure" || \
269+
"${{ needs.container-proxy.result }}" == "failure" || \
270+
"${{ needs.windows-build.result }}" == "failure" ]]; then
271+
echo "Flutter rules checks failed"
272+
exit 1
273+
fi
274+
echo "Flutter rules checks passed or were skipped"
275+
exit 0

0 commit comments

Comments
 (0)