Add files via upload (#146) #753
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |