-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (138 loc) · 5.84 KB
/
Copy pathdart.yml
File metadata and controls
149 lines (138 loc) · 5.84 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: "Run dart specific github actions"
on:
workflow_call:
inputs:
env_file:
description: "Path to an .env file to read flutter_version and/or dart_version from."
type: string
required: false
directory:
description: "The subdirectory for the dart project, defaults to the current directory."
type: string
required: false
default: ""
ignore_formatting:
description: "A subdirectory which is ignored in the format check by formatting it before."
type: string
required: false
default: ""
secrets:
ssh_key:
description: "SSH key to pull private dependencies"
required: false
famedly_github_token:
description: "GitHub token to pull private dependencies over HTTPS"
required: false
jobs:
dart_analyzer:
runs-on: ubuntu-latest
env:
env_file: ${{ inputs.env_file }}
steps:
- uses: actions/checkout@v4
- name: Read env file
if: env.env_file != ''
run: cat ${{ env.env_file }} >> $GITHUB_ENV
- uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46
if: env.dart_version != ''
with:
sdk: ${{ env.dart_version }}
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa
with:
flutter-version: ${{ env.flutter_version }}
cache: true
- uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-${{ hashFiles('**/pubspec.lock') }}
- name: Enable pulling private dependencies
uses: famedly/frontend-ci-templates/.github/actions/dart-prepare@main
with:
ssh_key: "${{ secrets.ssh_key }}"
famedly_github_token: "${{ secrets.famedly_github_token }}"
container_mode: "false"
- name: Fetch dependencies
id: deps
working-directory: ${{ inputs.directory }}
run: |
flutter pub get
- name: Check if pubspec.lock is up to date
run: git check-ignore -q pubspec.lock || git diff --exit-code pubspec.lock
working-directory: ${{ inputs.directory }}
- run: dart format ${{ inputs.ignore_formatting }}
if: inputs.ignore_formatting != ''
- name: Check formatting
working-directory: ${{ inputs.directory }}
run: |
dart format lib/ --set-exit-if-changed || (echo '```diff' >> "$GITHUB_STEP_SUMMARY"; git diff >> "$GITHUB_STEP_SUMMARY"; echo '```' >> "$GITHUB_STEP_SUMMARY"; exit 1)
- name: Run analyzer
working-directory: ${{ inputs.directory }}
if: success() || (failure() && steps.deps.conclusion == 'success')
run: |
SCRIPT=$(cat << 'EOL'
import json,sys,os
obj = json.load(sys.stdin)
diagnostics = obj["diagnostics"]
if diagnostics:
print('|severity|file|problem|suggestion|documentation|')
print('|:--|:--|:--|:--|:--|')
else:
exit(0)
sha = os.environ["GITHUB_SHA"]
server = os.environ["GITHUB_SERVER_URL"]
repo = os.environ["GITHUB_REPOSITORY"]
workspace = os.environ["GITHUB_WORKSPACE"]
for d in diagnostics:
l = d["location"]
file =l["file"].removeprefix(workspace + "/")
start = str(l["range"]["start"]["line"])
end = str(l["range"]["end"]["line"])
location = f'[{file}:{start}]({server}/{repo}/blob/{sha}/{file}#L{start}-L{end})'
print("", d["severity"], location, d.get("correctionMessage", "").replace("|", "\\|"), d.get("correctionMessage", "").replace("|", "\\|"), f'[{d["code"]}]({d.get("documentation", "")})', "", sep="| ")
exit(1)
EOL
)
dart analyze --format=json | python3 -c "$SCRIPT" | tee -a "$GITHUB_STEP_SUMMARY"
test ${PIPESTATUS[0]} -eq 0 -a ${PIPESTATUS[1]} -eq 0 -a ${PIPESTATUS[2]} -eq 0
- name: Check for commented-out Dart code with semicolons
run: |
if grep -R --include="*.dart" -nE '^[[:space:]]*//[^/<].*;[[:space:]]*$' lib/; then
echo ""
echo "❌ Found commented-out Dart code ending with semicolon."
exit 1
fi
working-directory: ${{ inputs.directory }}
- name: Search unused dependencies
run: |
dart pub global activate dependency_validator
dart pub global run dependency_validator
working-directory: ${{ inputs.directory }}
- name: Check if dart_code_linter is present
id: check_linter
continue-on-error: true
working-directory: ${{ inputs.directory }}
run: |
if grep -q 'dart_code_linter:' pubspec.yaml; then
echo "has_linter=true" >> $GITHUB_OUTPUT
else
echo "has_linter=false" >> $GITHUB_OUTPUT
echo "::warning::dart_code_linter not found in pubspec.yaml, skipping linter checks"
exit 1
fi
- name: Dart Code linter
if: steps.check_linter.outputs.has_linter == 'true'
run: dart run dart_code_linter:metrics analyze lib --reporter=github
working-directory: ${{ inputs.directory }}
- name: Check for unused files
if: steps.check_linter.outputs.has_linter == 'true'
run: dart run dart_code_linter:metrics check-unused-files lib
working-directory: ${{ inputs.directory }}
- name: Check for unused code
if: steps.check_linter.outputs.has_linter == 'true'
run: dart run dart_code_linter:metrics check-unused-code lib --exclude="{**/generated/**.dart,**.g.dart,**.freezed.dart}"
working-directory: ${{ inputs.directory }}
- name: Check for unused translations
run: |
dart pub global activate sweeper
dart pub global run sweeper check
working-directory: ${{ inputs.directory }}