Telegram Release #8
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: Telegram Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_code: | |
| description: 'Specific Version Code (Leave empty to use latest Store version)' | |
| required: false | |
| type: string | |
| increment: | |
| description: 'Increment Version? (Only used if Version Code is empty)' | |
| required: true | |
| type: boolean | |
| default: false | |
| jobs: | |
| build-and-announce: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Required to check for releases | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'zulu' | |
| java-version: '21' | |
| cache: 'gradle' | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.0' | |
| - name: Install Fastlane | |
| run: gem install fastlane | |
| # --- SECRET DECODING --- | |
| - name: Decode Keystore | |
| env: | |
| ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} | |
| run: echo "$ANDROID_KEYSTORE_BASE64" | base64 --decode > app/release.jks | |
| - name: Decode Google Play Service Account | |
| env: | |
| PLAY_STORE_JSON_KEY: ${{ secrets.PLAY_STORE_JSON_KEY }} | |
| run: echo "$PLAY_STORE_JSON_KEY" > app/google-play-api.json | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| # --- BUILD ARTIFACTS --- | |
| # Updated to pass inputs to Fastlane | |
| - name: Run Fastlane (Build Candidates) | |
| env: | |
| JSON_KEY_FILE: ${{ github.workspace }}/app/google-play-api.json | |
| SUPPLY_JSON_KEY: ${{ github.workspace }}/app/google-play-api.json | |
| KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
| KEYSTORE_FILE_PATH: ${{ github.workspace }}/app/release.jks | |
| # Map inputs to Env Vars (cleaner than passing directly in run command string) | |
| INPUT_VERSION_CODE: ${{ inputs.version_code }} | |
| INPUT_INCREMENT: ${{ inputs.increment }} | |
| run: | | |
| # Pass arguments to the lane using key:value syntax | |
| # If INPUT_VERSION_CODE is empty, Fastlane receives nil/empty string and logic handles it | |
| fastlane android build_release_candidates \ | |
| version_code:"$INPUT_VERSION_CODE" \ | |
| increment:"$INPUT_INCREMENT" | |
| # --- PREPARE ANNOUNCEMENT --- | |
| - name: Read Version Info | |
| id: version_info | |
| run: | | |
| VERSION_NAME=$(cat version_name.txt) | |
| VERSION_CODE=$(cat version_code.txt) | |
| echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV | |
| echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV | |
| # Resolve Telegram notes | |
| TELEGRAM_NOTES_FILE="release-notes/v${VERSION_NAME}/telegram.md" | |
| if [ ! -f "$TELEGRAM_NOTES_FILE" ]; then | |
| TELEGRAM_NOTES_FILE="release-notes/${VERSION_NAME}/telegram.md" | |
| fi | |
| if [ -f "$TELEGRAM_NOTES_FILE" ]; then | |
| echo "telegram_notes_path=$TELEGRAM_NOTES_FILE" >> "$GITHUB_OUTPUT" | |
| echo "has_telegram_notes=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_telegram_notes=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Check for GitHub Release | |
| id: check_release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="v${{ env.VERSION_NAME }}" | |
| echo "Checking for release tag: $TAG" | |
| # Check if release exists using GitHub CLI | |
| if gh release view "$TAG" > /dev/null 2>&1; then | |
| echo "Release found!" | |
| echo "release_url=https://github.com/${{ github.repository }}/releases/tag/$TAG" >> $GITHUB_OUTPUT | |
| echo "has_release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No release found for $TAG" | |
| echo "has_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to Telegram Channel | |
| env: | |
| TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} | |
| TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_RELEASE_CHAT_ID }} | |
| RELEASE_URL: ${{ steps.check_release.outputs.release_url }} | |
| HAS_RELEASE: ${{ steps.check_release.outputs.has_release }} | |
| HAS_TELEGRAM_NOTES: ${{ steps.version_info.outputs.has_telegram_notes }} | |
| TELEGRAM_NOTES_PATH: ${{ steps.version_info.outputs.telegram_notes_path }} | |
| VERSION_NAME: ${{ env.VERSION_NAME }} | |
| VERSION_CODE: ${{ env.VERSION_CODE }} | |
| GITHUB_REF_NAME: ${{ github.ref_name }} | |
| run: | | |
| STORE_APK="app/build/distribution/store/store-release.apk" | |
| FOSS_APK="app/build/distribution/foss/foss-release.apk" | |
| # 1. Construct the Caption | |
| CAPTION=$(printf "⚡️ *Thor v%s Released!*\n\nBuild: %s\nBranch: %s" "$VERSION_NAME" "$VERSION_CODE" "$GITHUB_REF_NAME") | |
| if [ "$HAS_TELEGRAM_NOTES" = "true" ] && [ -f "$TELEGRAM_NOTES_PATH" ]; then | |
| CAPTION=$(printf "%s\n\n%s" "$CAPTION" "$(cat "$TELEGRAM_NOTES_PATH")") | |
| else | |
| CAPTION=$(printf "%s\n\n• Bug fixes and performance improvements" "$CAPTION") | |
| fi | |
| if [ "$HAS_RELEASE" = "true" ]; then | |
| CAPTION=$(printf "%s\n\n🔗 [View on GitHub](%s)" "$CAPTION" "$RELEASE_URL") | |
| fi | |
| # 2. Send Store APK | |
| echo "Sending Store APK..." | |
| curl -s -F "chat_id=$TELEGRAM_CHAT_ID" \ | |
| -F "document=@$STORE_APK" \ | |
| -F "caption=$CAPTION" \ | |
| -F "parse_mode=Markdown" \ | |
| "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendDocument" > /dev/null | |
| # 3. Send FOSS APK (Reply to previous? No, just send as second message for now) | |
| echo "Sending FOSS APK..." | |
| curl -s -F "chat_id=$TELEGRAM_CHAT_ID" \ | |
| -F "document=@$FOSS_APK" \ | |
| -F "caption=🔓 *FOSS Version (No Google Services)*" \ | |
| -F "parse_mode=Markdown" \ | |
| "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendDocument" > /dev/null | |
| # --- SECURITY CLEANUP --- | |
| - name: Cleanup sensitive files | |
| if: always() | |
| run: | | |
| rm -f app/release.jks | |
| rm -f app/google-play-api.json |