|
| 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 |
0 commit comments