| name: build | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| schedule: | |
| # Make sure everything is still working by running the CI weekly. | |
| - cron: "0 5 * * 1" | |
| permissions: {} | |
| jobs: | |
| zizmor: | |
| permissions: | |
| security-events: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - name: Run zizmor 🌈 | |
| uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0 | |
| analyze: | |
| strategy: | |
| matrix: | |
| dart-sdk: [stable, beta, dev] | |
| runs-on: ubuntu-latest | |
| outputs: | |
| stable: ${{ steps.output.outputs.stable }} | |
| beta: ${{ steps.output.outputs.beta }} | |
| dev: ${{ steps.output.outputs.dev }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - uses: dart-lang/setup-dart@v1 | |
| id: dart | |
| with: | |
| sdk: ${{ matrix.dart-sdk }} | |
| - name: "Setup local pub cache folder" | |
| # Make pub cache folder consistent across OSes, so that we can share the cache. | |
| run: "echo PUB_CACHE=.dart_tool/pub-cache/ >> $GITHUB_ENV" | |
| shell: bash | |
| # We need to update the cache whenever the pubspec.lock changes, as that | |
| # indicates a changed dependency after `pub upgrade`. However, we can't | |
| # include the pubspec.lock in the cache key as it's not part of the repository. | |
| # So, we explicitly restore from and update to the cache as needed. | |
| - uses: actions/cache/restore@v6 | |
| id: restore | |
| with: | |
| path: | | |
| ${{ env.PUB_CACHE }} | |
| pubspec.lock | |
| key: dart-deps-${{ steps.dart.outputs.dart-version }}-${{ hashFiles('pubspec.yaml') }} | |
| restore-keys: | |
| dart-deps-${{ steps.dart.outputs.dart-version }} | |
| dart-deps- | |
| enableCrossOsArchive: true | |
| - name: "Hash pubspec lockfiles before pub upgrade" | |
| id: deps-before | |
| run: | | |
| echo "lockfiles=${{ hashFiles('**/pubspec.lock') }}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - name: "Install dependencies" | |
| run: dart pub upgrade | |
| - name: "Ensure formatted" | |
| run: dart format --output=none --set-exit-if-changed . | |
| - name: "Analyze project" | |
| run: dart analyze --fatal-infos | |
| - name: "Update cache due to changed pubspec.lock" | |
| if: ${{ hashFiles('**/pubspec.lock') != steps.deps-before.outputs.lockfiles || !steps.restore.outputs.cache-hit }} | |
| uses: actions/cache/save@v6 | |
| with: | |
| path: | | |
| ${{ env.PUB_CACHE }} | |
| pubspec.lock | |
| key: dart-deps-${{ steps.dart.outputs.dart-version }}-${{ hashFiles('pubspec.yaml') }} | |
| enableCrossOsArchive: true | |
| # This allows the test matrix to depend on a matching output from this matrix invocation, see | |
| # https://github.com/orgs/community/discussions/26639#discussioncomment-3949595 | |
| - name: Save Dart version for matching test run | |
| id: output | |
| run: | | |
| echo "${{ matrix.dart-sdk }}=${STEPS_DART_OUTPUTS_DART_VERSION}" >> $GITHUB_OUTPUT | |
| env: | |
| STEPS_DART_OUTPUTS_DART_VERSION: ${{ steps.dart.outputs.dart-version }} | |
| test: | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macOS-latest] | |
| dart-sdk: ${{ needs.analyze.outputs.* }} | |
| runs-on: ${{ matrix.os }} | |
| # analyze creates the cache, avoid downloading dependencies again here | |
| needs: analyze | |
| steps: | |
| - run: git config --global core.autocrlf false | |
| if: runner.os == 'Windows' | |
| - uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - uses: dart-lang/setup-dart@v1 | |
| with: | |
| sdk: ${{ matrix.dart-sdk }} | |
| - name: "Setup local pub cache folder" | |
| run: "echo PUB_CACHE=.dart_tool/pub-cache/ >> $GITHUB_ENV" | |
| shell: bash | |
| - uses: actions/cache/restore@v6 | |
| with: | |
| path: | | |
| ${{ env.PUB_CACHE }} | |
| pubspec.lock | |
| key: dart-deps-${{ matrix.dart-sdk }}-${{ hashFiles('pubspec.yaml') }} | |
| # Should be created by analyze run | |
| fail-on-cache-miss: true | |
| enableCrossOsArchive: true | |
| - name: "Get dependencies" | |
| run: dart pub get --offline | |
| - name: "Download 7za" | |
| run: dart run tool/download_7za.dart | |
| if: runner.os == 'Windows' | |
| - name: "Run tests" | |
| run: dart test |