Repository navigation
210 lines (191 loc) · 7.89 KB
/
Copy pathdevelop-build.yml
File metadata and controls
210 lines (191 loc) · 7.89 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Develop Build (manual)
on:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: develop-build-${{ github.ref }}
cancel-in-progress: true
env:
VT_API_KEY: ${{ secrets.VIRUSTOTAL_API_KEY }}
jobs:
build:
name: Build test APK
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up JDK 21
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
with:
distribution: temurin
java-version: "21"
- name: Validate Gradle wrapper & set up Gradle
uses: gradle/actions/setup-gradle@67621b124fd2e251c5e8a0e6e3b91318f2287669 # v6.3.0
with:
validate-wrappers: true
- name: Set up Android SDK
uses: android-actions/setup-android@40fd30fb8d7440372e1316f5d1809ec01dcd3699 # v4.0.1
with:
# The action's default is "tools platform-tools", but Google removed
# the deprecated `tools` package (setup-android issue #537), which made
# `sdkmanager tools` fail. platform-tools is all we need.
packages: 'platform-tools'
- name: Read versionName
id: ver
run: |
V=$(grep -oE 'versionName = "[^"]+"' app/build.gradle.kts | cut -d '"' -f2)
echo "version=$V" >> "$GITHUB_OUTPUT"
echo "Building $V from ${GITHUB_REF_NAME} @ ${GITHUB_SHA::7}"
# Signing is optional: with keystore secrets the APK is release-signed
# (installs as an update over a released build); otherwise a debug APK is
# produced, which is always installable but has a different signature.
- name: Restore keystore
env:
RELEASE_KEYSTORE_BASE64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }}
run: |
if [ -n "$RELEASE_KEYSTORE_BASE64" ]; then
echo "$RELEASE_KEYSTORE_BASE64" | base64 -d > release.keystore
else
echo "::notice::RELEASE_KEYSTORE_BASE64 not set - building debug APK"
fi
- name: Build APK
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
if [ -f release.keystore ] && [ -n "$KEYSTORE_PASSWORD" ] && [ -n "$KEY_PASSWORD" ]; then
task=assembleRelease
else
task=assembleDebug
fi
# See pr-build.yml: a dependency lookup that answers 404 on a cold
# cache should not fail the build on its first try.
for attempt in 1 2 3; do
if ./gradlew --no-daemon "$task"; then
exit 0
fi
echo "::warning::Gradle attempt ${attempt} failed; retrying"
rm -rf "${HOME}/.gradle/caches/modules-2"
sleep $((attempt * 10))
done
echo "::error::Gradle failed after 3 attempts"
exit 1
- name: Collect APK
id: apk
run: |
src=$(ls app/build/outputs/apk/release/*.apk 2>/dev/null | head -1)
kind=release
if [ -z "$src" ]; then
src=$(ls app/build/outputs/apk/debug/*.apk | head -1)
kind=debug
fi
refsafe=$(echo "${GITHUB_REF_NAME}" | tr '/' '_')
name="Messages-${{ steps.ver.outputs.version }}-${kind}-${refsafe}-${GITHUB_SHA::7}.apk"
cp "$src" "$name"
sha=$(sha256sum "$name" | cut -d' ' -f1)
echo "file=$name" >> "$GITHUB_OUTPUT"
echo "sha=$sha" >> "$GITHUB_OUTPUT"
{
echo "### Test build"
echo ""
echo "- Version: \`${{ steps.ver.outputs.version }}\` ($kind)"
echo "- Branch: \`${GITHUB_REF_NAME}\` @ \`${GITHUB_SHA::7}\`"
echo "- APK: \`$name\`"
echo "- SHA-256: \`$sha\`"
echo ""
echo "No release or tag was published. Download it from the Artifacts section below."
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload APK
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ steps.apk.outputs.file }}
path: ${{ steps.apk.outputs.file }}
if-no-files-found: error
retention-days: 30
- name: Check VirusTotal API key
run: |
if [ -z "$VT_API_KEY" ]; then
echo "::notice::VIRUSTOTAL_API_KEY not set - skipping VirusTotal scan"
fi
- name: Upload to VirusTotal
if: env.VT_API_KEY != ''
id: upload
run: |
APK="${{ steps.apk.outputs.file }}"
echo "Uploading $APK ($(stat -c%s "$APK") bytes)"
RESP=$(curl -sf -H "x-apikey: $VT_API_KEY" -F "file=@$APK" \
https://www.virustotal.com/api/v3/files)
ID=$(echo "$RESP" | python3 -c "import sys,json;print(json.load(sys.stdin)['data']['id'])")
echo "analysis_id=$ID" >> "$GITHUB_OUTPUT"
echo "Analysis id: $ID"
- name: Wait for analysis and extract stats
if: env.VT_API_KEY != ''
id: result
run: |
ANALY="${{ steps.upload.outputs.analysis_id }}"
mkdir -p /tmp/vt
for i in $(seq 1 60); do
if RESP=$(curl -sf -H "x-apikey: $VT_API_KEY" \
"https://www.virustotal.com/api/v3/analyses/$ANALY"); then
ST=$(echo "$RESP" | python3 -c \
"import sys,json;print(json.load(sys.stdin)['data']['attributes']['status'])")
if [ "$ST" = "completed" ]; then
echo "$RESP" > /tmp/vt/result.json
break
fi
fi
sleep 15
done
test -f /tmp/vt/result.json || { echo "::error::Analysis did not finish in time"; exit 1; }
python3 - "$GITHUB_OUTPUT" <<'PY'
import json,sys
d=json.load(open('/tmp/vt/result.json'))
attr=d['data']['attributes']
st=attr.get('stats',{})
fi=d.get('meta',{}).get('file_info',{})
total=sum(st.values())
with open(sys.argv[1],'a') as f:
for k in ('harmless','malicious','suspicious','undetected','timeout',
'confirmed-timeout','failure','type-unsupported'):
f.write(f"{k}={st.get(k,0)}\n")
f.write(f"total={total}\n")
f.write(f"sha256={fi.get('sha256','')}\n")
print(f"engines={total} malicious={st.get('malicious',0)} suspicious={st.get('suspicious',0)}")
PY
- name: Add VirusTotal report to job summary
if: env.VT_API_KEY != ''
env:
FILE: ${{ steps.apk.outputs.file }}
SHA: ${{ steps.result.outputs.sha256 }}
MAL: ${{ steps.result.outputs.malicious }}
SUS: ${{ steps.result.outputs.suspicious }}
GOOD: ${{ steps.result.outputs.harmless }}
UNDET: ${{ steps.result.outputs.undetected }}
TOTAL: ${{ steps.result.outputs.total }}
run: |
GUILINK="https://www.virustotal.com/gui/file/$SHA"
{
echo "### VirusTotal Scan Report"
echo ""
echo "Results for **$FILE** - [full report]($GUILINK)"
echo ""
echo "| Result | Count |"
echo "|---|---|"
echo "| Malicious | **$MAL** |"
echo "| Suspicious | $SUS |"
echo "| Harmless | $GOOD |"
echo "| Undetected | $UNDET |"
echo "| Total engines | $TOTAL |"
} >> "$GITHUB_STEP_SUMMARY"
- name: Flag malware detections
if: env.VT_API_KEY != '' && steps.result.outputs.malicious != '' && steps.result.outputs.malicious != '0'
run: |
echo "::error::VirusTotal reported ${{ steps.result.outputs.malicious }} malicious detection(s) for this APK - investigate before sharing"
exit 1
- name: Remove keystore
if: always()
run: rm -f release.keystore