|
| 1 | +name: Build Android |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + tags: ['*'] |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Setup environment |
| 16 | + uses: ./.github/actions/setup-environment |
| 17 | + |
| 18 | + - name: Setup cache |
| 19 | + uses: ./.github/actions/setup-cache |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: npm install |
| 23 | + |
| 24 | + - name: Decode Android keystore |
| 25 | + run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android_keystore.jks |
| 26 | + |
| 27 | + - name: Set build type |
| 28 | + run: | |
| 29 | + if [[ $GITHUB_REF == refs/heads/master ]]; then |
| 30 | + echo "BUILD_TYPE=beta" >> $GITHUB_ENV |
| 31 | + echo "BUILD_SCRIPT=build:android:beta" >> $GITHUB_ENV |
| 32 | + elif [[ $GITHUB_REF == refs/tags/* ]]; then |
| 33 | + echo "BUILD_TYPE=release" >> $GITHUB_ENV |
| 34 | + echo "BUILD_SCRIPT=build:android:release" >> $GITHUB_ENV |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Build Android APK |
| 38 | + env: |
| 39 | + KEYSTORE_PATH: ./android_keystore.jks |
| 40 | + KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} |
| 41 | + KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }} |
| 42 | + KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }} |
| 43 | + run: npm run ${{ env.BUILD_SCRIPT }} |
| 44 | + |
| 45 | + - name: Get APK filename |
| 46 | + id: apk-info |
| 47 | + run: | |
| 48 | + APK_PATH=$(find platforms/android/app/build/outputs -name "*.apk" | head -n 1) |
| 49 | + APK_FILENAME=$(basename "$APK_PATH") |
| 50 | + echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT |
| 51 | + echo "apk_filename=$APK_FILENAME" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Create release for tags |
| 54 | + if: startsWith(github.ref, 'refs/tags/') |
| 55 | + uses: ncipollo/release-action@v1 |
| 56 | + with: |
| 57 | + allowUpdates: true |
| 58 | + artifacts: ${{ steps.apk-info.outputs.apk_path }} |
| 59 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Prepare metadata |
| 62 | + run: | |
| 63 | + mkdir -p artifact/.metadata |
| 64 | + echo "${{ env.BUILD_TYPE }}" > artifact/.metadata/build_type |
| 65 | + echo "${{ github.sha }}" > artifact/.metadata/commit |
| 66 | + echo "${{ steps.apk-info.outputs.apk_filename }}" > artifact/.metadata/apk_filename |
| 67 | + echo "$(date -u +'%Y-%m-%d_%H-%M')" > artifact/.metadata/buildstamp |
| 68 | +
|
| 69 | + # Copy APK to artifact directory |
| 70 | + mkdir -p artifact/build |
| 71 | + cp "${{ steps.apk-info.outputs.apk_path }}" artifact/build/ |
| 72 | +
|
| 73 | + - uses: actions/upload-artifact@v4 |
| 74 | + id: upload-artifact |
| 75 | + with: |
| 76 | + name: android-build |
| 77 | + include-hidden-files: true |
| 78 | + path: | |
| 79 | + artifact/.metadata/ |
| 80 | + artifact/build/ |
| 81 | +
|
| 82 | + - name: Get artifact ID |
| 83 | + id: get-artifact-id |
| 84 | + if: vars.WEBSITE_REPO != '' |
| 85 | + uses: actions/github-script@v7 |
| 86 | + with: |
| 87 | + script: | |
| 88 | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + run_id: context.runId |
| 92 | + }); |
| 93 | + const artifact = artifacts.data.artifacts.find(a => a.name === 'android-build'); |
| 94 | + return artifact.id; |
| 95 | +
|
| 96 | + - name: Send build to website |
| 97 | + if: vars.WEBSITE_REPO != '' |
| 98 | + uses: peter-evans/repository-dispatch@v3 |
| 99 | + with: |
| 100 | + token: ${{ secrets.API_TOKEN_GITHUB }} |
| 101 | + repository: ${{ vars.WEBSITE_REPO }} |
| 102 | + event-type: 'new_iitc_prime_build' |
| 103 | + client-payload: | |
| 104 | + { |
| 105 | + "repo": { |
| 106 | + "owner": "${{ github.repository_owner }}", |
| 107 | + "repo": "${{ github.event.repository.name }}" |
| 108 | + }, |
| 109 | + "artifact_id": "${{ steps.get-artifact-id.outputs.result }}" |
| 110 | + } |
0 commit comments