| 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 | build: |
| 17 | name: Gradle Build |
| 18 | runs-on: ubuntu-latest |
| 19 | env: |
| 20 | CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion" |
| 21 | CCACHE_NOHASHDIR: "true" |
| 22 | CCACHE_MAXSIZE: "5G" |
| 23 | CCACHE_HARDLINK: "true" |
| 24 | steps: |
| 25 | - name: Checkout |
| 26 | uses: actions/checkout@v7 |
| 27 | with: |
| 28 | submodules: 'recursive' |
| 29 | - name: Set up JDK 17 |
| 30 | uses: actions/setup-java@v6 |
| 31 | with: |
| 32 | java-version: '17' |
| 33 | distribution: 'temurin' |
| 34 | - name: Setup Android SDK Tools |
| 35 | uses: android-actions/setup-android@v4 |
| 36 | with: |
| 37 | packages: 'platform-tools' |
| 38 | - name: Set up ccache |
| 39 | uses: hendrikmuhs/ccache-action@v1 |
| 40 | with: |
| 41 | append-timestamp: false |
| 42 | key: native-${{ github.job }} |
| 43 | max-size: 5G |
| 44 | - name: Install NDK |
| 45 | run: | |
| 46 | echo "y" | sdkmanager --install "ndk;27.2.12479018" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null |
| 47 | echo "sdk.dir=${ANDROID_HOME}" > local.properties |
| 48 | echo "ndk.dir=${ANDROID_HOME}/ndk/27.2.12479018" >> local.properties |
| 49 | - name: Configure Gradle |
| 50 | run: | |
| 51 | sed -i "s/2000000000000/$(date +%s%N | cut -c1-13)/g" gradle.properties |
| 52 | echo "sdk.dir=${ANDROID_HOME}" >> local.properties |
| 53 | - name: Setup Gradle |
| 54 | uses: gradle/actions/setup-gradle@v6 |
| 55 | - name: Release Build |
| 56 | run: | |
| 57 | export LOCAL_PROPERTIES="${{ secrets.LOCAL_PROPERTIES }}" |
| 58 | export SENTRY_AUTH_TOKEN="${{ secrets.SENTRY_AUTH_TOKEN }}" |
| 59 | ./gradlew TMessagesProj:assembleRelease --build-cache --no-configuration-cache |
| 60 |
| 61 | APK=$(find TMessagesProj/build/outputs/apk -name '*arm64-v8a*.apk') |
| 62 | APK=$(dirname $APK) |
| 63 | echo "APK=$APK" >> $GITHUB_ENV |
| 64 | - name: Upload gradle.properties |
| 65 | uses: actions/upload-artifact@v7 |
| 66 | with: |
| 67 | name: gradle-properties |
| 68 | path: gradle.properties |
| 69 | - uses: actions/upload-artifact@v7 |
| 70 | with: |
| 71 | name: Release |
| 72 | path: ${{ env.APK }} |
| 73 | upload: |
| 74 | name: Upload release |
| 75 | if: github.event.inputs.upload != 'y' |
| 76 | # The channel-publish action runs a Bot API server built on this system. |
| 77 | runs-on: ubuntu-24.04 |
| 78 | needs: |
| 79 | - build |
| 80 | steps: |
| 81 | - name: Checkout |
| 82 | uses: actions/checkout@v7 |
| 83 | - name: Remove gradle.properties |
| 84 | run: | |
| 85 | rm -f gradle.properties |
| 86 | - name: Download gradle.properties |
| 87 | uses: actions/download-artifact@v8 |
| 88 | with: |
| 89 | name: gradle-properties |
| 90 | path: . |
| 91 | - name: Donwload Artifacts |
| 92 | uses: actions/download-artifact@v8 |
| 93 | with: |
| 94 | path: artifacts |
| 95 | - name: Set up Python |
| 96 | uses: actions/setup-python@v7 |
| 97 | with: |
| 98 | python-version: 3.12 |
| 99 | - name: Prepare channel post |
| 100 | id: post |
| 101 | env: |
| 102 | BOT_TOKEN: ${{ secrets.NAGRAM_CHANNEL_BOT_TOKEN }} |
| 103 | ASSETS_CHAT_ID: ${{ vars.NAGRAM_CHANNEL_ASSETS_CHAT_ID }} |
| 104 | OFFICIAL_CHAT_ID: ${{ vars.NAGRAM_CHANNEL_CHAT_ID }} |
| 105 | run: | |
| 106 | if [ -z "$BOT_TOKEN" ] || [ -z "$ASSETS_CHAT_ID$OFFICIAL_CHAT_ID" ]; then |
| 107 | echo "::notice::NAGRAM_CHANNEL_BOT_TOKEN or both channels are not set, nothing is posted." |
| 108 | exit 0 |
| 109 | fi |
| 110 | mkdir "$RUNNER_TEMP/channel" |
| 111 | find artifacts \( -name '*arm64-v8a.apk' -o -name '*armeabi-v7a.apk' \) \ |
| 112 | -exec cp {} "$RUNNER_TEMP/channel/" \; |
| 113 | ls -l "$RUNNER_TEMP/channel" |
| 114 | python bin/scripts/apk_version.py "$RUNNER_TEMP"/channel/*arm64-v8a.apk > "$RUNNER_TEMP/apk-version" |
| 115 | cat "$RUNNER_TEMP/apk-version" >> "$GITHUB_OUTPUT" |
| 116 | BUILD="$(sed -n 's/^build=//p' "$RUNNER_TEMP/apk-version")" |
| 117 | # Every release has its notes, named after the version code. |
| 118 | NOTES="docs/releases/$BUILD.md" |
| 119 | if [ ! -f "$NOTES" ]; then |
| 120 | echo "::error::$NOTES is missing, the release is not posted." |
| 121 | exit 1 |
| 122 | fi |
| 123 | # English notes are optional and are folded under the others. |
| 124 | NOTES_EN="docs/releases/$BUILD.en.md" |
| 125 | if [ ! -f "$NOTES_EN" ]; then |
| 126 | NOTES_EN="" |
| 127 | fi |
| 128 | # The files are sent to the assets channel and the official one |
| 129 | # gets a copy of the post; with one channel set, it gets the post. |
| 130 | CHAT_ID="${ASSETS_CHAT_ID:-$OFFICIAL_CHAT_ID}" |
| 131 | COPY_TO="" |
| 132 | if [ -n "$ASSETS_CHAT_ID" ] && [ "$OFFICIAL_CHAT_ID" != "$ASSETS_CHAT_ID" ]; then |
| 133 | COPY_TO="$OFFICIAL_CHAT_ID" |
| 134 | fi |
| 135 | { |
| 136 | echo "chat=$CHAT_ID" |
| 137 | echo "copy=$COPY_TO" |
| 138 | echo "notes=$NOTES" |
| 139 | echo "notes_en=$NOTES_EN" |
| 140 | } >> "$GITHUB_OUTPUT" |
| 141 | # The in-app updater reads the APKs and their JSON from the metadata |
| 142 | # channel, whatever is posted to the channels below. |
| 143 | - name: Update metadata |
| 144 | env: |
| 145 | HELPER_BOT_TOKEN: ${{ secrets.HELPER_BOT_TOKEN }} |
| 146 | run: | |
| 147 | python -m pip install -r bin/scripts/requirements.txt |
| 148 | python bin/scripts/upload.py "$HELPER_BOT_TOKEN" |
| 149 | - name: Post to channels |
| 150 | if: steps.post.outputs.chat != '' |
| 151 | uses: NextAlone/NagramActionRelated/channel-publish@f6be16850f0f7eddbc0fa3db6561bd3abde0a8ea |
| 152 | with: |
| 153 | bot-token: ${{ secrets.NAGRAM_CHANNEL_BOT_TOKEN }} |
| 154 | api-id: ${{ secrets.NAGRAM_API_ID }} |
| 155 | api-hash: ${{ secrets.NAGRAM_API_HASH }} |
| 156 | chat-id: ${{ steps.post.outputs.chat }} |
| 157 | copy-to: ${{ steps.post.outputs.copy }} |
| 158 | directory: ${{ runner.temp }}/channel |
| 159 | title: Nagram |
| 160 | version: ${{ steps.post.outputs.version }} |
| 161 | build: ${{ steps.post.outputs.build }} |
| 162 | hashtags: android release |
| 163 | notes-file: ${{ steps.post.outputs.notes }} |
| 164 | notes-en-file: ${{ steps.post.outputs.notes_en }} |
| 165 | files: | |
| 166 | *arm64-v8a.apk | arm64-v8a · 大多数设备 |
| 167 | *armeabi-v7a.apk | armeabi-v7a · 旧设备 |
| 168 | # The release is tagged with the version code. |
| 169 | buttons: | |
| 170 | *GitHub Release=${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.post.outputs.build }} | danger:问题反馈=https://t.me/OrIssuesBot | Assets={post} |
| 171 |