|
| 1 | +name: "Build only" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + tags: |
| 7 | + - v* |
| 8 | + pull_request: |
| 9 | + branches: [ master ] |
| 10 | + |
| 11 | + |
| 12 | +env: |
| 13 | + NDK_VERSION: '25.2.9519653' |
| 14 | + NODE_VERSION: '16' |
| 15 | + JAVA_VERSION: '17' |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-rust: |
| 19 | + name: Build aw-server-rust |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v3 |
| 23 | + with: |
| 24 | + submodules: 'recursive' |
| 25 | + - name: Set RELEASE |
| 26 | + run: | |
| 27 | + echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Cache JNI libs |
| 30 | + uses: actions/cache@v3 |
| 31 | + id: cache-jniLibs |
| 32 | + env: |
| 33 | + cache-name: jniLibs |
| 34 | + with: |
| 35 | + path: mobile/src/main/jniLibs/ |
| 36 | + key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }} |
| 37 | + |
| 38 | + - name: Display structure of downloaded files |
| 39 | + if: steps.cache-jniLibs.outputs.cache-hit == 'true' |
| 40 | + run: | |
| 41 | + pushd mobile/src/main/jniLibs && ls -R && popd |
| 42 | +
|
| 43 | + # Android SDK & NDK |
| 44 | + - name: Set up Android SDK |
| 45 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 46 | + uses: android-actions/setup-android@v2 |
| 47 | + - name: Set up Android NDK |
| 48 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 49 | + run: | |
| 50 | + sdkmanager "ndk;${{ env.NDK_VERSION }}" |
| 51 | + ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}" |
| 52 | + ls $ANDROID_NDK_HOME |
| 53 | + echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + # Rust |
| 56 | + - name: Set up Rust |
| 57 | + id: toolchain |
| 58 | + uses: dtolnay/rust-toolchain@stable |
| 59 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 60 | + |
| 61 | + - name: Set up Rust toolchain for Android NDK |
| 62 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 63 | + run: | |
| 64 | + ./aw-server-rust/install-ndk.sh |
| 65 | +
|
| 66 | + - name: Cache cargo build |
| 67 | + uses: actions/cache@v3 |
| 68 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 69 | + env: |
| 70 | + cache-name: cargo-build-target |
| 71 | + with: |
| 72 | + path: aw-server-rust/target |
| 73 | + # key needs to contain cachekey due to https://github.com/ActivityWatch/aw-server-rust/issues/180 |
| 74 | + key: ${{ env.cache-name }}-${{ runner.os }}-release-${{ env.RELEASE }}-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} |
| 75 | + restore-keys: | |
| 76 | + ${{ env.cache-name }}-${{ runner.os }}-release-${{ env.RELEASE }}-${{ steps.toolchain.outputs.cachekey }}- |
| 77 | +
|
| 78 | + - name: Build aw-server-rust |
| 79 | + if: steps.cache-jniLibs.outputs.cache-hit != 'true' |
| 80 | + run: | |
| 81 | + make aw-server-rust |
| 82 | +
|
| 83 | + - name: Check that jniLibs present |
| 84 | + run: | |
| 85 | + test -e mobile/src/main/jniLibs/x86_64/libaw_server.so |
| 86 | +
|
| 87 | + # This needs to be a seperate job since fastlane update_version, |
| 88 | + # fails if run concurrently (such as in build apk/aab matrix), |
| 89 | + # thus we need to run it once and and reuse the results. |
| 90 | + # https://github.com/fastlane/fastlane/issues/13689#issuecomment-439217502 |
| 91 | + get-versionCode: |
| 92 | + name: Get latest versionCode |
| 93 | + runs-on: ubuntu-latest |
| 94 | + outputs: |
| 95 | + versionCode: ${{ steps.versionCode.outputs.versionCode }} |
| 96 | + |
| 97 | + steps: |
| 98 | + - uses: actions/checkout@v2 |
| 99 | + with: |
| 100 | + submodules: 'recursive' |
| 101 | + |
| 102 | + - name: Output versionCode |
| 103 | + id: versionCode |
| 104 | + run: | |
| 105 | + cat mobile/build.gradle | grep versionCode | sed 's/.*\s\([0-9]*\)$/versionCode=\1/' >> "$GITHUB_OUTPUT" |
| 106 | +
|
| 107 | + build-apk: |
| 108 | + name: Build ${{ matrix.type }} |
| 109 | + runs-on: ubuntu-20.04 |
| 110 | + needs: [build-rust, get-versionCode] |
| 111 | + strategy: |
| 112 | + fail-fast: true |
| 113 | + matrix: |
| 114 | + type: ['apk', 'aab'] |
| 115 | + |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v2 |
| 118 | + with: |
| 119 | + submodules: 'recursive' |
| 120 | + |
| 121 | + - uses: ActivityWatch/check-version-format-action@v2 |
| 122 | + id: version |
| 123 | + with: |
| 124 | + prefix: 'v' |
| 125 | + |
| 126 | + - name: Echo version |
| 127 | + run: | |
| 128 | + echo "${{ steps.version.outputs.full }} (stable: ${{ steps.version.outputs.is_stable }})" |
| 129 | +
|
| 130 | + - name: Set RELEASE |
| 131 | + run: | |
| 132 | + # Build in release mode if on a tag/release (longer build times) |
| 133 | + echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV |
| 134 | +
|
| 135 | + - name: Set up JDK |
| 136 | + uses: actions/setup-java@v1 |
| 137 | + with: |
| 138 | + java-version: ${{ env.JAVA_VERSION }} |
| 139 | + |
| 140 | + # Android SDK & NDK |
| 141 | + - name: Set up Android SDK |
| 142 | + uses: android-actions/setup-android@v2 |
| 143 | + - name: Set up Android NDK |
| 144 | + run: | |
| 145 | + sdkmanager "ndk;${{ env.NDK_VERSION }}" |
| 146 | + ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}" |
| 147 | + ls $ANDROID_NDK_HOME |
| 148 | + echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV |
| 149 | +
|
| 150 | + # Restores jniLibs from cache |
| 151 | + # `actions/cache/restore` only restores, without saving back in a post-hook |
| 152 | + - uses: actions/cache/restore@v3 |
| 153 | + id: cache-jniLibs |
| 154 | + env: |
| 155 | + cache-name: jniLibs |
| 156 | + with: |
| 157 | + path: mobile/src/main/jniLibs/ |
| 158 | + key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }} |
| 159 | + fail-on-cache-miss: true |
| 160 | + |
| 161 | + - name: Check that jniLibs present |
| 162 | + run: | |
| 163 | + test -e mobile/src/main/jniLibs/x86_64/libaw_server.so |
| 164 | +
|
| 165 | + - name: Set versionName |
| 166 | + if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag |
| 167 | + run: | |
| 168 | + # Sets versionName, tail used to skip "v" at start of tag name |
| 169 | + SHORT_VERSION=$(echo "${{ github.ref_name }}" | tail -c +2 -) |
| 170 | + sed -i "s/versionName \".*\"/versionName \"$SHORT_VERSION\"/g" \ |
| 171 | + mobile/build.gradle |
| 172 | +
|
| 173 | + - name: Set versionCode |
| 174 | + run: | |
| 175 | + # Sets versionCode |
| 176 | + sed -i "s/versionCode .*/versionCode ${{needs.get-versionCode.outputs.versionCode}}/" \ |
| 177 | + mobile/build.gradle |
| 178 | +
|
| 179 | + |
| 180 | + - name: Load Android secrets |
| 181 | + if: env.KEY_ANDROID_JKS != null |
| 182 | + env: |
| 183 | + KEY_ANDROID_JKS: ${{ secrets.KEY_ANDROID_JKS }} |
| 184 | + run: | |
| 185 | + printf "$KEY_ANDROID_JKS" > android.jks.key |
| 186 | + cat android.jks.age | age -d -i android.jks.key -o android.jks |
| 187 | + rm android.jks.key |
| 188 | +
|
| 189 | + - name: Assemble |
| 190 | + env: |
| 191 | + JKS_STOREPASS: ${{ secrets.KEY_ANDROID_JKS_STOREPASS }} |
| 192 | + JKS_KEYPASS: ${{ secrets.KEY_ANDROID_JKS_KEYPASS }} |
| 193 | + run: | |
| 194 | + make dist/aw-android.${{ matrix.type }} |
| 195 | +
|
| 196 | + - name: Upload |
| 197 | + uses: actions/upload-artifact@v3 |
| 198 | + with: |
| 199 | + name: aw-android |
| 200 | + path: dist/aw-android*.${{ matrix.type }} |
0 commit comments