This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
โ๏ธ GitHub Action | Update Increment Version Code Logic #7
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 ./Nabi/presentation/build.gradle.kts | sed 's/[^0-9]*//g') | ||
echo "Current versionCode: $VERSION_CODE" | ||
# Increment the versionCode | ||
NEW_VERSION_CODE=$((VERSION_CODE + 1)) | ||
echo "New versionCode: $NEW_VERSION_CODE" | ||
# Replace the old versionCode with the new one in build.gradle | ||
sed -i "s/versionCode $VERSION_CODE/versionCode $NEW_VERSION_CODE/" ./Nabi/presentation/build.gradle.kts | ||
# 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 add ./Nabi/presentation/build.gradle.kts | ||
git commit -m "[GitHub Action] Increment versionCode to $NEW_VERSION_CODE" | ||
echo "changed=true" >> $GITHUB_ENV | ||
else | ||
echo "changed=false" >> $GITHUB_ENV | ||
fi | ||
- name: Show git status | ||
run: git status | ||
- name: Push changes | ||
if: env.changed == 'true' | ||
run: | | ||
echo "Pushing changes to version-update branch" | ||
git push origin version-update | ||
merge_version_update: | ||
runs-on: ubuntu-latest | ||
needs: increment_version_code | ||
if: env.changed == 'true' | ||
Check failure on line 61 in .github/workflows/versioning-and-deployment.yaml GitHub Actions / Build, Increment Version, and Upload to Firebase App DistributionInvalid workflow file
|
||
steps: | ||
- name: Checkout develop branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: develop | ||
fetch-depth: 0 | ||
- name: Configure Git | ||
run: | | ||
git config user.name "${{ secrets.GIT_USER_NAME }}" | ||
git config user.email "${{ secrets.GIT_USER_EMAIL }}" | ||
- name: Merge version-update branch | ||
run: | | ||
git fetch origin | ||
git checkout develop | ||
git merge origin/version-update --no-edit | ||
- name: Push changes to develop branch | ||
uses: ad-m/github-push-action@master | ||
with: | ||
branch: develop | ||
github_token: ${{ secrets.HUBGIT_TOKEN }} | ||
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: | | ||
echo "Granting execute permission for gradlew" | ||
chmod +x ./Nabi/gradlew | ||
- name: Decode and save keystore | ||
run: | | ||
echo "Decoding and saving keystore" | ||
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > ./Nabi/presentation/keystore.jks | ||
- name: Verify keystore | ||
run: | | ||
echo "Listing files in ./Nabi/presentation/" | ||
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 "Creating google-services.json" | ||
echo "$GOOGLE_SERVICES_JSON" > ./Nabi/presentation/google-services.json | ||
- name: Create local.properties | ||
run: | | ||
echo "Creating local.properties" | ||
echo "$LOCAL_PROPERTIES_CONTENTS" > ./Nabi/local.properties | ||
- name: Build release APK | ||
run: | | ||
echo "Building release APK" | ||
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 |