Skip to content

Commit 3b2982c

Browse files
authored
feat(dart): dotprompt and handlebars implementation (#509)
1 parent 33a2562 commit 3b2982c

File tree

94 files changed

+24553
-132
lines changed

Some content is hidden

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

94 files changed

+24553
-132
lines changed

.github/labeler.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ python:
6464
- "**/pyproject.toml"
6565
- "python/**"
6666

67+
dart:
68+
- changed-files:
69+
- any-glob-to-any-file:
70+
- "**/*.dart"
71+
- "dart/**"
72+
- "**/pubspec.yaml"
73+
- "**/analysis_options.yaml"
74+
75+
rules_dart:
76+
- changed-files:
77+
- any-glob-to-any-file:
78+
- "bazel/rules_dart/**"
79+
80+
dotprompt-dart:
81+
- changed-files:
82+
- any-glob-to-any-file:
83+
- "dart/dotprompt/**"
84+
85+
handlebarrz-dart:
86+
- changed-files:
87+
- any-glob-to-any-file:
88+
- "dart/handlebarrz/**"
89+
6790
js:
6891
- changed-files:
6992
- any-glob-to-any-file:

.github/workflows/dart.yml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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: "Dart checks"
18+
19+
on:
20+
pull_request:
21+
branches: [main]
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
check-paths:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
any_changed: ${{ steps.changed-files.outputs.any_changed }}
31+
steps:
32+
- uses: actions/checkout@v6
33+
with:
34+
fetch-depth: 0
35+
- name: Get changed files
36+
id: changed-files
37+
uses: tj-actions/changed-files@v45
38+
with:
39+
files: |
40+
dart/**
41+
bazel/dart/**
42+
bazel/rules_dart/**
43+
spec/**
44+
.github/workflows/dart.yml
45+
46+
format-check:
47+
needs: check-paths
48+
if: needs.check-paths.outputs.any_changed == 'true'
49+
name: Format Check
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v6
54+
55+
- name: Setup Dart
56+
uses: dart-lang/setup-dart@v1
57+
with:
58+
sdk: stable
59+
60+
- name: Get dependencies
61+
working-directory: dart/dotprompt
62+
run: dart pub get
63+
64+
- name: Check formatting
65+
working-directory: dart/dotprompt
66+
run: dart format --line-length=120 --set-exit-if-changed --output=none .
67+
68+
analyze:
69+
needs: check-paths
70+
if: needs.check-paths.outputs.any_changed == 'true'
71+
name: Static Analysis
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@v6
76+
77+
- name: Setup Dart
78+
uses: dart-lang/setup-dart@v1
79+
with:
80+
sdk: stable
81+
82+
- name: Get dependencies
83+
working-directory: dart/dotprompt
84+
run: dart pub get
85+
86+
- name: Run analyzer with strict settings
87+
working-directory: dart/dotprompt
88+
run: dart analyze --fatal-infos --fatal-warnings
89+
90+
test:
91+
needs: check-paths
92+
if: needs.check-paths.outputs.any_changed == 'true'
93+
name: Tests (${{ matrix.sdk }}, ${{ matrix.os }})
94+
runs-on: ${{ matrix.os }}
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
os: [ubuntu-latest, macos-latest]
99+
sdk: [stable, beta]
100+
steps:
101+
- name: Checkout code
102+
uses: actions/checkout@v6
103+
104+
- name: Setup Dart
105+
uses: dart-lang/setup-dart@v1
106+
with:
107+
sdk: ${{ matrix.sdk }}
108+
109+
- name: Get dependencies
110+
working-directory: dart/dotprompt
111+
run: dart pub get
112+
113+
- name: Run tests
114+
working-directory: dart/dotprompt
115+
run: dart test
116+
117+
- name: Run tests with coverage
118+
if: matrix.os == 'ubuntu-latest' && matrix.sdk == 'stable'
119+
working-directory: dart/dotprompt
120+
run: |
121+
dart pub global activate coverage
122+
dart pub global run coverage:test_with_coverage
123+
124+
bazel-build:
125+
needs: check-paths
126+
if: needs.check-paths.outputs.any_changed == 'true'
127+
name: Bazel Build & Test
128+
runs-on: ubuntu-latest
129+
steps:
130+
- name: Checkout code
131+
uses: actions/checkout@v6
132+
133+
- name: Setup Bazel
134+
uses: bazel-contrib/setup-bazel@0.14.0
135+
with:
136+
bazelisk-cache: true
137+
disk-cache: ${{ github.workflow }}
138+
repository-cache: true
139+
140+
- name: Build Dart targets
141+
run: bazel build //dart/...
142+
143+
- name: Run Dart tests via Bazel
144+
run: bazel test //dart/dotprompt/test:... --test_output=errors
145+
continue-on-error: true # Tests may need network access
146+
147+
antlr-grammar:
148+
needs: check-paths
149+
if: needs.check-paths.outputs.any_changed == 'true'
150+
name: ANTLR Grammar Validation
151+
runs-on: ubuntu-latest
152+
steps:
153+
- name: Checkout code
154+
uses: actions/checkout@v6
155+
156+
- name: Setup Java (required for ANTLR)
157+
uses: actions/setup-java@v4
158+
with:
159+
distribution: 'temurin'
160+
java-version: '17'
161+
162+
- name: Install ANTLR4
163+
run: |
164+
curl -O https://www.antlr.org/download/antlr-4.13.2-complete.jar
165+
echo "alias antlr4='java -jar $(pwd)/antlr-4.13.2-complete.jar'" >> $GITHUB_ENV
166+
167+
- name: Validate Handlebars Grammar
168+
run: |
169+
cd spec/handlebars/antlr
170+
java -jar ${{ github.workspace }}/antlr-4.13.2-complete.jar -Dlanguage=Dart HandlebarsLexer.g4
171+
java -jar ${{ github.workspace }}/antlr-4.13.2-complete.jar -Dlanguage=Dart -visitor -no-listener HandlebarsParser.g4
172+
echo "ANTLR grammar validated successfully"
173+
174+
- name: Check generated files match
175+
run: |
176+
# Generate fresh files
177+
cd spec/handlebars/antlr
178+
java -jar ${{ github.workspace }}/antlr-4.13.2-complete.jar -Dlanguage=Dart HandlebarsLexer.g4
179+
java -jar ${{ github.workspace }}/antlr-4.13.2-complete.jar -Dlanguage=Dart -visitor -no-listener HandlebarsParser.g4
180+
181+
# Compare with committed files (excluding headers)
182+
for file in HandlebarsLexer.dart HandlebarsParser.dart HandlebarsParserVisitor.dart HandlebarsParserBaseVisitor.dart; do
183+
if [ -f "../../dart/handlebarrz/lib/src/antlr/$file" ]; then
184+
# Strip header comments and compare
185+
tail -n +22 "$file" > "/tmp/generated_$file"
186+
tail -n +22 "../../dart/handlebarrz/lib/src/antlr/$file" > "/tmp/committed_$file"
187+
if ! diff -q "/tmp/generated_$file" "/tmp/committed_$file" > /dev/null; then
188+
echo "Warning: Generated $file differs from committed version"
189+
echo "Run './scripts/generate_handlebars_parser' to update"
190+
fi
191+
fi
192+
done
193+
194+
dart-checks-all:
195+
if: always()
196+
needs: [format-check, analyze, test, bazel-build, antlr-grammar]
197+
runs-on: ubuntu-latest
198+
steps:
199+
- name: Check overall status
200+
run: |
201+
if [[ "${{ needs.format-check.result }}" == "failure" || \
202+
"${{ needs.analyze.result }}" == "failure" || \
203+
"${{ needs.test.result }}" == "failure" || \
204+
"${{ needs.antlr-grammar.result }}" == "failure" ]]; then
205+
echo "Dart checks failed"
206+
exit 1
207+
fi
208+
echo "Dart checks passed or were skipped"
209+
exit 0

.release-please-config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@
7878
"release-type": "simple",
7979
"component": "dotprompt-java"
8080
},
81+
"dart/dotprompt": {
82+
"release-type": "dart",
83+
"component": "dotprompt-dart",
84+
"extra-files": [
85+
{
86+
"type": "yaml",
87+
"path": "pubspec.yaml",
88+
"jsonpath": "$.version"
89+
}
90+
]
91+
},
92+
"bazel/rules_dart": {
93+
"release-type": "simple",
94+
"component": "rules_dart"
95+
},
8196
"packages/vscode": {
8297
"release-type": "node",
8398
"component": "dotprompt-vscode"

.release-please-manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"python/handlebarrz": "0.1.8",
55
"go": "0.2.0",
66
"java": "0.1.0",
7+
"dart/dotprompt": "0.0.1",
8+
"bazel/rules_dart": "0.0.1",
79
"rs": "0.1.0",
810
"packages/vscode": "0.0.1",
911
"packages/vim": "0.1.0",

BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
2121
package(default_visibility = ["//visibility:public"])
2222

2323
# gazelle:prefix github.com/google/dotprompt
24-
gazelle(name = "gazelle")
24+
gazelle(
25+
name = "gazelle",
26+
gazelle = "@rules_dart//gazelle:gazelle_bin",
27+
)
2528

2629
# Building this package creates bazel-bin/node_modules/@google/dotprompt
2730
# so that other packages can depend on this target.

0 commit comments

Comments
 (0)