From 33a28f87a34e9dcf288aec284069ea75ab558fa7 Mon Sep 17 00:00:00 2001 From: Anillc Date: Fri, 19 Aug 2022 02:17:51 +0800 Subject: [PATCH] update workflow --- .github/workflows/release.yml | 59 ++++------------------------ .github/workflows/upload.yml | 72 +++++++++++++++++++++++++++++++++++ app/build.gradle.kts | 4 +- 3 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/upload.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b7fa07d..06219a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,62 +1,19 @@ -on: - release: - types: [created] - workflow_dispatch: +on: workflow_dispatch jobs: release: - strategy: - matrix: - build: - - name: koishi-android - copy: copy - - name: koishi-android-with-chromium - copy: copy-extra runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v15 - - - name: setup cachix - uses: cachix/cachix-action@v10 - with: - name: koishi - authToken: ${{ secrets.CACHIX_TOKEN }} - - - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: '11' - cache: gradle - - - name: Build + - name: Create release run: | - export COPY=${{ matrix.build.copy }} - ./build.sh - - - uses: ilharp/sign-android-release@v1 - name: Sign app APK - id: sign_app - with: - keyAlias: koishi-android - signingKey: ${{ secrets.JKS }} - keyStorePassword: ${{ secrets.JKS_PASSWORD }} - keyPassword: ${{ secrets.JKS_PASSWORD }} - - - name: Upload - run: | - RELEASE=$(curl \ + LATEST_RELEASE=$(curl \ -H 'Accept: application/vnd.github.v3+json' \ -H 'Authorization: token ${{ github.token }}' \ https://api.github.com/repos/${{ github.repository }}/releases/latest) - TAG=$(echo "$RELEASE" | jq -r '.tag_name') - UPLOAD_URL=$(echo "$RELEASE" | jq -r '.upload_url' | cut -d '{' -f 1) + LATEST_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name') + TAG=$(echo $LATEST_TAG | awk -F. '{ print $1 "." $2 "." ($3 + 1) }') curl -X POST \ -H 'Accept: application/vnd.github.v3+json' \ - -H 'Content-Type: octet-stream' \ - -H 'Authorization: token ${{ github.token }}' \ - --data-binary @${{steps.sign_app.outputs.signedFile}} \ - "$UPLOAD_URL?name=${{ matrix.build.name }}-$TAG.apk" + -H 'Authorization: token ${{ secrets.WORKFLOW_TOKEN }}' \ + https://api.github.com/repos/${{ github.repository }}/releases \ + -d "{\"tag_name\":\"$TAG\"}" diff --git a/.github/workflows/upload.yml b/.github/workflows/upload.yml new file mode 100644 index 0000000..910468d --- /dev/null +++ b/.github/workflows/upload.yml @@ -0,0 +1,72 @@ +on: + release: + types: + - created + workflow_dispatch: + +jobs: + upload: + strategy: + matrix: + build: + - name: koishi-android + copy: copy + - name: koishi-android-with-chromium + copy: copy-extra + runs-on: ubuntu-latest + steps: + - name: Set up variables + id: vars + run: | + RELEASE=$(curl \ + -H 'Accept: application/vnd.github.v3+json' \ + -H 'Authorization: token ${{ github.token }}' \ + https://api.github.com/repos/${{ github.repository }}/releases/latest) + TAG=$(echo "$RELEASE" | jq -r '.tag_name') + UPLOAD_URL=$(echo "$RELEASE" | jq -r '.upload_url' | cut -d '{' -f 1) + echo ::set-output name=TAG::$TAG + echo ::set-output name=UPLOAD_URL::$UPLOAD_URL + + - name: Checkout + uses: actions/checkout@v3 + + - name: Install nix + uses: cachix/install-nix-action@v15 + + - name: setup cachix + uses: cachix/cachix-action@v10 + with: + name: koishi + authToken: ${{ secrets.CACHIX_TOKEN }} + + - uses: actions/setup-java@v3 + with: + distribution: adopt + java-version: '11' + cache: gradle + + - name: Build + run: | + TAG=${{ steps.vars.outputs.TAG }} + export VERSION_CODE=$(echo "${TAG:1}" | sed 's/\.//g') + export VERSION_NAME=$TAG + export COPY=${{ matrix.build.copy }} + ./build.sh + + - uses: ilharp/sign-android-release@v1 + name: Sign app APK + id: sign_app + with: + keyAlias: koishi-android + signingKey: ${{ secrets.JKS }} + keyStorePassword: ${{ secrets.JKS_PASSWORD }} + keyPassword: ${{ secrets.JKS_PASSWORD }} + + - name: Upload + run: | + curl -X POST \ + -H 'Accept: application/vnd.github.v3+json' \ + -H 'Content-Type: octet-stream' \ + -H 'Authorization: token ${{ github.token }}' \ + --data-binary @${{steps.sign_app.outputs.signedFile}} \ + "${{ steps.vars.outputs.UPLOAD_URL }}?name=${{ matrix.build.name }}-${{ steps.vars.outputs.TAG }}.apk" diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bae306f..ed99ae7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,8 +10,8 @@ android { applicationId = "cn.anillc.koishi" minSdk = 24 targetSdk = 28 - versionCode = 1 - versionName = "0.0.1" + versionCode = System.getenv("VERSION_CODE")?.toIntOrNull() ?: 1 + versionName = System.getenv("VERSION_NAME") ?: "0.0.1" } buildFeatures {