From ecf52b68ca8819f1c0d51a71c5284e5283e95352 Mon Sep 17 00:00:00 2001 From: HeroBrine1st Erquilenne Date: Wed, 4 Sep 2024 18:19:46 +0300 Subject: [PATCH] Add github release action --- .github/workflows/publish-release.yml | 76 +++++++++++++++++++++++++++ app/build.gradle.kts | 13 ++++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-release.yml diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 00000000..c5891d0d --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,76 @@ +#file: noinspection SpellCheckingInspection +name: Publish release + +on: + push: + tags: + - "*" + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: # fix git tag --format=... showing commit message instead of tag message + fetch-depth: 1 # despite being the default, it allows checking out a tag + ref: ${{ github.ref }} + - name: Abort if tag is not annotated + run: | + tag_type=$(git cat-file -t $GITHUB_REF) + if [ "$tag_type" != "tag" ]; then # if not annotated, tag_type is "commit" + echo "The tag $GITHUB_REF_NAME is not annotated. Aborting job." + exit 1 + fi + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Set up android SDK + uses: android-actions/setup-android@v2 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-version: wrapper + - name: Run tests + run: ./gradlew testReleaseUnitTest + - name: Decode Keystore + env: + ENCODED_STRING: ${{ secrets.KEYSTORE }} + run: | + echo $ENCODED_STRING | base64 -di > app/keystore.jks + - name: Show signing report + env: + SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} + SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} + SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} + run: ./gradlew signingReport + - name: Build release APK + env: + SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} + SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} + SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} + run: ./gradlew :app:assembleRelease + - name: Clean up + if: ${{ !cancelled() }} + run: rm app/keystore.jks + - name: Make directory for release files + run: mkdir ./dist + - name: Compress proguard mappings + run: tar -C app/build/outputs/mapping/release -c . | zstd --ultra --long -22 -T0 > ./dist/proguard-mappings.tar.zst + - name: Rename apk + run: mv app/build/outputs/apk/release/app-release.apk ./dist/e621-$GITHUB_REF_NAME.apk + - name: Fetch release notes + run: git tag -l --format="%(contents)" $GITHUB_REF_NAME | tee ./release.txt + - name: Publish release + uses: softprops/action-gh-release@v2 + with: + files: | + ./dist/** + fail_on_unmatched_files: true + make_latest: true + body_path: "./release.txt" + generate_release_notes: true \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e49ef6a3..61428591 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -41,7 +41,17 @@ android { "%s/%s (Android/%s; %s build; +https://github.com/HeroBrine1st/E621) Ktor/${libs.versions.ktor.get()}" ) } - + signingConfigs { + create("release") { + storeFile = file("keystore.jks") + storePassword = System.getenv("SIGNING_STORE_PASSWORD") + keyAlias = System.getenv("SIGNING_KEY_ALIAS") + keyPassword = System.getenv("SIGNING_KEY_PASSWORD") + + // Apk will be in app/build/outputs/apk/release/app-release.apk + // or app-release-unsigned.apk, if unsigned + } + } buildTypes { release { isMinifyEnabled = true @@ -50,6 +60,7 @@ android { "proguard-rules.pro", "intellij-idea-does-not-like-these-proguard-rules.pro" ) + signingConfig = signingConfigs.getByName("release") } debug { applicationIdSuffix = ".debug"