From e4b068015894953821192b9d4ba92c196b298a9f Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sun, 12 Jul 2026 00:28:24 +0200 Subject: [PATCH] fix(ci): enforce automation checks --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 22 +++++----------------- .github/workflows/release.yml | 2 +- .github/workflows/update-packages.yml | 2 +- CONTRIBUTING.md | 7 +++++-- scripts/ci_checks.sh | 22 +++++++--------------- scripts/codegen.sh | 25 ++++++++++++++++++++++++- 7 files changed, 45 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 417e7080..991259e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -470,7 +470,7 @@ jobs: key: ${{ runner.os }}-${{ runner.arch }}-pub-v2-${{ hashFiles('pubspec.yaml', 'pubspec.lock') }} - name: Install dependencies - run: flutter pub get --no-example + run: flutter pub get --enforce-lockfile --no-example - name: Install patched Flutter engine (DComp) shell: pwsh @@ -768,7 +768,7 @@ jobs: run: sudo gem install fpm - name: Install dependencies - run: flutter pub get --no-example + run: flutter pub get --enforce-lockfile --no-example - name: Build Linux arm64 run: flutter build linux --release --dart-define=ENABLE_UPDATE_CHECK=true ${{ env.SENTRY_DART_DEFINE }} ${{ env.GIT_COMMIT_DART_DEFINE }} ${{ env.SENTRY_ENV_DART_DEFINE }} --dart-define=SENTRY_DIST=github-linux-arm64 ${{ env.DONATIONS_DART_DEFINE }} --split-debug-info=debug-info/linux-arm64 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d993a216..eb6faed8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,26 +40,14 @@ jobs: flutter pub get - name: Verify generated files committed - run: | - scripts/codegen.sh - if ! git diff --exit-code lib/; then - echo "::error::Generated files (.g.dart / .freezed.dart) are out of date." - echo "Run 'scripts/codegen.sh' and commit the result." - exit 1 - fi + run: scripts/codegen.sh --check - name: Verify formatting run: | - # Find all Dart files excluding generated files - find lib $([ -d test ] && echo test) -name "*.dart" ! -name "*.g.dart" ! -name "*.freezed.dart" -type f 2>/dev/null | while IFS= read -r file; do - files_found=true - break - done - if [ "$files_found" != "true" ]; then - echo "No Dart files found to format" - exit 0 - fi - find lib $([ -d test ] && echo test) -name "*.dart" ! -name "*.g.dart" ! -name "*.freezed.dart" -type f 2>/dev/null -print0 | xargs -0 dart format --output=none --set-exit-if-changed + paths=(lib) + [ ! -d test ] || paths+=(test) + find "${paths[@]}" -name "*.dart" ! -name "*.g.dart" ! -name "*.freezed.dart" -type f -print0 | + xargs -0 -r dart format --output=none --set-exit-if-changed - name: Analyze code run: | # Run flutter analyze diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6e576967..d97de061 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: - name: Trigger build workflow run: | - curl -L \ + curl --fail-with-body -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ diff --git a/.github/workflows/update-packages.yml b/.github/workflows/update-packages.yml index 14495834..fb5cde50 100644 --- a/.github/workflows/update-packages.yml +++ b/.github/workflows/update-packages.yml @@ -20,7 +20,7 @@ jobs: id: release run: | VERSION="${{ github.event.release.tag_name || github.ref_name }}" - curl -L -o plezy-macos.dmg \ + curl --fail-with-body -L -o plezy-macos.dmg \ "https://github.com/edde746/plezy/releases/download/$VERSION/plezy-macos.dmg" SHA256=$(shasum -a 256 plezy-macos.dmg | cut -d' ' -f1) echo "version=$VERSION" >> $GITHUB_OUTPUT diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 93cdc540..19dbabd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ 1. Fork and clone the repository 2. Run `flutter pub get` to install dependencies -3. Run `dart run build_runner build` to generate code +3. Run `scripts/codegen.sh` to generate translations and Dart model code 4. Start developing! ## Development @@ -30,7 +30,10 @@ The project includes automated CI checks that run on all pull requests: - Run locally: `flutter analyze` - Note: CI excludes generated files from analysis (configured in `analysis_options.yaml`) -3. **Tests**: Runs unit and widget tests (when available) +3. **Generated Code**: Ensures generated translations and model files are current + - Run locally: `scripts/codegen.sh --check` + +4. **Tests**: Runs unit and widget tests (when available) - Run locally: `flutter test` All these checks must pass before your changes can be merged. diff --git a/scripts/ci_checks.sh b/scripts/ci_checks.sh index 6b487a31..6390981c 100755 --- a/scripts/ci_checks.sh +++ b/scripts/ci_checks.sh @@ -59,25 +59,17 @@ else rm -f "$out" fi -# 2. Codegen freshness (build_runner outputs newer than their sources) +# 2. Codegen freshness section "codegen freshness" -stale=() -while IFS= read -r -d '' src; do - for gen in "${src%.dart}.g.dart" "${src%.dart}.freezed.dart"; do - if [ -f "$gen" ] && [ "$src" -nt "$gen" ]; then - stale+=("${src#./}") - break - fi - done -done < <(find lib -name "*.dart" ! -name "*.g.dart" ! -name "*.freezed.dart" -type f -print0 2>/dev/null) -if [ ${#stale[@]} -eq 0 ]; then - ok "no stale generated files" +out="$(mktemp)" +if scripts/codegen.sh --check >"$out" 2>&1; then + ok "generated files are current" else - fail "${#stale[@]} dart source(s) newer than their generated .g/.freezed:" - printf ' %s\n' "${stale[@]}" - echo " Run: scripts/codegen.sh" + fail "generated files are stale" + sed 's/^/ /' "$out" FAILED=1 fi +rm -f "$out" # 3. Native formatting section "native format" diff --git a/scripts/codegen.sh b/scripts/codegen.sh index 2fa24b21..86c84f87 100755 --- a/scripts/codegen.sh +++ b/scripts/codegen.sh @@ -1,5 +1,28 @@ #!/usr/bin/env bash set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." + +check=false +if [[ "${1:-}" == "--check" ]]; then + check=true + shift +fi + dart run slang -exec dart run build_runner build --delete-conflicting-outputs "$@" +dart run build_runner build --delete-conflicting-outputs "$@" + +if $check; then + generated_changes="$({ + git diff --name-only -- lib + git ls-files --others --exclude-standard -- \ + ':(glob)lib/**/*.g.dart' \ + ':(glob)lib/**/*.freezed.dart' + } | grep -E '\.(g|freezed)\.dart$' || true)" + + if [[ -n "$generated_changes" ]]; then + echo "Generated files are out of date:" >&2 + printf ' %s\n' "$generated_changes" >&2 + echo "Run 'scripts/codegen.sh' and commit the result." >&2 + exit 1 + fi +fi