From 291572a4f33746f6ddc44d3edb9e18ea8b250a00 Mon Sep 17 00:00:00 2001 From: ForestL18 <45709305+ForestL18@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:37:05 +0800 Subject: [PATCH] Add auto increment version and local properties --- .github/workflows/build-pre-release.yaml | 39 +++++++++++++++++++++++- .github/workflows/build-release.yaml | 26 +++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-pre-release.yaml b/.github/workflows/build-pre-release.yaml index 9ad6243bac..77152e1852 100644 --- a/.github/workflows/build-pre-release.yaml +++ b/.github/workflows/build-pre-release.yaml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v4 - + - name: Checkout submodules run: git submodule update --init --recursive --force @@ -44,6 +44,43 @@ jobs: sudo update-ca-certificates cp -f /etc/ssl/certs/ca-certificates.crt core/src/foss/golang/clash/component/ca/ca-certificates.crt + - name: Read and increment version from build.gradle.kts + id: process-version + run: | + # read version from build.gradle.kts + VERSION_NAME=$(grep -oP 'versionName\s*=\s*"\K[^"]+' build.gradle.kts) + VERSION_CODE=$(grep -oP 'versionCode\s*=\s*\K\d+' build.gradle.kts) + + echo "Current version: $VERSION_NAME ($VERSION_CODE)" + + # increment version + IFS='.' read -ra VERSION_PARTS <<< "$VERSION_NAME" + VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1)) + NEW_VERSION_NAME="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}" + NEW_VERSION_CODE=$((VERSION_CODE + 1)) + + echo "New version: $NEW_VERSION_NAME ($NEW_VERSION_CODE)" + + echo "versionName=$NEW_VERSION_NAME" >> $GITHUB_OUTPUT + echo "versionCode=$NEW_VERSION_CODE" >> $GITHUB_OUTPUT + + - name: Update build.gradle.kts with new version + run: | + sed -i "s/versionName = \".*\"/versionName = \"${{ steps.process-version.outputs.versionName }}\"/" build.gradle.kts + sed -i "s/versionCode = .*/versionCode = ${{ steps.process-version.outputs.versionCode }}/" build.gradle.kts + + - name: Local Properties + env: + CUSTOM_APPLICATION_ID: ${{ secrets.CUSTOM_APPLICATION_ID }} + REMOVE_SUFFIX: ${{ secrets.REMOVE_SUFFIX }} + run: | + touch local.properties + echo custom.application.id="$CUSTOM_APPLICATION_ID" >> local.properties + echo remove.suffix="$REMOVE_SUFFIX" >> local.properties + + echo "cat local.properties" + cat local.properties + - name: Signing properties env: SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml index f292cf7618..7413ab19d8 100644 --- a/.github/workflows/build-release.yaml +++ b/.github/workflows/build-release.yaml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: release-tag: - description: 'Release Tag (v2.x.x)' + description: "Release Tag (v2.x.x)" required: true jobs: @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - + - name: Checkout submodules run: git submodule update --init --recursive --force @@ -41,7 +41,7 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- - + - name: Convert and set version env id: process-version run: | @@ -49,10 +49,10 @@ jobs: VERSION_TAG=${VERSION_TAG#v} # remove the 'v' prefix IFS='.' read -ra VERSION_PARTS <<< "$VERSION_TAG" # split into array VERSION_CODE=$(printf "%1d%02d%03d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}") - + echo "versonName=$VERSION_TAG" >> $GITHUB_OUTPUT # "1.2.3" echo "versonCode=$VERSION_CODE" >> $GITHUB_OUTPUT # "102003" - + # Re-write version in build.gradle.kts - name: Re-write version uses: Devofure/advance-android-version-actions@v1.5 @@ -60,7 +60,7 @@ jobs: gradlePath: build.gradle.kts versionCode: ${{ steps.process-version.outputs.versonCode }} versionName: ${{ steps.process-version.outputs.versonName }} - + # If any change found, commit it and push - name: Commit and push if changes run: | @@ -83,6 +83,18 @@ jobs: sudo update-ca-certificates cp -f /etc/ssl/certs/ca-certificates.crt core/src/foss/golang/clash/component/ca/ca-certificates.crt + - name: Local Properties + env: + CUSTOM_APPLICATION_ID: ${{ secrets.CUSTOM_APPLICATION_ID }} + REMOVE_SUFFIX: ${{ secrets.REMOVE_SUFFIX }} + run: | + touch local.properties + echo custom.application.id="$CUSTOM_APPLICATION_ID" >> local.properties + echo remove.suffix="$REMOVE_SUFFIX" >> local.properties + + echo "cat local.properties" + cat local.properties + - name: Signing properties env: SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} @@ -124,4 +136,4 @@ jobs: "ignore_labels": [ "Update" ], - } \ No newline at end of file + }