Skip to content

Commit 59fd064

Browse files
committed
ci: overhaul GitHub Actions workflow for reliable debug/release builds and Telegram notifications
- Split matrix build job into independent debug/release jobs with proper conditional execution - Replace deprecated gh run download with actions/download-artifact for reliable artifact handling - Inline Telegram upload logic directly into build.yml to resolve workflow_call artifact scope issues - Fix upload job condition expressions and improve error resilience for Telegram API calls
1 parent e363ef4 commit 59fd064

2 files changed

Lines changed: 126 additions & 47 deletions

File tree

.github/workflows/CI_up.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,32 @@ jobs:
1717
upload:
1818
name: Upload to Telegram
1919
runs-on: ubuntu-latest
20-
if: ${{ vars.TELEGRAM_ENABLED == 'true' }}
2120

2221
steps:
22+
- name: Check Telegram config
23+
id: tg_check
24+
run: |
25+
if [ -n "${{ secrets.TELEGRAM_BOT_TOKEN }}" ] && [ -n "${{ secrets.TELEGRAM_CHAT_ID }}" ]; then
26+
echo "enabled=true" >> "$GITHUB_OUTPUT"
27+
else
28+
echo "::notice::Telegram secrets not configured, skipping upload"
29+
fi
30+
2331
- name: Checkout repository
32+
if: steps.tg_check.outputs.enabled == 'true'
2433
uses: actions/checkout@v5
2534

2635
- name: Download artifacts
27-
run: |
28-
mkdir -p artifacts
29-
IFS=',' read -ra NAMES <<< "${{ inputs.artifact_names }}"
30-
for NAME in "${NAMES[@]}"; do
31-
echo "Downloading artifact: $NAME"
32-
gh run download "$RUN_ID" --name "$NAME" --dir artifacts 2>/dev/null || \
33-
echo "::warning::Artifact $NAME not found"
34-
done
35-
env:
36-
GH_TOKEN: ${{ github.token }}
37-
RUN_ID: ${{ github.run_id }}
36+
if: steps.tg_check.outputs.enabled == 'true'
37+
uses: actions/download-artifact@v4
38+
with:
39+
pattern: folkpatch-*
40+
path: artifacts
41+
merge-multiple: true
3842

3943
- name: Send to Telegram
44+
if: steps.tg_check.outputs.enabled == 'true'
4045
run: |
41-
mkdir -p artifacts
4246
FILES=$(find artifacts -type f 2>/dev/null | sort)
4347
FILE_COUNT=$(echo "$FILES" | grep -c . || true)
4448
@@ -53,7 +57,7 @@ jobs:
5357
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
5458
5559
if [ "$FILE_COUNT" -eq 1 ]; then
56-
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
60+
curl -sf -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
5761
-F "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
5862
-F "document=@$FILES" \
5963
-F "caption=${CAPTION}"
@@ -87,5 +91,5 @@ jobs:
8791
ARGS+=(-F "$FNAME=@$f")
8892
done <<< "$FILES"
8993
90-
curl -s "${ARGS[@]}"
94+
curl -sf "${ARGS[@]}"
9195
fi

.github/workflows/build.yml

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)