From a4a5519f40f31e02f60815aeb167f65d7431dff3 Mon Sep 17 00:00:00 2001 From: shocknet-justin <34176400+shocknet-justin@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:17:30 -0400 Subject: [PATCH] version codes --- .env.development.example | 3 ++- .env.production.example | 1 + .github/workflows/android-build.yml | 13 +++++++++-- .gitignore | 1 + preBuild/preBuild.ts | 34 +++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/.env.development.example b/.env.development.example index a902b5ea..32d56bf0 100644 --- a/.env.development.example +++ b/.env.development.example @@ -3,4 +3,5 @@ VITE_NOSTR_PUB_DESTINATION=e306c45ee0a7c772540f1dc88b00f79d2d3910bfd4047e9105849 VITE_DEFAULT_BRIDGE_URL=https://zap.page VITE_APP_URL=test.shockwallet.app VITE_SANCTUM_URL=https://test-auth.shock.network -VITE_KEYLINK_APP_ID=2ff35dfeb1448156e4f4057899cff2b3aa7679914565ce80e2f8fc45dfe61e4e \ No newline at end of file +VITE_KEYLINK_APP_ID=2ff35dfeb1448156e4f4057899cff2b3aa7679914565ce80e2f8fc45dfe61e4e +VITE_ANDROID_APPLICATION_ID=app.shockwallet.test \ No newline at end of file diff --git a/.env.production.example b/.env.production.example index 5ee53e09..b15a3f79 100644 --- a/.env.production.example +++ b/.env.production.example @@ -4,3 +4,4 @@ VITE_DEFAULT_BRIDGE_URL=https://shockwallet.app VITE_APP_URL=my.shockwallet.app VITE_SANCTUM_URL=https://auth.shock.network VITE_KEYLINK_APP_ID=81dcf7168a5de38247ee1a42855f499d077ef5fce79446b779f2bcb2a0e123be +VITE_ANDROID_APPLICATION_ID=app.shockwallet \ No newline at end of file diff --git a/.github/workflows/android-build.yml b/.github/workflows/android-build.yml index d37ae0ec..62ccb14e 100644 --- a/.github/workflows/android-build.yml +++ b/.github/workflows/android-build.yml @@ -14,7 +14,7 @@ env: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout code @@ -41,8 +41,17 @@ jobs: if: github.ref == 'refs/heads/main' run: cp .env.production.example .env + - name: Set VERSION and VERSION_CODE + run: | + if [[ ${{ github.event_name }} == 'release' ]]; then + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + else + echo "VERSION=test" >> $GITHUB_ENV + fi + echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV + - name: Run pre-build script - run: npm run prebuild + run: VERSION=${{ env.VERSION }} VERSION_CODE=${{ env.VERSION_CODE }} npm run prebuild - name: Build Android app run: ionic cap build android --no-interactive diff --git a/.gitignore b/.gitignore index e8182b09..420890e3 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ ios/App/App/App.entitlements act event.json run.log +android_key.base64 diff --git a/preBuild/preBuild.ts b/preBuild/preBuild.ts index 14a63c3f..e474dff9 100644 --- a/preBuild/preBuild.ts +++ b/preBuild/preBuild.ts @@ -1,6 +1,7 @@ // preBuild.js const fs = require('fs'); require('dotenv').config(); +const path = require('path'); // Read and modify the AndroidManifest.xml file const androidManifestPath = 'android/app/src/main/AndroidManifest.xml'; @@ -24,4 +25,37 @@ entitlements = entitlements.replace('${appUrl}', process.env.VITE_APP_URL); fs.writeFileSync(entitlementsPath, entitlements); +// Update the build.gradle file +function updateBuildGradle(version, versionCode, applicationId) { + const buildGradlePath = path.join(__dirname, '..', 'android', 'app', 'build.gradle'); + let buildGradle = fs.readFileSync(buildGradlePath, 'utf8'); + + buildGradle = buildGradle.replace( + /applicationId "[^"]+"/, + `applicationId "${applicationId}"` + ); + + buildGradle = buildGradle.replace( + /versionCode \d+/, + `versionCode ${versionCode}` + ); + + buildGradle = buildGradle.replace( + /versionName "[^"]+"/, + `versionName "${version}"` + ); + + buildGradle = buildGradle.replace( + /namespace "[^"]+"/, + `namespace "${applicationId}"` + ); + + fs.writeFileSync(buildGradlePath, buildGradle); +} + +const version = process.env.VERSION || '0.0.0'; +const versionCode = process.env.VERSION_CODE || '1'; +const applicationId = process.env.VITE_ANDROID_APPLICATION_ID || 'app.shockwallet.test'; +updateBuildGradle(version, versionCode, applicationId); + console.log('Pre-build script completed'); \ No newline at end of file