-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (160 loc) · 6.58 KB
/
Copy pathlint.yml
File metadata and controls
182 lines (160 loc) · 6.58 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Lint Check on Push
# branches: [main]
# → mainブランチ向けのPRのみで発火します
# types: [opened, synchronize, reopened, ready_for_review]
# → PRが作成された時・更新された時・下書きからreadyにした時だけ実行
# closed や merged などは含まれません
# Draft PRでは自動で実行されません
# Draft中はsynchronizeやopenedイベントでもGitHub側でWorkflow実行がスキップされます
# ただし「Draft → Ready」に切り替えた瞬間のみ ready_for_review で実行されます
on:
pull_request:
types: [opened, reopened, synchronize, requested_review, ready_for_review]
branches:
- main
# 同じブランチに新しいコミットが追加された場合、前のActionsの実行をキャンセルする
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
name: Lint Changed Modules
env:
NDK_VERSION: 27.3.13750724
ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
ANDROID_HOME: /usr/local/lib/android/sdk
GPR_USER: ${{ secrets.GPR_USER }}
GPR_TOKEN: ${{ secrets.GPR_TOKEN }}
steps:
- name: Check variables
run: |
if [ -z "$GPR_USER" ] || [ -z "$GPR_TOKEN" ]; then
echo "GPR credentials are not available"
exit 1
fi
- name: Checkout
uses: actions/checkout@v6
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
- name: Write gradle.properties
run: |
{
echo "android.ndkVersion=${NDK_VERSION}"
} >> gradle.properties
- name: Set NDK environment
run: |
echo "ANDROID_NDK_ROOT=/usr/local/lib/android/sdk/ndk/${NDK_VERSION}" >> $GITHUB_ENV
echo "NDK_VERSION=${NDK_VERSION}" >> $GITHUB_ENV
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 17
# - name: Install Android NDK $NDK_VERSION
# uses: android-actions/setup-android@v3
# with:
# packages: "build-tools;36.0.0 ndk;${{ env.NDK_VERSION }} platform-tools platforms;android-35"
- name: Read module list from projects.properties
id: define
run: |
modules=$(grep '^modules=' projects.properties | cut -d= -f2 | tr ',' ' ')
echo "modules=$modules" >> $GITHUB_OUTPUT
# here_sdk_name=$(grep '^hereSdkAarName=' gradle.properties | cut -d= -f2 | tr -d '\r')
# echo "here_sdk_artifact=$here_sdk_name" >> $GITHUB_OUTPUT
- name: Restore hash cache
uses: actions/cache/restore@v5
with:
key: lint-hash-cache-${{ github.base_ref || 'main' }}
path: .lint-hash-cache/
restore-keys: |
lint-hash-cache-
- name: Detect changed modules by hashing
id: detect
env:
MODULES: ${{ steps.define.outputs.modules }}
run: |
changed_modules=""
mkdir -p .lint-hash-cache
for module in $MODULES; do
if [ "$module" != "mapconductor-bom" ]; then
# src配下のKotlinとXMLファイルのハッシュを計算
if [ -d "$module/src" ]; then
hash=$(find "$module/src" -type f -name "*.kt" -print0 2>/dev/null | \
sort -z | xargs -0 sha256sum 2>/dev/null | sha256sum | cut -d ' ' -f1)
else
hash="empty"
fi
CACHE_KEY_FILE=".lint-hash-cache/${module//\//-}.txt"
# ハッシュベースの比較
if [ -f "$CACHE_KEY_FILE" ]; then
old_hash=$(cat "$CACHE_KEY_FILE")
if [ "$hash" == "$old_hash" ]; then
echo "Module $module unchanged (hash match)"
continue
else
echo "Module $module changed (hash mismatch: $old_hash -> $hash)"
fi
else
echo "Module $module changed (no previous hash)"
fi
changed_modules="${changed_modules:+$changed_modules }$module"
echo "$hash" > "$CACHE_KEY_FILE"
fi
done
# 余分な空白や改行を除去
changed_modules=$(echo "$changed_modules" | xargs)
echo "Changed modules: $changed_modules"
echo "changed_modules=$changed_modules" >> $GITHUB_OUTPUT
- name: Fetch HERE SDK mock artifact
if: steps.detect.outputs.changed_modules != ''
run: |
mkdir -p libs
target_path="libs/heresdk-explore-mock-4.23.2.0.210004.jar"
echo "Downloading HERE SDK mock artifact to $target_path"
curl --fail --show-error --silent --location \
-u "$GPR_USER:$GPR_TOKEN" \
-o "$target_path" \
"https://raw.githubusercontent.com/MapConductor/here-sdk-mocks/main/heresdk-explore-mock-4.23.2.0.210004.jar"
if [ ! -s "$target_path" ]; then
echo "Failed to download HERE SDK mock artifact"
exit 1
fi
- name: Run ktlintCheck
if: steps.detect.outputs.changed_modules != ''
run: |
echo "Running ktlintCheck for modules: ${{ steps.detect.outputs.changed_modules }}"
for module in ${{ steps.detect.outputs.changed_modules }}; do
echo "Running ktlintCheck for $module"
if ./gradlew ":$module:ktlintCheck"; then
echo "✅ ktlintCheck passed for $module"
else
echo "❌ ktlintCheck failed for $module"
exit 1
fi
done
- name: Run Android Lint
if: steps.detect.outputs.changed_modules != ''
run: |
echo "Running Android Lint for modules: ${{ steps.detect.outputs.changed_modules }}"
for module in ${{ steps.detect.outputs.changed_modules }}; do
echo "Running lint for $module"
if ./gradlew ":$module:lint"; then
echo "✅ Android Lint passed for $module"
else
echo "❌ Android Lint failed for $module"
exit 1
fi
done
- name: Save hash cache
if: success()
uses: actions/cache/save@v5
with:
key: lint-hash-cache-${{ github.base_ref || 'main' }}-${{ github.run_id }}
path: .lint-hash-cache/
- name: No modules to lint
if: steps.detect.outputs.changed_modules == ''
run: |
echo "🎉 No modules have changed - skipping lint checks"