-
Notifications
You must be signed in to change notification settings - Fork 94
210 lines (177 loc) · 7.05 KB
/
Copy pathbuild.yml
File metadata and controls
210 lines (177 loc) · 7.05 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: Build FolkPatch
on:
push:
branches: [ main, develop ]
paths: [ 'app/**', 'fpd/**', '.github/workflows/build.yml' ]
pull_request:
branches: [ main, develop ]
paths: [ 'app/**', 'fpd/**', '.github/workflows/build.yml' ]
workflow_dispatch:
inputs:
build_type:
description: 'Build type'
required: true
default: 'both'
type: choice
options: [ both, debug, release ]
env:
KEYSTORE_FILE: debug.keystore
KEYSTORE_PASSWORD: android
KEY_ALIAS: androiddebugkey
KEY_PASSWORD: android
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
build_debug: ${{ steps.set.outputs.debug }}
build_release: ${{ steps.set.outputs.release }}
commit_msg: ${{ steps.msg.outputs.text }}
commit_author: ${{ steps.msg.outputs.author }}
artifact_list: ${{ steps.set.outputs.artifact_list }}
steps:
- id: set
run: |
TYPE="${{ inputs.build_type }}"
[ "${{ github.event_name }}" != "workflow_dispatch" ] && TYPE="both"
DEBUG="false"; RELEASE="false"; LIST=""
[ "$TYPE" = "both" -o "$TYPE" = "debug" ] && { DEBUG="true"; LIST="folkpatch-debug-${{ github.sha }}"; }
[ "$TYPE" = "both" -o "$TYPE" = "release" ] && {
RELEASE="true"
[ -n "$LIST" ] && LIST="$LIST," || true
LIST="${LIST}folkpatch-release-${{ github.sha }}"
}
echo "debug=$DEBUG" >> "$GITHUB_OUTPUT"
echo "release=$RELEASE" >> "$GITHUB_OUTPUT"
echo "artifact_list=$LIST" >> "$GITHUB_OUTPUT"
- id: msg
run: |
case "${{ github.event_name }}" in
push) TEXT="${{ github.event.head_commit.message }}"
AUTHOR="${{ github.event.head_commit.author.name }}" ;;
pull_request) TEXT="PR: ${{ github.event.pull_request.title }}"
AUTHOR="${{ github.event.pull_request.user.login }}" ;;
*) TEXT="FolkPatch Build"
AUTHOR="${{ github.actor }}" ;;
esac
TEXT="${TEXT%%$'\n'*}"
echo "text=$TEXT" >> "$GITHUB_OUTPUT"
echo "author=$AUTHOR" >> "$GITHUB_OUTPUT"
build_debug:
name: Build Debug
needs: prepare
if: needs.prepare.outputs.build_debug == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- uses: ./.github/actions/setup-build-env
- run: ./gradlew assembleDebug --no-daemon
- name: Rename APK
run: |
SHORT="${GITHUB_SHA::7}"
APK=$(find app/build/outputs/apk/debug -name "*.apk" -type f | head -1)
[ -n "$APK" ] && mv "$APK" "FolkPatch-Debug-${SHORT}.apk"
- uses: actions/upload-artifact@v4
with:
name: folkpatch-debug-${{ github.sha }}
path: FolkPatch-Debug-*.apk
retention-days: 30
build_release:
name: Build Release
needs: prepare
if: needs.prepare.outputs.build_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- uses: ./.github/actions/setup-build-env
- name: Decode keystore
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > FolkPatch.jks
- name: Create keystore.properties
run: |
cat > keystore.properties << 'EOF'
KEYSTORE_FILE=../FolkPatch.jks
KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS=${{ secrets.KEY_ALIAS }}
KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}
EOF
- run: ./gradlew assembleRelease --no-daemon
- name: Debug APK location
run: find app/build/outputs -name "*.apk" -type f || echo "No APK found"
- name: Rename APK
run: |
SHORT="${GITHUB_SHA::7}"
APK=$(find app/build/outputs/apk/release -name "*.apk" -type f | head -1)
[ -n "$APK" ] && mv "$APK" "FolkPatch-Release-${SHORT}.apk"
- uses: actions/upload-artifact@v4
with:
name: folkpatch-release-${{ github.sha }}
path: FolkPatch-Release-*.apk
retention-days: 30
upload:
name: Upload to Telegram
needs: [prepare, build_debug, build_release]
if: always() && needs.prepare.result == 'success' && (needs.build_debug.result == 'success' || needs.build_release.result == 'success') && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Check Telegram config
id: tg_check
run: |
if [ -n "${{ secrets.TELEGRAM_BOT_TOKEN }}" ] && [ -n "${{ secrets.TELEGRAM_CHAT_ID }}" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Telegram secrets not configured, skipping upload"
fi
- name: Download artifacts
if: steps.tg_check.outputs.enabled == 'true'
uses: actions/download-artifact@v4
with:
pattern: folkpatch-*
path: artifacts
merge-multiple: true
- name: Send to Telegram
if: steps.tg_check.outputs.enabled == 'true'
run: |
FILES=$(find artifacts -type f 2>/dev/null | sort)
FILE_COUNT=$(echo "$FILES" | grep -c . || true)
if [ "$FILE_COUNT" -eq 0 ]; then
echo "::error::No files found in artifacts"
exit 1
fi
CAPTION="${{ needs.prepare.outputs.commit_msg }}\nBranch: ${{ github.ref_name }}\nCommit: ${{ github.sha }}\nAuthor: ${{ needs.prepare.outputs.commit_author }}\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
if [ "$FILE_COUNT" -eq 1 ]; then
curl -sf -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
-F "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
-F "document=@$FILES" \
-F "caption=${CAPTION}"
else
FILE_ARR=()
while IFS= read -r f; do
FILE_ARR+=("$f")
done <<< "$FILES"
TOTAL=${#FILE_ARR[@]}
MEDIA_JSON="["
for i in "${!FILE_ARR[@]}"; do
FNAME=$(basename "${FILE_ARR[$i]}")
if [ $i -gt 0 ]; then
MEDIA_JSON+=","
fi
if [ $((i + 1)) -eq $TOTAL ]; then
MEDIA_JSON+="{\"type\":\"document\",\"media\":\"attach://$FNAME\",\"caption\":\"${CAPTION}\"}"
else
MEDIA_JSON+="{\"type\":\"document\",\"media\":\"attach://$FNAME\"}"
fi
done
MEDIA_JSON+="]"
ARGS=(-X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMediaGroup")
ARGS+=(-F "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}")
ARGS+=(-F "media=${MEDIA_JSON}")
while IFS= read -r f; do
FNAME=$(basename "$f")
ARGS+=(-F "$FNAME=@$f")
done <<< "$FILES"
curl -sf "${ARGS[@]}"
fi