|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - 'app/**' |
| 8 | + - 'module/**' |
| 9 | + - 'gradle/**' |
| 10 | + - 'build.gradle.kts' |
| 11 | + - 'settings.gradle.kts' |
| 12 | + - 'gradle.properties' |
| 13 | + - 'scripts/**' |
| 14 | + - '.github/workflows/build.yml' |
| 15 | + pull_request: |
| 16 | + branches: [master] |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + profile: [debug, release] |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - uses: actions/setup-java@v4 |
| 29 | + with: |
| 30 | + distribution: temurin |
| 31 | + java-version: 17 |
| 32 | + |
| 33 | + - uses: gradle/actions/setup-gradle@v4 |
| 34 | + |
| 35 | + - name: Build APK (${{ matrix.profile }}) |
| 36 | + run: | |
| 37 | + if [ "${{ matrix.profile }}" = "release" ]; then |
| 38 | + ./gradlew assembleRelease |
| 39 | + else |
| 40 | + ./gradlew assembleDebug |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Upload APK |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: apk-${{ matrix.profile }} |
| 47 | + path: app/build/outputs/apk/${{ matrix.profile }}/app-${{ matrix.profile }}.apk |
| 48 | + retention-days: 7 |
| 49 | + |
| 50 | + package: |
| 51 | + needs: build |
| 52 | + runs-on: ubuntu-latest |
| 53 | + strategy: |
| 54 | + matrix: |
| 55 | + profile: [debug, release] |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Download APK |
| 60 | + uses: actions/download-artifact@v4 |
| 61 | + with: |
| 62 | + name: apk-${{ matrix.profile }} |
| 63 | + path: apk/ |
| 64 | + |
| 65 | + - name: Read version |
| 66 | + id: ver |
| 67 | + run: echo "version=$(grep '^version=' module/module.prop | cut -d= -f2)" >> "$GITHUB_OUTPUT" |
| 68 | + |
| 69 | + - name: Package module ZIP |
| 70 | + run: | |
| 71 | + bash scripts/package.sh --apk=apk/app-${{ matrix.profile }}.apk |
| 72 | +
|
| 73 | + - name: Rename ZIP for profile |
| 74 | + run: | |
| 75 | + ver="${{ steps.ver.outputs.version }}" |
| 76 | + src="out/UsbMassStorage-${ver}.zip" |
| 77 | + if [ "${{ matrix.profile }}" = "debug" ]; then |
| 78 | + mv "$src" "out/UsbMassStorage-${ver}-debug.zip" |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Upload module ZIP |
| 82 | + uses: actions/upload-artifact@v4 |
| 83 | + with: |
| 84 | + name: module-${{ matrix.profile }} |
| 85 | + path: out/UsbMassStorage-*.zip |
| 86 | + retention-days: 30 |
| 87 | + |
| 88 | + release: |
| 89 | + needs: [build, package] |
| 90 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 91 | + runs-on: ubuntu-latest |
| 92 | + permissions: |
| 93 | + contents: write |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Read version |
| 98 | + id: ver |
| 99 | + run: echo "version=$(grep '^version=' module/module.prop | cut -d= -f2)" >> "$GITHUB_OUTPUT" |
| 100 | + |
| 101 | + - name: Download release ZIP |
| 102 | + uses: actions/download-artifact@v4 |
| 103 | + with: |
| 104 | + name: module-release |
| 105 | + path: zips/release/ |
| 106 | + |
| 107 | + - name: Download debug ZIP |
| 108 | + uses: actions/download-artifact@v4 |
| 109 | + with: |
| 110 | + name: module-debug |
| 111 | + path: zips/debug/ |
| 112 | + |
| 113 | + - name: Extract changelog |
| 114 | + id: notes |
| 115 | + run: | |
| 116 | + ver="${{ steps.ver.outputs.version }}" |
| 117 | + if [ -f CHANGELOG.md ]; then |
| 118 | + awk "/^## ${ver}/{flag=1; next} /^## v/{if(flag) exit} flag" CHANGELOG.md > /tmp/notes.md |
| 119 | + fi |
| 120 | + if [ ! -s /tmp/notes.md ]; then |
| 121 | + echo "Release ${ver}" > /tmp/notes.md |
| 122 | + fi |
| 123 | +
|
| 124 | + - name: Delete old release |
| 125 | + run: gh release delete "${{ steps.ver.outputs.version }}" --yes 2>/dev/null || true |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + |
| 129 | + - name: Create release |
| 130 | + run: | |
| 131 | + gh release create "${{ steps.ver.outputs.version }}" \ |
| 132 | + --title "${{ steps.ver.outputs.version }}" \ |
| 133 | + --notes-file /tmp/notes.md \ |
| 134 | + --latest \ |
| 135 | + zips/release/*.zip \ |
| 136 | + zips/debug/*.zip |
| 137 | + env: |
| 138 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments