From 135a7c2f56d44938129f7177933abccd09ba0f93 Mon Sep 17 00:00:00 2001 From: owo233 Date: Wed, 13 Dec 2023 01:23:40 +0800 Subject: [PATCH] =?UTF-8?q?`Shamrock`:=20=E4=BC=98=E5=8C=96=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-apk.yml | 36 +++++++++++----- .github/workflows/codeql.yml | 57 ------------------------- .github/workflows/release.yml | 73 --------------------------------- app/build.gradle.kts | 52 ++++++++++++++++------- 4 files changed, 62 insertions(+), 156 deletions(-) delete mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build-apk.yml b/.github/workflows/build-apk.yml index da09bf0..d08766a 100644 --- a/.github/workflows/build-apk.yml +++ b/.github/workflows/build-apk.yml @@ -13,24 +13,38 @@ on: jobs: build: - name: Build APK + name: Build Shamrock runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v4.0.0 with: - distribution: "temurin" + fetch-depth: 0 + + - name: Setup JDK 17 + uses: actions/setup-java@v4.0.0 + with: java-version: 17 - cache: 'gradle' + distribution: "adopt" - - name: Setup cmake - run: | - echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "cmake;3.22.1" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null - echo "sdk.dir=${ANDROID_HOME}" > local.properties + - name: Cache Gradle Dependencies + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + !~/.gradle/caches/build-cache-* + key: gradle-deps-core-${{ hashFiles('**/build.gradle.kts') }} + restore-keys: gradle-deps - - name: Setup Gradle - uses: gradle/gradle-build-action@v2.10.0 + - name: Cache Gradle Build + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches/build-cache-* + ~/.gradle/buildOutputCleanup/cache.properties + key: gradle-builds-core-${{ github.sha }} + restore-keys: gradle-builds - name: Build with Gradle run: | @@ -83,4 +97,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: "${{ env.SHAMROCK_VERSION_x86_64 }}" - path: "${{ env.APK_FILE_X86_64 }}" + path: "${{ env.APK_FILE_X86_64 }}" \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 83e49e3..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - schedule: - - cron: '24 7 * * 4' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - timeout-minutes: 360 - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'cpp', 'java' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3.6.0 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Setup JDK 17 - uses: actions/setup-java@v3.12.0 - with: - distribution: "temurin" - java-version: 17 - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2.8.0 - - - name: Setup cmake - run: | - echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "cmake;3.22.1" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null - echo "sdk.dir=${ANDROID_HOME}" > local.properties - - - name: Build - run: | - chmod +x ./gradlew - ./gradlew :app:assembleAppRelease - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 79e1eff..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Shamrock Release - -on: - push: - tags: - - 'v*' - -jobs: - build: - name: Release - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: 17 - cache: 'gradle' - - - name: Setup cmake - run: | - echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "cmake;3.22.1" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null - echo "sdk.dir=${ANDROID_HOME}" > local.properties - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2.9.0 - - - name: Build with Gradle - run: | - echo ${{ secrets.SIGN_KEYSTORE_BASE64 }} | base64 -d > keystore.jks - chmod +x ./gradlew - ./gradlew :app:assembleRelease --build-cache --parallel --daemon --warning-mode all --stacktrace - echo "APK_FILE_ALL=$(find app/build/outputs/apk/app/release -name '*.apk')" >> $GITHUB_ENV - echo "APK_FILE_ARM64=$(find app/build/outputs/apk/arm64/release -name '*.apk')" >> $GITHUB_ENV - echo "APK_FILE_X86_64=$(find app/build/outputs/apk/x64/release -name '*.apk')" >> $GITHUB_ENV - env: - KEYSTORE_PATH: "../keystore.jks" - KEYSTORE_PASSWORD: ${{ secrets.SIGN_KEYSTORE_PASSWORD }} - KEY_ALIAS: ${{ secrets.SIGN_ALIAS }} - KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }} - - - name: Install aapt - run: sudo apt-get update && sudo apt-get install -y aapt - - - name: Set Shamrock Version - run: | - apk_file=${{ env.APK_FILE_ALL }} - apk_dump=$(aapt dump badging "$apk_file") - version_name=$(sed -n "s/.*versionName='\([^']*\)'.*/\1/p" <<< "$apk_dump") - echo "SHAMROCK_VERSION=$version_name" >> $GITHUB_ENV - - - name: Show Artifacts SHA256 - run: | - echo "### Build Success :rocket:" >> $GITHUB_STEP_SUMMARY - echo "|ABI|SHA256|" >> $GITHUB_STEP_SUMMARY - echo "|:--------:|:----------|" >> $GITHUB_STEP_SUMMARY - all=($(sha256sum ${{ env.APK_FILE_ALL }})) - echo "|all|$all" >> $GITHUB_STEP_SUMMARY - arm64=($(sha256sum ${{ env.APK_FILE_ARM64 }})) - echo "|arm64|$arm64" >> $GITHUB_STEP_SUMMARY - x86_64=($(sha256sum ${{ env.APK_FILE_X86_64 }})) - echo "|x86_64|$x86_64" >> $GITHUB_STEP_SUMMARY - - - name: Release - uses: marvinpinto/action-automatic-releases@latest - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - automatic_release_tag: Shamrock v${{ env.SHAMROCK_VERSION }} - files: | - ${{ env.APK_FILE_ALL }} - ${{ env.APK_FILE_ARM64 }} - ${{ env.APK_FILE_X86_64 }} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f410d0c..dbcc815 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,12 +1,5 @@ import com.android.build.api.dsl.ApplicationExtension - -fun gitCommitHash(): String { - val builder = ProcessBuilder("git", "rev-parse", "--short", "HEAD") - val process = builder.start() - val reader = process.inputReader() - val hash = reader.readText().trim() - return if (hash.isNotEmpty()) ".$hash" else "" -} +import java.io.ByteArrayOutputStream plugins { id("com.android.application") @@ -17,19 +10,20 @@ plugins { android { namespace = "moe.fuqiuluo.shamrock" ndkVersion = "25.1.8937393" - compileSdk = 33 + compileSdk = 34 defaultConfig { applicationId = "moe.fuqiuluo.shamrock" - minSdk = 24 - targetSdk = 33 - versionCode = (System.currentTimeMillis() / 1000).toInt() - versionName = "1.0.7-dev" + gitCommitHash() + minSdk = 27 + targetSdk = 34 + versionCode = getVersionCode() + versionName = "1.0.7" + ".r${getGitCommitCount()}." + getVersionName() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary = true } + @Suppress("UnstableApiUsage") externalNativeBuild { cmake { cppFlags += "" @@ -50,8 +44,7 @@ android { android.applicationVariants.all { outputs.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } .forEach { - val abi = it.outputFileName.split("-")[1].split(".apk")[0] - val abiName = when (abi) { + val abiName = when (val abi = it.outputFileName.split("-")[1].split(".apk")[0]) { "app" -> "all" "x64" -> "x86_64" else -> abi @@ -154,10 +147,39 @@ fun configureAppSigningConfigsForRelease(project: Project) { release { signingConfig = signingConfigs.findByName("release") } + debug { + signingConfig = signingConfigs.findByName("release") + } } } } +fun getGitCommitCount(): Int { + val out = ByteArrayOutputStream() + exec { + commandLine("git", "rev-list", "--count", "HEAD") + standardOutput = out + } + return out.toString().trim().toInt() +} + +fun getGitCommitHash(): String { + val out = ByteArrayOutputStream() + exec { + commandLine("git", "rev-parse", "--short", "HEAD") + standardOutput = out + } + return out.toString().trim() +} + +fun getVersionCode(): Int { + return (System.currentTimeMillis() / 1000L).toInt() +} + +fun getVersionName(): String { + return getGitCommitHash() +} + dependencies { implementation("androidx.core:core-ktx:1.9.0") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")