|
| 1 | +name: Push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - development |
| 8 | + |
| 9 | +env: |
| 10 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + branch: ${{ steps.branch-name.outputs.current_branch }} |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Download repository |
| 20 | + uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Setup Java |
| 23 | + uses: actions/setup-java@v2 |
| 24 | + with: |
| 25 | + distribution: 'adopt' |
| 26 | + java-version: '11' |
| 27 | + |
| 28 | + - name: Build with Gradle |
| 29 | + run: | |
| 30 | + bash ./gradlew build --stacktrace |
| 31 | + bash ./gradlew bundle --stacktrace |
| 32 | + |
| 33 | + - name: Store APK files |
| 34 | + uses: actions/upload-artifact@v2 |
| 35 | + with: |
| 36 | + name: apk-files |
| 37 | + path: | |
| 38 | + app/build/outputs/apk/debug/app-debug.apk |
| 39 | + app/build/outputs/apk/release/app-release-unsigned.apk |
| 40 | + app/build/outputs/bundle/debug/app-debug.aab |
| 41 | + app/build/outputs/bundle/release/app-release.aab |
| 42 | + |
| 43 | + - name: Define branch |
| 44 | + id: branch-name |
| 45 | + run: echo "::set-output name=current_branch::${{ github.ref_name }}" |
| 46 | + |
| 47 | + upload: |
| 48 | + needs: build |
| 49 | + runs-on: ubuntu-latest |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Clone APK branch |
| 53 | + uses: actions/checkout@v2 |
| 54 | + with: |
| 55 | + repository: fossasia/pslab-android |
| 56 | + ref: apk |
| 57 | + |
| 58 | + - name: Clean APK branch for master builds |
| 59 | + if: ${{ needs.build.outputs.branch == 'master' }} |
| 60 | + run: | |
| 61 | + rm -rf app-debug-master.apk || true |
| 62 | + rm -rf app-release-unsigned-master.apk || true |
| 63 | + rm -rf app-debug-master.aab || true |
| 64 | + rm -rf app-release-master.aab || true |
| 65 | + |
| 66 | + - name: Clean APK branch for development builds |
| 67 | + if: ${{ needs.build.outputs.branch == 'development' }} |
| 68 | + run: | |
| 69 | + rm -rf app-debug-development.apk || true |
| 70 | + rm -rf app-release-unsigned-development.apk || true |
| 71 | + rm -rf app-debug-development.aab || true |
| 72 | + rm -rf app-release-development.aab || true |
| 73 | +
|
| 74 | + - name: Retrieve APK files |
| 75 | + uses: actions/download-artifact@v2 |
| 76 | + with: |
| 77 | + name: apk-files |
| 78 | + |
| 79 | + - name: Rename files in master branch |
| 80 | + if: ${{ needs.build.outputs.branch == 'master' }} |
| 81 | + run: | |
| 82 | + mv apk/debug/app-debug.apk app-debug-master.apk |
| 83 | + mv apk/release/app-release-unsigned.apk app-release-unsigned-master.apk |
| 84 | + mv bundle/debug/app-debug.aab app-debug-master.aab |
| 85 | + mv bundle/release/app-release.aab app-release-master.aab |
| 86 | + |
| 87 | + - name: Rename files in development branch |
| 88 | + if: ${{ needs.build.outputs.branch == 'development' }} |
| 89 | + run: | |
| 90 | + mv apk/debug/app-debug.apk app-debug-development.apk |
| 91 | + mv apk/release/app-release-unsigned.apk app-release-unsigned-development.apk |
| 92 | + mv bundle/debug/app-debug.aab app-debug-development.aab |
| 93 | + mv bundle/release/app-release.aab app-release-development.aab |
| 94 | + |
| 95 | + - name: Setup credentials |
| 96 | + run: | |
| 97 | + git config user.name 'github-actions[bot]' |
| 98 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 99 | + |
| 100 | + - name: Update APK branch |
| 101 | + run: | |
| 102 | + git remote set-url --push origin https://github-actions[bot]:$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY} |
| 103 | + git checkout --orphan temporary |
| 104 | + git add . |
| 105 | + git commit -m "release: build files from ${{ needs.build.outputs.branch }} branch" |
| 106 | + git branch -D apk |
| 107 | + git branch -m apk |
| 108 | + git push origin apk -f --quiet > /dev/null |
| 109 | +
|
0 commit comments