@@ -3,7 +3,6 @@ permissions:
33 contents : write
44on :
55 workflow_dispatch :
6- inputs :
76 changes_in_release :
87 description : ' Changes in release'
98 required : true
1716 steps :
1817 - name : Checkout repository
1918 uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0 # Important: get all tags!
21+
22+ - name : Get Latest Tag
23+ run : |
24+ latest_tag=$(git describe --tags --abbrev=0)
25+ echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV
26+
27+ - name : Generate Version
28+ run : |
29+ # Extract version components
30+ version_base="${LATEST_TAG#v}"
31+ major=$(echo $version_base | cut -d. -f1)
32+ minor=$(echo $version_base | cut -d. -f2)
33+ patch=$(echo $version_base | cut -d. -f3)
34+
35+ # Increment versions by the specified input values
36+ new_major=$((major + ${{ github.event.inputs.increment_major }}))
37+ new_minor=$((minor + ${{ github.event.inputs.increment_minor }}))
38+ new_patch=$((patch + ${{ github.event.inputs.increment_patch }}))
39+
40+ # Construct the new version string
41+ new_version="$major.$minor.$new_patch"
42+
43+ # Calculate the version code (e.g., 1.0.5 -> 10005)
44+ version_code=$((major * 10000 + minor * 100 + new_patch))
45+
46+ # Set environment variables
47+ echo "NEW_VERSION_NAME=${new_version}" >> $GITHUB_ENV
48+ echo "NEW_VERSION_CODE=${version_code}" >> $GITHUB_ENV
49+
50+ - name : Update build.gradle with new version code and version name
51+ run : |
52+ # Update versionCode and versionName in build.gradle
53+ sed -i "s/versionCode [0-9]\+/versionCode ${NEW_VERSION_CODE}/" app/build.gradle
54+ sed -i "s/versionName \"[^\"]*\"/versionName \"${NEW_VERSION_NAME}\"/" app/build.gradle
55+
56+ - name : Print Version
57+ run : |
58+ echo "Version Name: $NEW_VERSION_NAME"
59+ echo "Version Code: $NEW_VERSION_CODE"
2060
2161 - name : Set up JDK 21
2262 uses : actions/setup-java@v4
0 commit comments