Skip to content

Commit 291572a

Browse files
committed
Add auto increment version and local properties
1 parent b93319b commit 291572a

2 files changed

Lines changed: 57 additions & 8 deletions

File tree

.github/workflows/build-pre-release.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- name: Checkout Repository
1313
uses: actions/checkout@v4
14-
14+
1515
- name: Checkout submodules
1616
run: git submodule update --init --recursive --force
1717

@@ -44,6 +44,43 @@ jobs:
4444
sudo update-ca-certificates
4545
cp -f /etc/ssl/certs/ca-certificates.crt core/src/foss/golang/clash/component/ca/ca-certificates.crt
4646
47+
- name: Read and increment version from build.gradle.kts
48+
id: process-version
49+
run: |
50+
# read version from build.gradle.kts
51+
VERSION_NAME=$(grep -oP 'versionName\s*=\s*"\K[^"]+' build.gradle.kts)
52+
VERSION_CODE=$(grep -oP 'versionCode\s*=\s*\K\d+' build.gradle.kts)
53+
54+
echo "Current version: $VERSION_NAME ($VERSION_CODE)"
55+
56+
# increment version
57+
IFS='.' read -ra VERSION_PARTS <<< "$VERSION_NAME"
58+
VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1))
59+
NEW_VERSION_NAME="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
60+
NEW_VERSION_CODE=$((VERSION_CODE + 1))
61+
62+
echo "New version: $NEW_VERSION_NAME ($NEW_VERSION_CODE)"
63+
64+
echo "versionName=$NEW_VERSION_NAME" >> $GITHUB_OUTPUT
65+
echo "versionCode=$NEW_VERSION_CODE" >> $GITHUB_OUTPUT
66+
67+
- name: Update build.gradle.kts with new version
68+
run: |
69+
sed -i "s/versionName = \".*\"/versionName = \"${{ steps.process-version.outputs.versionName }}\"/" build.gradle.kts
70+
sed -i "s/versionCode = .*/versionCode = ${{ steps.process-version.outputs.versionCode }}/" build.gradle.kts
71+
72+
- name: Local Properties
73+
env:
74+
CUSTOM_APPLICATION_ID: ${{ secrets.CUSTOM_APPLICATION_ID }}
75+
REMOVE_SUFFIX: ${{ secrets.REMOVE_SUFFIX }}
76+
run: |
77+
touch local.properties
78+
echo custom.application.id="$CUSTOM_APPLICATION_ID" >> local.properties
79+
echo remove.suffix="$REMOVE_SUFFIX" >> local.properties
80+
81+
echo "cat local.properties"
82+
cat local.properties
83+
4784
- name: Signing properties
4885
env:
4986
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}

.github/workflows/build-release.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
release-tag:
7-
description: 'Release Tag (v2.x.x)'
7+
description: "Release Tag (v2.x.x)"
88
required: true
99

1010
jobs:
@@ -15,7 +15,7 @@ jobs:
1515
uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
18-
18+
1919
- name: Checkout submodules
2020
run: git submodule update --init --recursive --force
2121

@@ -41,26 +41,26 @@ jobs:
4141
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
4242
restore-keys: |
4343
${{ runner.os }}-go-
44-
44+
4545
- name: Convert and set version env
4646
id: process-version
4747
run: |
4848
VERSION_TAG=${{ inputs.release-tag }}
4949
VERSION_TAG=${VERSION_TAG#v} # remove the 'v' prefix
5050
IFS='.' read -ra VERSION_PARTS <<< "$VERSION_TAG" # split into array
5151
VERSION_CODE=$(printf "%1d%02d%03d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}")
52-
52+
5353
echo "versonName=$VERSION_TAG" >> $GITHUB_OUTPUT # "1.2.3"
5454
echo "versonCode=$VERSION_CODE" >> $GITHUB_OUTPUT # "102003"
55-
55+
5656
# Re-write version in build.gradle.kts
5757
- name: Re-write version
5858
uses: Devofure/advance-android-version-actions@v1.5
5959
with:
6060
gradlePath: build.gradle.kts
6161
versionCode: ${{ steps.process-version.outputs.versonCode }}
6262
versionName: ${{ steps.process-version.outputs.versonName }}
63-
63+
6464
# If any change found, commit it and push
6565
- name: Commit and push if changes
6666
run: |
@@ -83,6 +83,18 @@ jobs:
8383
sudo update-ca-certificates
8484
cp -f /etc/ssl/certs/ca-certificates.crt core/src/foss/golang/clash/component/ca/ca-certificates.crt
8585
86+
- name: Local Properties
87+
env:
88+
CUSTOM_APPLICATION_ID: ${{ secrets.CUSTOM_APPLICATION_ID }}
89+
REMOVE_SUFFIX: ${{ secrets.REMOVE_SUFFIX }}
90+
run: |
91+
touch local.properties
92+
echo custom.application.id="$CUSTOM_APPLICATION_ID" >> local.properties
93+
echo remove.suffix="$REMOVE_SUFFIX" >> local.properties
94+
95+
echo "cat local.properties"
96+
cat local.properties
97+
8698
- name: Signing properties
8799
env:
88100
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
@@ -124,4 +136,4 @@ jobs:
124136
"ignore_labels": [
125137
"Update"
126138
],
127-
}
139+
}

0 commit comments

Comments
 (0)