This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
โ๏ธ GitHub Action | Add Increment Version Code Logic (#52) #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Increment Version, and Upload to Firebase App Distribution | |
on: | |
push: | |
branches: | |
- develop | |
workflow_dispatch: | |
jobs: | |
increment_version_code: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Update version code | |
id: update_version_code | |
run: | | |
# Get the current versionCode from build.gradle | |
VERSION_CODE=$(grep versionCode presentation/build.gradle | sed 's/[^0-9]*//g') | |
# Increment the versionCode | |
NEW_VERSION_CODE=$((VERSION_CODE + 1)) | |
# Replace the old versionCode with the new one in build.gradle | |
sed -i "s/versionCode $VERSION_CODE/versionCode $NEW_VERSION_CODE/" presentation/build.gradle | |
# Check if there are changes to commit | |
if [ $(git status --porcelain | wc -l) -gt 0 ]; then | |
git config --global user.name "${{ secrets.GIT_USER_NAME }}" | |
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" | |
git checkout -b version-update | |
git commit -am "[GitHub Action] Increment versionCode to $NEW_VERSION_CODE" | |
echo "::set-output name=changed::true" | |
else | |
echo "::set-output name=changed::false" | |
fi | |
- name: Push changes | |
if: steps.update_version_code.outputs.changed == 'true' | |
run: | | |
git push origin version-update | |
merge_version_update: | |
runs-on: ubuntu-latest | |
needs: increment_version_code | |
if: needs.increment_version_code.outputs.changed == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Merge version-update branch | |
run: | | |
git fetch origin | |
git checkout develop | |
git merge origin/version-update | |
git push origin develop | |
build_and_upload: | |
runs-on: ubuntu-latest | |
needs: merge_version_update | |
if: needs.merge_version_update.result == 'success' | |
env: | |
LOCAL_PROPERTIES_CONTENTS: ${{ secrets.LOCAL_PROPERTIES_CONTENTS }} | |
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./Nabi/gradlew | |
- name: Decode and save keystore | |
run: echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > ./Nabi/presentation/keystore.jks | |
- name: Verify keystore | |
run: | | |
ls -alh ./Nabi/presentation/ | |
echo "Checking JKS format..." | |
keytool -list -v -keystore ./Nabi/presentation/keystore.jks -storetype JKS || echo "JKS format verification failed" | |
- name: Create google-services.json | |
run: echo "$GOOGLE_SERVICES_JSON" > ./Nabi/presentation/google-services.json | |
- name: Create local.properties | |
run: echo "$LOCAL_PROPERTIES_CONTENTS" > ./Nabi/local.properties | |
- name: Build release APK | |
run: | | |
cd ./Nabi | |
./gradlew assembleRelease | |
- name: Upload to Firebase App Distribution | |
uses: wzieba/Firebase-Distribution-Github-Action@v1 | |
with: | |
appId: ${{ secrets.FIREBASE_APP_ID }} | |
serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} | |
groups: nabi-team | |
file: ./Nabi/presentation/build/outputs/apk/release/Nabi-release.apk |