Skip to content

Commit 81c9418

Browse files
Surjit Kumar SahooSurjit Kumar Sahoo
authored andcommitted
fix: auto versioning
1 parent 97d779a commit 81c9418

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Auto Version Bump
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'gradle.properties'
9+
- '.github/workflows/**'
10+
11+
jobs:
12+
bump-version:
13+
runs-on: ubuntu-latest
14+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Get Current Version
23+
id: get_version
24+
run: |
25+
VERSION=$(grep 'appVersionName=' gradle.properties | cut -d'=' -f2)
26+
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
27+
28+
- name: Determine Bump Type
29+
id: bump_type
30+
uses: anothrNick/github-tag-action@1.67.0
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
WITH_V: false
34+
DRY_RUN: true
35+
DEFAULT_BUMP: patch
36+
37+
- name: Bump Version in Files
38+
id: bump
39+
run: |
40+
BUMP_TYPE="${{ steps.bump_type.outputs.part }}"
41+
if [ -z "$BUMP_TYPE" ]; then BUMP_TYPE="patch"; fi
42+
NEW_VERSION=$(python3 scripts/bump_version.py ${{ steps.get_version.outputs.current_version }} $BUMP_TYPE)
43+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
44+
45+
- name: Commit and Push Changes
46+
run: |
47+
NEW_TAG="v${{ steps.bump.outputs.new_version }}"
48+
git config --local user.email "action@github.com"
49+
git config --local user.name "GitHub Action"
50+
git add gradle.properties
51+
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
52+
git tag $NEW_TAG
53+
git push origin main
54+
git push origin $NEW_TAG

.github/workflows/build_app.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
name: Build Lissen App
1+
name: Build Kahani App
22

33
env:
44
# The name of the main module repository
55
main_project_module: app
66

77
on:
88
push:
9-
branches: [ "main" ]
9+
branches: ['main']
1010
pull_request:
11-
branches: [ "main" ]
11+
branches: ['main']
1212

1313
workflow_dispatch:
1414

1515
jobs:
1616
build:
17-
1817
runs-on: ubuntu-latest
1918

2019
steps:

.github/workflows/release.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ name: Build and Release Kahani
22

33
on:
44
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
5+
tags:
6+
- 'v*'
107
workflow_dispatch:
118

129
jobs:
@@ -42,8 +39,8 @@ jobs:
4239
uses: softprops/action-gh-release@v1
4340
with:
4441
files: app/build/outputs/apk/release/app-release.apk
45-
tag_name: v${{ github.run_number }}
46-
name: Release v${{ github.run_number }}
42+
tag_name: ${{ github.ref_name }}
43+
name: Release ${{ github.ref_name }}
4744
body: |
4845
Automated Release for Kahani.
4946
Commit: ${{ github.sha }}

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ android {
5353
applicationId = "org.surjit.kahani"
5454
minSdk = 28
5555
targetSdk = 36
56-
versionCode = 10000
57-
versionName = "1.0.0-${commitHash}"
56+
versionCode = project.property("appVersionCode").toString().toInt()
57+
versionName = project.property("appVersionName").toString()
5858

5959
buildConfigField("String", "GIT_HASH", "\"$commitHash\"")
6060

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
22
android.useAndroidX=true
33
kotlin.code.style=official
44
android.nonTransitiveRClass=true
5+
6+
appVersionName=1.0.0
7+
appVersionCode=10000

0 commit comments

Comments
 (0)