Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Make mobile packages linter fully self-discovering with matrix strategy

Neeraj Gupta9224e424e4eb
diff --git a/.github/scripts/get-affected-packages.sh b/.github/scripts/get-affected-packages.sh
index 269734aa77..f8c64ef596 100755
--- a/.github/scripts/get-affected-packages.sh
+++ b/.github/scripts/get-affected-packages.sh
@@ -10,7 +10,7 @@
#
# Output (JSON to stdout):
# {
-# "packages": "pkg1 pkg2 pkg3",
+# "packages": ["pkg1", "pkg2", "pkg3"],
# "lint_photos": "true/false",
# "lint_auth": "true/false",
# "lint_locker": "true/false",
@@ -165,10 +165,23 @@ main() {
# If linting all, return all packages
if [ "$lint_all" = "true" ]; then
- local all_pkgs=$(find "$PACKAGES_DIR" -maxdepth 1 -type d -not -name "packages" -not -name "rust" -exec basename {} \; | sort | tr '\n' ' ')
+ local all_pkgs=$(find "$PACKAGES_DIR" -maxdepth 1 -type d -not -name "packages" -not -name "rust" -exec basename {} \; | sort)
+
+ # Convert to JSON array
+ local json_array="["
+ local first=true
+ for pkg in $all_pkgs; do
+ if [ "$first" = true ]; then
+ json_array="$json_array\"$pkg\""
+ first=false
+ else
+ json_array="$json_array, \"$pkg\""
+ fi
+ done
+ json_array="$json_array]"
echo "{"
- echo " \"packages\": \"$all_pkgs\","
+ echo " \"packages\": $json_array,"
echo " \"lint_photos\": \"true\","
echo " \"lint_auth\": \"true\","
echo " \"lint_locker\": \"true\","
@@ -193,7 +206,7 @@ main() {
# If no packages changed, nothing to lint
if [ -z "$(echo $changed_pkgs | tr -d ' ')" ]; then
echo "{"
- echo " \"packages\": \"\","
+ echo " \"packages\": [],"
echo " \"lint_photos\": \"false\","
echo " \"lint_auth\": \"false\","
echo " \"lint_locker\": \"false\","
@@ -213,9 +226,22 @@ main() {
local lint_auth=$(check_app_affected "auth" "$affected_pkgs")
local lint_locker=$(check_app_affected "locker" "$affected_pkgs")
+ # Convert affected_pkgs to JSON array
+ local json_array="["
+ local first=true
+ for pkg in $affected_pkgs; do
+ if [ "$first" = true ]; then
+ json_array="$json_array\"$pkg\""
+ first=false
+ else
+ json_array="$json_array, \"$pkg\""
+ fi
+ done
+ json_array="$json_array]"
+
# Output JSON
echo "{"
- echo " \"packages\": \"$affected_pkgs\","
+ echo " \"packages\": $json_array,"
echo " \"lint_photos\": \"$lint_photos\","
echo " \"lint_auth\": \"$lint_auth\","
echo " \"lint_locker\": \"$lint_locker\","
diff --git a/.github/workflows/mobile-packages-lint.yml b/.github/workflows/mobile-packages-lint.yml
index 1fd81026ab..8d19b18b4c 100644
--- a/.github/workflows/mobile-packages-lint.yml
+++ b/.github/workflows/mobile-packages-lint.yml
@@ -89,7 +89,11 @@ jobs:
needs: detect-changes
runs-on: ubuntu-latest
# Skip if no packages need linting
- if: needs.detect-changes.outputs.packages != '' || needs.detect-changes.outputs.lint_all == 'true'
+ if: needs.detect-changes.outputs.lint_all == 'true' || toJson(fromJson(needs.detect-changes.outputs.packages)) != '[]'
+ strategy:
+ fail-fast: false
+ matrix:
+ package: ${{ fromJson(needs.detect-changes.outputs.packages) }}
steps:
- name: Checkout code and submodules
uses: actions/checkout@v4
@@ -120,161 +124,117 @@ jobs:
working-directory: mobile/packages/rust
- name: Generate strings localizations
+ if: matrix.package == 'strings'
run: flutter gen-l10n
working-directory: mobile/packages/strings
- # Lint all packages (conditionally based on what changed)
- - name: Lint package - accounts
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'accounts')
+ # Lint the package from the matrix
+ - name: Lint package - ${{ matrix.package }}
run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/accounts
+ working-directory: mobile/packages/${{ matrix.package }}
- - name: Lint package - base
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'base')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/base
-
- - name: Lint package - configuration
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'configuration')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/configuration
-
- - name: Lint package - dir_utils
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'dir_utils')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/dir_utils
-
- - name: Lint package - ente_crypto_api
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'ente_crypto_api')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/ente_crypto_api
-
- - name: Lint package - ente_crypto_dart_adapter
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'ente_crypto_dart_adapter')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/ente_crypto_dart_adapter
-
- - name: Lint package - ente_icons
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'ente_icons')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/ente_icons
-
- - name: Lint package - ente_pure_utils
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'ente_pure_utils')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/ente_pure_utils
-
- - name: Lint package - events
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'events')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/events
-
- - name: Lint package - legacy
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'legacy')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/legacy
-
- - name: Lint package - lock_screen
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'lock_screen')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/lock_screen
-
- - name: Lint package - log_viewer
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'log_viewer')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/log_viewer
-
- - name: Lint package - logging
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'logging')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/logging
-
- - name: Lint package - native_video_editor
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'native_video_editor')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/native_video_editor
-
- - name: Lint package - network
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'network')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/network
-
- - name: Lint package - qr
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'qr')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/qr
-
- - name: Lint package - sharing
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'sharing')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/sharing
+ rust-lint:
+ needs: detect-changes
+ runs-on: ubuntu-latest
+ if: needs.detect-changes.outputs.rust_changed == 'true'
+ steps:
+ - name: Checkout code and submodules
+ uses: actions/checkout@v4
+ with:
+ submodules: recursive
- - name: Lint package - strings
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'strings')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/strings
+ - name: Cache Rust dependencies
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ mobile/packages/rust/rust/target
+ key: ${{ runner.os }}-cargo-packages-${{ hashFiles('mobile/packages/**/Cargo.lock') }}
- - name: Lint package - ui
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'ui')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/ui
+ - name: Install Flutter Rust Bridge
+ run: cargo install flutter_rust_bridge_codegen
- - name: Lint package - utils
- if: needs.detect-changes.outputs.lint_all == 'true' || contains(needs.detect-changes.outputs.packages, 'utils')
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/packages/utils
+ - name: Generate Rust bindings (Core)
+ run: flutter_rust_bridge_codegen generate
+ working-directory: mobile/packages/rust
- name: Check formatting (ente_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/packages/rust/rust
run: cargo fmt -- src/frb_generated.rs && cargo fmt --check
- name: Run clippy (ente_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/packages/rust/rust
run: cargo clippy --all-targets --all-features
- name: Build (ente_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/packages/rust/rust
run: cargo build
- name: Test (ente_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/packages/rust/rust
run: cargo test
- # Lint all three apps to ensure package changes don't break them
- name: Generate Rust bindings (photos app)
- if: needs.detect-changes.outputs.lint_photos == 'true'
run: flutter_rust_bridge_codegen generate
working-directory: mobile/apps/photos
- - name: Lint app - photos
- if: needs.detect-changes.outputs.lint_photos == 'true'
- run: flutter pub get && flutter analyze --no-fatal-infos
- working-directory: mobile/apps/photos
-
- name: Check formatting (ente_photos_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/apps/photos/rust
run: cargo fmt -- src/frb_generated.rs && cargo fmt --check
- name: Run clippy (ente_photos_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/apps/photos/rust
run: cargo clippy --all-targets --all-features
- name: Build (ente_photos_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/apps/photos/rust
run: cargo build
- name: Test (ente_photos_rust)
- if: needs.detect-changes.outputs.rust_changed == 'true'
working-directory: mobile/apps/photos/rust
run: cargo test
+ apps-lint:
+ needs: detect-changes
+ runs-on: ubuntu-latest
+ if: needs.detect-changes.outputs.lint_photos == 'true' || needs.detect-changes.outputs.lint_auth == 'true' || needs.detect-changes.outputs.lint_locker == 'true'
+ steps:
+ - name: Checkout code and submodules
+ uses: actions/checkout@v4
+ with:
+ submodules: recursive
+
+ - name: Install Flutter ${{ env.FLUTTER_VERSION }}
+ uses: subosito/flutter-action@v2
+ with:
+ channel: "stable"
+ flutter-version: ${{ env.FLUTTER_VERSION }}
+ cache: true
+
+ - name: Cache Rust dependencies
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ mobile/packages/rust/rust/target
+ key: ${{ runner.os }}-cargo-packages-${{ hashFiles('mobile/packages/**/Cargo.lock') }}
+
+ - name: Install Flutter Rust Bridge
+ if: needs.detect-changes.outputs.lint_photos == 'true'
+ run: cargo install flutter_rust_bridge_codegen
+
+ - name: Generate Rust bindings (photos app)
+ if: needs.detect-changes.outputs.lint_photos == 'true'
+ run: flutter_rust_bridge_codegen generate
+ working-directory: mobile/apps/photos
+
+ - name: Lint app - photos
+ if: needs.detect-changes.outputs.lint_photos == 'true'
+ run: flutter pub get && flutter analyze --no-fatal-infos
+ working-directory: mobile/apps/photos
+
- name: Lint app - auth
if: needs.detect-changes.outputs.lint_auth == 'true'
run: flutter pub get && flutter analyze --no-fatal-infos