Add CD for android live update

This commit is contained in:
MartinBraquet
2025-12-14 23:05:23 +02:00
parent d699ceae38
commit 0d026d36d1
5 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
name: CD API
on:
push:
branches: [ main, master ]
paths:
- "android/capawesome.json"
- ".github/workflows/cd-android-live-update.yml"
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # we need full history for git log
- name: Install jq
run: sudo apt-get install -y jq
- name: Read current version
id: current
run: |
current=$(jq -r '.version' android/capawesome.json)
echo "version=$current" >> $GITHUB_OUTPUT
- name: Read previous version
id: previous
run: |
# Get previous commits package.json (if it existed)
if git show HEAD^:android/capawesome.json >/dev/null 2>&1; then
previous=$(git show HEAD^:android/capawesome.json | jq -r '.version')
else
previous="none"
fi
echo "version=$previous" >> $GITHUB_OUTPUT
- name: Check version change
id: check
run: |
echo "current=${{ steps.current.outputs.version }}"
echo "previous=${{ steps.previous.outputs.version }}"
if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check.outputs.changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Perform live update
if: steps.check.outputs.changed == 'true'
run: yarn android-live-update

3
android/capawesome.json Normal file
View File

@@ -0,0 +1,3 @@
{
"version": 1
}

View File

@@ -18,6 +18,7 @@
"clean-install": "./scripts/install.sh",
"build-web-view": "./scripts/build_web_view.sh",
"build-sync-android": "./scripts/build_sync_android.sh",
"android-live-update": "./scripts/android_live_update.sh",
"sync-android": "./scripts/sync_android.sh",
"migrate": "./scripts/migrate.sh",
"test": "yarn workspaces run test",

15
scripts/android_live_update.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"/..
yarn build-web-view
npx @capawesome/cli apps:bundles:create \
--app-id 969bc540-8077-492f-8403-b554bee5de50 \
--channel default \
--commit-message $(git log -1 --pretty=format:"%s") \
--commit-ref 'd699ceae3890f70a7bc66720bc980398f799a6e1' \
--commit-sha 'd699ceae3890f70a7bc66720bc980398f799a6e1' \
--path web/out

View File

@@ -31,6 +31,13 @@ if (Capacitor.isNativePlatform()) {
})
App.addListener("resume", async () => {
const newChannelName = 'default'
try {
await LiveUpdate.setChannel({channel: newChannelName})
console.log(`Device channel set to: ${newChannelName}`)
} catch (error) {
console.error('Failed to set channel', error)
}
const {nextBundleId} = await LiveUpdate.sync()
if (nextBundleId) {
// Ask the user if they want to apply the update immediately