Skip to content

Commit

Permalink
version codes
Browse files Browse the repository at this point in the history
  • Loading branch information
shocknet-justin committed Sep 12, 2024
1 parent fd4df33 commit a4a5519
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
VITE_KEYLINK_APP_ID=2ff35dfeb1448156e4f4057899cff2b3aa7679914565ce80e2f8fc45dfe61e4e
VITE_ANDROID_APPLICATION_ID=app.shockwallet.test
1 change: 1 addition & 0 deletions .env.production.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ ios/App/App/App.entitlements
act
event.json
run.log
android_key.base64
34 changes: 34 additions & 0 deletions preBuild/preBuild.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');

0 comments on commit a4a5519

Please sign in to comment.