Skip to content

Commit c22530f

Browse files
committed
feat: add version bump actions
1 parent 33cbef7 commit c22530f

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

.github/workflows/versionBump.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Bump App Version
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
type:
6+
description: 'Bump type'
7+
required: true
8+
default: 'patch'
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
releaseNote:
15+
description: 'Release Note'
16+
required: true
17+
type: string
18+
19+
jobs:
20+
bump:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: 🏗 Bump App Version
26+
id: bump-app-version
27+
run: |
28+
newVersion=$(bash ./scripts/versionBump.sh $TYPE "$RELEASE_NOTES")
29+
echo "::newVersion::$newVersion"
30+
echo "newVersion=$newVersion" >> "$GITHUB_OUTPUT"
31+
env:
32+
TYPE: ${{ inputs.type }}
33+
RELEASE_NOTES: ${{ inputs.releaseNote }}
34+
35+
- name: Git Add and Commit
36+
run: |
37+
git config --global user.name 'Yogesh Choudhary Paliyal'
38+
git config --global user.email '[email protected]'
39+
git add .
40+
git commit -am "Github Actions: App version Bumped to ${{ steps.bump-app-version.outputs.newVersion }}"
41+
42+
- name: Print newVersion
43+
run: echo "${{ steps.bump-app-version.outputs.newVersion }}"
44+
45+
- name: Build Release AAB
46+
id: buildFreeRelease
47+
run: ./gradlew bundleRelease
48+
49+
- name: Sign Release AAB
50+
id: signPro
51+
uses: r0adkll/sign-android-release@fix/bundle-signing
52+
with:
53+
releaseDirectory: app/build/outputs/bundle/release
54+
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
55+
alias: ${{ secrets.ALIAS }}
56+
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
57+
keyPassword: ${{ secrets.KEY_PASSWORD }}
58+
59+
- name: Push to protected branch
60+
uses: CasperWA/push-protected@v2
61+
with:
62+
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
63+
branch: master
64+
unprotect_reviews: true
65+
66+
- name: Git push tag
67+
run: |
68+
git tag -a ${{ steps.bump-app-version.outputs.newVersion }} -m "Release version ${{ steps.bump-app-version.outputs.newVersion }}"
69+
git push origin ${{ steps.bump-app-version.outputs.newVersion }}
70+
71+
- name: Rename aab names
72+
run: |
73+
mv app/build/outputs/bundle/release/app-release.aab app/build/outputs/bundle/release/deepr-release-${{steps.bump-app-version.outputs.newVersion}}.aab
74+
75+
- name: Create Release
76+
uses: ncipollo/[email protected]
77+
with:
78+
tag: "${{ steps.bump-app-version.outputs.newVersion }}"
79+
generateReleaseNotes: true
80+
commit: "master"
81+
artifacts: "app/build/outputs/bundle/release/deepr-release-${{steps.bump-app-version.outputs.newVersion}}.aab"
82+
discussionCategory: "Release feedbacks"
83+
makeLatest: true
84+
85+
- uses: snnaplab/universal-apk-generate-action@v1
86+
id: apk-release-generate
87+
with:
88+
aab-path: 'app/build/outputs/bundle/release/deepr-release-${{steps.bump-app-version.outputs.newVersion}}.aab'
89+
keystore-base64: ${{ secrets.SIGNING_KEY }}
90+
keystore-password: ${{ secrets.KEY_STORE_PASSWORD }}
91+
key-alias: ${{ secrets.ALIAS }}
92+
key-password: ${{ secrets.KEY_PASSWORD }}
93+
94+
- name: Upload binaries to github release
95+
uses: svenstaro/upload-release-action@v2
96+
with:
97+
repo_token: ${{ secrets.GITHUB_TOKEN }}
98+
file: ${{ steps.apk-free-generate.outputs.apk-path }}
99+
asset_name: 'deepr-release-${{steps.bump-app-version.outputs.newVersion}}.apk'
100+
tag: ${{ steps.bump-app-version.outputs.newVersion }}
101+
overwrite: true

scripts/versionBump.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
INCREMENT_MODE=$1 # major, minor, and patch
4+
RELEASE_NOTES=$2 # String files
5+
6+
# Read the current versionCode and versionName from the build.gradle.kts.kts file
7+
VERSION_CODE=$(grep "versionCode " app/build.gradle.kts | awk '{print $3}' | tr -d '\r''"')
8+
VERSION_NAME=$(grep "versionName " app/build.gradle.kts | awk '{print $3}' | tr -d '\r''"')
9+
10+
11+
# Split the versionName into major, minor, and patch numbers
12+
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION_NAME"
13+
14+
MAJOR=${VERSION_PARTS[0]}
15+
MINOR=${VERSION_PARTS[1]}
16+
PATCH=${VERSION_PARTS[2]}
17+
18+
#echo "$VERSION_CODE"
19+
20+
# Increment the appropriate version number based on the input type
21+
case $INCREMENT_MODE in
22+
"major") ((MAJOR++)); MINOR=0; PATCH=0;;
23+
"minor") ((MINOR++)); PATCH=0;;
24+
"patch") ((PATCH++));;
25+
*) echo "Invalid type: $INCREMENT_MODE"; exit 1;;
26+
esac
27+
28+
# Construct the new versionCode and versionName values
29+
NEW_VERSION_CODE=$((VERSION_CODE + 1))
30+
NEW_VERSION_NAME="$MAJOR.$MINOR.$PATCH"
31+
32+
# Update the build.gradle.kts.kts file with the new versionCode and versionName values
33+
sed -i "s/versionCode = $VERSION_CODE/versionCode = $NEW_VERSION_CODE/" app/build.gradle.kts
34+
sed -i "s/versionName = \"$VERSION_NAME\"/versionName = \"$NEW_VERSION_NAME\"/" app/build.gradle.kts
35+
36+
# Output the new versionCode and versionName values
37+
#echo "New versionCode: $NEW_VERSION_CODE"
38+
echo "$RELEASE_NOTES" > whatsnew/whatsnew-en-US
39+
echo "$RELEASE_NOTES" > fastlane/metadata/android/en-US/changelogs/${NEW_VERSION_CODE}.txt
40+
41+
echo "v$NEW_VERSION_NAME"
42+

0 commit comments

Comments
 (0)