forked from fujidaiti/smooth_sheets
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (107 loc) · 3.8 KB
/
code_check.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Code Check
on:
push:
branches: main
pull_request:
env:
FLUTTER_TEST_REPORT: ${{github.workspace}}/flutter-test-report.json
PATTERN_CHECKER: ${{github.workspace}}/scripts/pattern_checker.sh
jobs:
setup:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
flutter-file-changed: ${{ steps.filter.outputs.flutter-file-changed }}
flutter-lower-bound: ${{ steps.flutter-version-constraint.outputs.lower-bound }}
flutter-upper-bound: ${{ steps.flutter-version-constraint.outputs.upper-bound }}
steps:
- uses: actions/checkout@v4
- name: Filter changed files
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
flutter-file-changed:
- '**.dart'
- 'pubspec.yaml'
- 'pubspec.lock'
- name: Get Flutter SDK version constraint
id: flutter-version-constraint
# Extract the lower bound from pubspec.yaml and the upper bound from .fvmrc
run: |
sdk_constraint=$(cat pubspec.yaml | yq .environment.flutter)
lower_bound=$(echo "$sdk_constraint" | grep -oP '(?<=\>=)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
upper_bound=$(cat .fvmrc | jq -r .flutter)
echo "lower-bound=$lower_bound" >> "$GITHUB_OUTPUT"
echo "upper-bound=$upper_bound" >> "$GITHUB_OUTPUT"
- name: Print output values
run: |
echo "flutter-file-changed=${{ steps.filter.outputs.flutter-file-changed }}"
echo "flutter-lower-bound=${{ steps.flutter-version-constraint.outputs.lower-bound }}"
echo "flutter-upper-bound=${{ steps.flutter-version-constraint.outputs.upper-bound }}"
analysis:
needs: setup
if: ${{ needs.setup.outputs.flutter-file-changed == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.flutter-lower-bound }}
- ${{ needs.setup.outputs.flutter-upper-bound }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
version: ${{ matrix.flutter-version }}
- name: Format
run: dart format . -o none --set-exit-if-changed
- name: Analyze
run: dart analyze
- name: Disallowed patterns check
run: bash ${{ env.PATTERN_CHECKER }} "*.dart" "--" "debugPrint"
testing:
needs: setup
if: ${{ needs.setup.outputs.flutter-file-changed == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
checks: write
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.flutter-lower-bound }}
- ${{ needs.setup.outputs.flutter-upper-bound }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flutter
uses: ./.github/actions/setup_flutter
with:
version: ${{ matrix.flutter-version }}
- name: Run unit tests
run: flutter test --file-reporter="json:${{ env.FLUTTER_TEST_REPORT }}"
- name: Write test report
uses: dorny/test-reporter@v1
# PRs from forks have no write permissions.
if: github.event.pull_request.head.repo.fork == false && (success() || failure())
with:
name: Test Report (with Flutter ${{ matrix.flutter-version }})
path: ${{ env.FLUTTER_TEST_REPORT }}
reporter: flutter-json
# Final results (Used for status checks)
code-check:
if: ${{ always() }}
runs-on: ubuntu-latest
needs: [analysis, testing]
steps:
# Fails if any of the previous jobs failed.
- run: exit 1
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
}}