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