1name: '📱 Application'
 2
 3on:
 4  push:
 5    branches:
 6      - 'main'
 7    paths:
 8      - "app/**"
 9      - "health_data_store/**"
10      - "extendend-testing.yml"
11  workflow_dispatch:
12
13jobs:
14  run-tests:
15    runs-on: ubuntu-latest
16    permissions:
17      contents: write
18      pull-requests: write
19    steps:
20      - name: Checkout code
21        uses: actions/checkout@v4
22        with:
23          # ensures there are no unexpected directories needed
24          sparse-checkout: |
25            app
26            health_data_store
27      - name: Cache generated health data store
28        id: cache-generated
29        uses: actions/cache@v4
30        with:
31          path: health_data_store/lib
32          key: builder-${{ hashFiles('health_data_store/pubspec.yaml', 'health_data_store/lib/*', 'health_data_store/lib/**/*dart') }}
33      - name: Setup dart
34        if: steps.cache-generated.outputs.cache-hit != 'true'
35        uses: dart-lang/setup-dart@v1
36        with:
37          sdk: stable
38      - name: Generate code
39        if: steps.cache-generated.outputs.cache-hit != 'true'
40        run: dart run build_runner build
41        working-directory: health_data_store
42      - name: Extract Flutter version
43        id: get_version
44        run: |
45          # This is the same function f-droid uses to ensure their builds keep succeeding:
46          # https://gitlab.com/fdroid/fdroiddata/-/blob/master/metadata/com.derdilla.bloodPressureApp.yml
47          VERSION=$(sed -n -E "s/.*flutter:\s*'(.*)'/\1/p" app/pubspec.yaml)
48          if [ -z "$VERSION" ]; then
49            echo "Error: Could not find a Flutter version specified in app/pubspec.yaml."
50            exit 1
51          fi
52          echo "version=$VERSION" >> $GITHUB_OUTPUT
53      - name: Setup Flutter
54        uses: subosito/flutter-action@v2
55        with:
56          flutter-version: ${{ steps.get_version.outputs.version }}
57          cache: true
58      - name: Disable analytics
59        run:
60          flutter config --no-analytics --suppress-analytics
61      - name: Update app dependencies
62        run: flutter pub get
63        working-directory: app
64      - name: Generate app mock code # no efficient caching possible
65        run: flutter pub run build_runner build
66        working-directory: app
67      - name: Run tests
68        run: flutter test
69        working-directory: app
70      - name: Run golden tests
71        run: flutter test --tags gold --run-skipped
72        working-directory: app