| 5 |
| - main |
| 6 | paths-ignore: |
| 7 | - '**.md' |
| 8 | - '.github/**' |
| 9 | - '!.github/workflows/release.yml' |
| 10 | workflow_dispatch: |
| 11 | inputs: |
| 12 | upload: |
| 13 | description: 'Upload: If want ignore' |
| 14 | required: false |
| 15 | jobs: |
| 16 | native: |
| 17 | name: Native Build (Telegram) |
| 18 | runs-on: ubuntu-latest |
| 19 | strategy: |
| 20 | matrix: |
| 21 | flavor: |
| 22 | - armeabi-v7a |
| 23 | - arm64-v8a |
| 24 | steps: |
| 25 | - name: Checkout |
| 26 | uses: actions/checkout@v7 |
| 27 | - name: Fetch Status |
| 28 | run: | |
| 29 | sed -i 's/\/\///g' settings.gradle |
| 30 | - name: Native Cache |
| 31 | id: cache |
| 32 | uses: actions/cache@v6 |
| 33 | with: |
| 34 | path: | |
| 35 | TMessagesProj/src/main/libs |
| 36 | key: ${{ hashFiles('TMessagesProj/jni/**') }}-${{ matrix.flavor }} |
| 37 | - name: Checkout Library |
| 38 | if: steps.cache.outputs.cache-hit != 'true' |
| 39 | run: | |
| 40 | git submodule update --init |
| 41 | - name: Set up JDK 17 |
| 42 | uses: actions/setup-java@v6 |
| 43 | if: steps.cache.outputs.cache-hit != 'true' |
| 44 | with: |
| 45 | java-version: '17' |
| 46 | distribution: 'temurin' |
| 47 | - name: Setup Android SDK Tools |
| 48 | uses: android-actions/setup-android@v4 |
| 49 | if: steps.cache.outputs.cache-hit != 'true' |
| 50 | with: |
| 51 | packages: 'platform-tools' |
| 52 | - name: Install NDK |
| 53 | if: steps.cache.outputs.cache-hit != 'true' |
| 54 | run: | |
| 55 | echo "y" | sdkmanager --install "ndk;27.2.12479018" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null |
| 56 | echo "sdk.dir=${ANDROID_HOME}" > local.properties |
| 57 | echo "ndk.dir=${ANDROID_HOME}/ndk/27.2.12479018" >> local.properties |
| 58 | - name: Native Build |
| 59 | if: steps.cache.outputs.cache-hit != 'true' |
| 60 | run: | |
| 61 | export NATIVE_TARGET="${{ matrix.flavor }}" |
| 62 | ./run libs native |
| 63 | build: |
| 64 | name: Gradle Build |
| 65 | runs-on: ubuntu-latest |
| 66 | needs: |
| 67 | - native |
| 68 | steps: |
| 69 | - name: Checkout |
| 70 | uses: actions/checkout@v7 |
| 71 | - name: Fetch Status |
| 72 | run: | |
| 73 | sed -i 's/\/\///g' settings.gradle |
| 74 | - name: Native Cache (armeabi-v7a) |
| 75 | uses: actions/cache@v6 |
| 76 | with: |
| 77 | path: | |
| 78 | TMessagesProj/src/main/libs |
| 79 | key: ${{ hashFiles('TMessagesProj/jni/**') }}-armeabi-v7a |
| 80 | - name: Native Cache (arm64-v8a) |
| 81 | uses: actions/cache@v6 |
| 82 | with: |
| 83 | path: | |
| 84 | TMessagesProj/src/main/libs |
| 85 | key: ${{ hashFiles('TMessagesProj/jni/**') }}-arm64-v8a |
| 86 | - name: Checkout Library |
| 87 | run: | |
| 88 | git submodule update --init |
| 89 | - name: Set up JDK 17 |
| 90 | uses: actions/setup-java@v6 |
| 91 | with: |
| 92 | java-version: '17' |
| 93 | distribution: 'temurin' |
| 94 | - name: Setup Android SDK Tools |
| 95 | uses: android-actions/setup-android@v4 |
| 96 | with: |
| 97 | packages: 'platform-tools' |
| 98 | - name: Install NDK |
| 99 | run: | |
| 100 | echo "y" | sdkmanager --install "ndk;27.2.12479018" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null |
| 101 | echo "sdk.dir=${ANDROID_HOME}" > local.properties |
| 102 | echo "ndk.dir=${ANDROID_HOME}/ndk/27.2.12479018" >> local.properties |
| 103 | - name: Configure Gradle |
| 104 | run: | |
| 105 | sed -i "s/2000000000000/$(date +%s%N | cut -c1-13)/g" gradle.properties |
| 106 | echo "sdk.dir=${ANDROID_HOME}" >> local.properties |
| 107 | - name: Setup Gradle |
| 108 | uses: gradle/actions/setup-gradle@v6 |
| 109 | - name: Release Build |
| 110 | run: | |
| 111 | export LOCAL_PROPERTIES="${{ secrets.LOCAL_PROPERTIES }}" |
| 112 | export SENTRY_AUTH_TOKEN="${{ secrets.SENTRY_AUTH_TOKEN }}" |
| 113 | ./gradlew TMessagesProj:assembleRelease --build-cache --no-configuration-cache |
| 114 |
| 115 | APK=$(find TMessagesProj/build/outputs/apk -name '*arm64-v8a*.apk') |
| 116 | APK=$(dirname $APK) |
| 117 | echo "APK=$APK" >> $GITHUB_ENV |
| 118 | - name: Upload gradle.properties |
| 119 | uses: actions/upload-artifact@v7 |
| 120 | with: |
| 121 | name: gradle-properties |
| 122 | path: gradle.properties |
| 123 | - uses: actions/upload-artifact@v7 |
| 124 | with: |
| 125 | name: Release |
| 126 | path: ${{ env.APK }} |
| 127 | upload: |
| 128 | name: Upload release |
| 129 | if: github.event.inputs.upload != 'y' |
| 130 | # The channel-publish action runs a Bot API server built on this system. |
| 131 | runs-on: ubuntu-24.04 |
| 132 | needs: |
| 133 | - build |
| 134 | steps: |
| 135 | - name: Checkout |
| 136 | uses: actions/checkout@v7 |
| 137 | - name: Remove gradle.properties |
| 138 | run: | |
| 139 | rm -f gradle.properties |
| 140 | - name: Download gradle.properties |
| 141 | uses: actions/download-artifact@v8 |
| 142 | with: |
| 143 | name: gradle-properties |
| 144 | path: . |
| 145 | - name: Donwload Artifacts |
| 146 | uses: actions/download-artifact@v8 |
| 147 | with: |
| 148 | path: artifacts |
| 149 | - name: Set up Python |
| 150 | uses: actions/setup-python@v7 |
| 151 | with: |
| 152 | python-version: 3.12 |
| 153 | - name: Prepare channel post |
| 154 | id: post |
| 155 | env: |
| 156 | BOT_TOKEN: ${{ secrets.NAGRAM_CHANNEL_BOT_TOKEN }} |
| 157 | ASSETS_CHAT_ID: ${{ vars.NAGRAM_CHANNEL_ASSETS_CHAT_ID }} |
| 158 | OFFICIAL_CHAT_ID: ${{ vars.NAGRAM_CHANNEL_CHAT_ID }} |
| 159 | run: | |
| 160 | if [ -z "$BOT_TOKEN" ] || [ -z "$ASSETS_CHAT_ID$OFFICIAL_CHAT_ID" ]; then |
| 161 | echo "::notice::NAGRAM_CHANNEL_BOT_TOKEN or both channels are not set, nothing is posted." |
| 162 | exit 0 |
| 163 | fi |
| 164 | mkdir "$RUNNER_TEMP/channel" |
| 165 | find artifacts \( -name '*arm64-v8a.apk' -o -name '*armeabi-v7a.apk' \) \ |
| 166 | -exec cp {} "$RUNNER_TEMP/channel/" \; |
| 167 | ls -l "$RUNNER_TEMP/channel" |
| 168 | python bin/scripts/apk_version.py "$RUNNER_TEMP"/channel/*arm64-v8a.apk > "$RUNNER_TEMP/apk-version" |
| 169 | cat "$RUNNER_TEMP/apk-version" >> "$GITHUB_OUTPUT" |
| 170 | BUILD="$(sed -n 's/^build=//p' "$RUNNER_TEMP/apk-version")" |
| 171 | # Every release has its notes, named after the version code. |
| 172 | NOTES="docs/releases/$BUILD.md" |
| 173 | if [ ! -f "$NOTES" ]; then |
| 174 | echo "::error::$NOTES is missing, the release is not posted." |
| 175 | exit 1 |
| 176 | fi |
| 177 | # English notes are optional and are folded under the others. |
| 178 | NOTES_EN="docs/releases/$BUILD.en.md" |
| 179 | if [ ! -f "$NOTES_EN" ]; then |
| 180 | NOTES_EN="" |
| 181 | fi |
| 182 | # The files are sent to the assets channel and the official one |
| 183 | # gets a copy of the post; with one channel set, it gets the post. |
| 184 | CHAT_ID="${ASSETS_CHAT_ID:-$OFFICIAL_CHAT_ID}" |
| 185 | COPY_TO="" |
| 186 | if [ -n "$ASSETS_CHAT_ID" ] && [ "$OFFICIAL_CHAT_ID" != "$ASSETS_CHAT_ID" ]; then |
| 187 | COPY_TO="$OFFICIAL_CHAT_ID" |
| 188 | fi |
| 189 | { |
| 190 | echo "chat=$CHAT_ID" |
| 191 | echo "copy=$COPY_TO" |
| 192 | echo "notes=$NOTES" |
| 193 | echo "notes_en=$NOTES_EN" |
| 194 | } >> "$GITHUB_OUTPUT" |
| 195 | # The in-app updater reads the APKs and their JSON from the metadata |
| 196 | # channel, whatever is posted to the channels below. |
| 197 | - name: Update metadata |
| 198 | env: |
| 199 | HELPER_BOT_TOKEN: ${{ secrets.HELPER_BOT_TOKEN }} |
| 200 | run: | |
| 201 | python -m pip install -r bin/scripts/requirements.txt |
| 202 | python bin/scripts/upload.py "$HELPER_BOT_TOKEN" |
| 203 | - name: Post to channels |
| 204 | if: steps.post.outputs.chat != '' |
| 205 | uses: NextAlone/NagramActionRelated/channel-publish@2b74e4cd4e3c89fcc9d50095c039e467c674661f |
| 206 | with: |
| 207 | bot-token: ${{ secrets.NAGRAM_CHANNEL_BOT_TOKEN }} |
| 208 | api-id: ${{ secrets.NAGRAM_API_ID }} |
| 209 | api-hash: ${{ secrets.NAGRAM_API_HASH }} |
| 210 | chat-id: ${{ steps.post.outputs.chat }} |
| 211 | copy-to: ${{ steps.post.outputs.copy }} |
| 212 | directory: ${{ runner.temp }}/channel |
| 213 | title: Nagram |
| 214 | version: ${{ steps.post.outputs.version }} |
| 215 | build: ${{ steps.post.outputs.build }} |
| 216 | hashtags: android release |
| 217 | notes-file: ${{ steps.post.outputs.notes }} |
| 218 | notes-en-file: ${{ steps.post.outputs.notes_en }} |
| 219 | files-title: 下载 |
| 220 | files: | |
| 221 | *arm64-v8a.apk | arm64-v8a · 大多数设备 |
| 222 | *armeabi-v7a.apk | armeabi-v7a · 旧设备 |
| 223 | # The release is tagged with the version code. |
| 224 | buttons: | |
| 225 | *GitHub Release=${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.post.outputs.build }} |
| 226 | 问题反馈=https://t.me/OrIssuesBot | Assets={post} |
| 227 |