Skip to content

Commit af047d4

Browse files
committed
Add a GitHub Workflow to run DCM checks weekly
1 parent 90487c0 commit af047d4

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Weekly DCM Checks
2+
3+
on:
4+
schedule:
5+
- cron: '0 8 * * 1' # Every Monday at 8am
6+
workflow_dispatch:
7+
8+
jobs:
9+
flutter-prep:
10+
uses: ./.github/workflows/flutter-prep.yaml
11+
12+
dcm_check:
13+
needs: flutter-prep
14+
runs-on: ubuntu-latest
15+
permissions:
16+
issues: write
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Load Cached Flutter SDK
22+
uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7
23+
with:
24+
path: |
25+
./tool/flutter-sdk
26+
key: flutter-sdk-${{ runner.os }}-${{ needs.flutter-prep.outputs.latest_flutter_candidate }}
27+
28+
- name: Setup PATHs
29+
run: |
30+
echo "$(pwd)/tool/flutter-sdk/bin" >> $GITHUB_PATH
31+
echo "$(pwd)/tool/flutter-sdk/bin/cache/dart-sdk/bin" >> $GITHUB_PATH
32+
33+
- name: Install DCM
34+
run: |
35+
sudo apt-get update
36+
wget -qO- https://dcm.dev/pgp-key.public | sudo gpg --dearmor -o /usr/share/keyrings/dcm.gpg
37+
echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
38+
sudo apt-get update
39+
sudo apt-get install dcm=1.38.1-1
40+
sudo chmod +x /usr/bin/dcm
41+
echo "$(dcm --version)"
42+
43+
- name: Install dependencies
44+
run: |
45+
dart pub get
46+
cd packages/devtools_app && flutter pub get
47+
cd ../devtools_app_shared && flutter pub get
48+
cd ../devtools_extensions && flutter pub get
49+
cd ../devtools_shared && dart pub get
50+
cd ../devtools_test && flutter pub get
51+
52+
- name: Run DCM unused checks
53+
run: |
54+
echo "Running check-unused-code..."
55+
dcm check-unused-code -c packages/devtools_app/lib/src/framework/scaffold/status_line.dart > raw_unused_code.txt || echo "found_code=true" >> $GITHUB_ENV
56+
grep '^• ' raw_unused_code.txt | sed 's/^• /- [ ] /' > unused_code.txt || true
57+
58+
echo "Running check-unused-files..."
59+
dcm check-unused-files -c packages/devtools_app/lib/src/framework/scaffold/status_line.dart > raw_unused_files.txt || echo "found_files=true" >> $GITHUB_ENV
60+
grep '^• ' raw_unused_files.txt | sed 's/^• /- [ ] /' > unused_files.txt || true
61+
62+
- name: Create Issue if findings
63+
if: env.found_code == 'true' || env.found_files == 'true'
64+
env:
65+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
run: |
67+
echo "The weekly DCM checks found unused code or files. Please review the findings below." > issue_body.md
68+
echo "" >> issue_body.md
69+
echo "### How to run locally" >> issue_body.md
70+
echo "To run these checks locally, you can use the following commands from the root of the repository:" >> issue_body.md
71+
echo "\`\`\`sh" >> issue_body.md
72+
echo "dcm check-unused-code packages/devtools_app/" >> issue_body.md
73+
echo "dcm check-unused-files packages/devtools_app/" >> issue_body.md
74+
echo "\`\`\`" >> issue_body.md
75+
echo "" >> issue_body.md
76+
77+
if [ "$found_code" == "true" ]; then
78+
echo "### Unused Code" >> issue_body.md
79+
cat unused_code.txt >> issue_body.md
80+
fi
81+
82+
if [ "$found_files" == "true" ]; then
83+
echo "### Unused Files" >> issue_body.md
84+
cat unused_files.txt >> issue_body.md
85+
fi
86+
87+
gh issue create \
88+
--title "Weekly DCM Checks: Unused code or files found" \
89+
--body-file issue_body.md \
90+
--label "cleanup"

0 commit comments

Comments
 (0)