@@ -59,56 +59,131 @@ jobs:
5959 TEXT="${TEXT%%$'\n'*}"
6060 echo "text=$TEXT" >> "$GITHUB_OUTPUT"
6161
62- build :
62+ build_debug :
63+ name : Build Debug
6364 needs : prepare
64- if : needs.prepare.outputs.build_debug == 'true' || needs.prepare.outputs.build_release == 'true'
65+ if : needs.prepare.outputs.build_debug == 'true'
6566 runs-on : ubuntu-latest
66- strategy :
67- fail-fast : false
68- matrix :
69- include :
70- - type : debug
71- task : assembleDebug
72- artifact_name : folkpatch-debug-${{ github.sha }}
73- apk_prefix : FolkPatch-Debug
74- apk_dir : debug
75- enabled : ${{ needs.prepare.outputs.build_debug == 'true' }}
76- - type : release
77- task : assembleRelease
78- artifact_name : folkpatch-release-${{ github.sha }}
79- apk_prefix : FolkPatch-Release
80- apk_dir : release
81- enabled : ${{ needs.prepare.outputs.build_release == 'true' }}
8267
8368 steps :
84- - name : Skip disabled build type
85- if : matrix.enabled != 'true'
86- run : echo "Skipping ${{ matrix.type }} build" && exit 0
69+ - uses : actions/checkout@v5
70+ with :
71+ submodules : recursive
72+
73+ - uses : ./.github/actions/setup-build-env
74+
75+ - run : ./gradlew assembleDebug --no-daemon
76+
77+ - name : Rename APK
78+ run : |
79+ SHORT="${GITHUB_SHA::7}"
80+ mv app/build/outputs/apk/debug/*.apk "FolkPatch-Debug-${SHORT}.apk"
81+
82+ - uses : actions/upload-artifact@v4
83+ with :
84+ name : folkpatch-debug-${{ github.sha }}
85+ path : FolkPatch-Debug-*.apk
86+ retention-days : 30
87+
88+ build_release :
89+ name : Build Release
90+ needs : prepare
91+ if : needs.prepare.outputs.build_release == 'true'
92+ runs-on : ubuntu-latest
8793
94+ steps :
8895 - uses : actions/checkout@v5
8996 with :
9097 submodules : recursive
9198
9299 - uses : ./.github/actions/setup-build-env
93100
94- - run : ./gradlew ${{ matrix.task }} --no-daemon
101+ - run : ./gradlew assembleRelease --no-daemon
95102
96103 - name : Rename APK
97104 run : |
98105 SHORT="${GITHUB_SHA::7}"
99- mv app/build/outputs/apk/${{ matrix.apk_dir }} /*.apk "${{ matrix.apk_prefix }} -${SHORT}.apk"
106+ mv app/build/outputs/apk/release /*.apk "FolkPatch-Release -${SHORT}.apk"
100107
101108 - uses : actions/upload-artifact@v4
102109 with :
103- name : ${{ matrix.artifact_name }}
104- path : ${{ matrix.apk_prefix }} -*.apk
110+ name : folkpatch-release- ${{ github.sha }}
111+ path : FolkPatch-Release -*.apk
105112 retention-days : 30
106113
107114 upload :
108- needs : [prepare, build]
109- if : always() && needs.prepare.result == 'success' && (needs.build.jobs.debug.result == 'success' || needs.build.jobs.release.result == 'success') && github.actor != 'dependabot[bot]'
110- uses : ./.github/workflows/CI_up.yml
111- with :
112- artifact_names : ${{ needs.prepare.outputs.artifact_list }}
113- message : ${{ needs.prepare.outputs.commit_msg }}
114- secrets : inherit
115+ name : Upload to Telegram
116+ needs : [prepare, build_debug, build_release]
117+ if : always() && needs.prepare.result == 'success' && (needs.build_debug.result == 'success' || needs.build_release.result == 'success') && github.actor != 'dependabot[bot]'
118+ runs-on : ubuntu-latest
119+
120+ steps :
121+ - name : Check Telegram config
122+ id : tg_check
123+ run : |
124+ if [ -n "${{ secrets.TELEGRAM_BOT_TOKEN }}" ] && [ -n "${{ secrets.TELEGRAM_CHAT_ID }}" ]; then
125+ echo "enabled=true" >> "$GITHUB_OUTPUT"
126+ else
127+ echo "::notice::Telegram secrets not configured, skipping upload"
128+ fi
129+
130+ - name : Download artifacts
131+ if : steps.tg_check.outputs.enabled == 'true'
132+ uses : actions/download-artifact@v4
133+ with :
134+ pattern : folkpatch-*
135+ path : artifacts
136+ merge-multiple : true
137+
138+ - name : Send to Telegram
139+ if : steps.tg_check.outputs.enabled == 'true'
140+ run : |
141+ FILES=$(find artifacts -type f 2>/dev/null | sort)
142+ FILE_COUNT=$(echo "$FILES" | grep -c . || true)
143+
144+ if [ "$FILE_COUNT" -eq 0 ]; then
145+ echo "::error::No files found in artifacts"
146+ exit 1
147+ fi
148+
149+ CAPTION="${{ needs.prepare.outputs.commit_msg }}
150+ Branch: ${{ github.ref_name }}
151+ Commit: ${{ github.sha }}"
152+
153+ if [ "$FILE_COUNT" -eq 1 ]; then
154+ curl -sf -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
155+ -F "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
156+ -F "document=@$FILES" \
157+ -F "caption=${CAPTION}"
158+ else
159+ FILE_ARR=()
160+ while IFS= read -r f; do
161+ FILE_ARR+=("$f")
162+ done <<< "$FILES"
163+
164+ TOTAL=${#FILE_ARR[@]}
165+ MEDIA_JSON="["
166+ for i in "${!FILE_ARR[@]}"; do
167+ FNAME=$(basename "${FILE_ARR[$i]}")
168+ if [ $i -gt 0 ]; then
169+ MEDIA_JSON+=","
170+ fi
171+ if [ $((i + 1)) -eq $TOTAL ]; then
172+ MEDIA_JSON+="{\"type\":\"document\",\"media\":\"attach://$FNAME\",\"caption\":\"${CAPTION}\"}"
173+ else
174+ MEDIA_JSON+="{\"type\":\"document\",\"media\":\"attach://$FNAME\"}"
175+ fi
176+ done
177+ MEDIA_JSON+="]"
178+
179+ ARGS=(-X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMediaGroup")
180+ ARGS+=(-F "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}")
181+ ARGS+=(-F "media=${MEDIA_JSON}")
182+
183+ while IFS= read -r f; do
184+ FNAME=$(basename "$f")
185+ ARGS+=(-F "$FNAME=@$f")
186+ done <<< "$FILES"
187+
188+ curl -sf "${ARGS[@]}"
189+ fi
0 commit comments