Skip to content

Commit 0d026d3

Browse files
committed
Add CD for android live update
1 parent d699cea commit 0d026d3

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CD API
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
paths:
6+
- "android/capawesome.json"
7+
- ".github/workflows/cd-android-live-update.yml"
8+
9+
jobs:
10+
deploy:
11+
name: Deploy
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # we need full history for git log
19+
20+
- name: Install jq
21+
run: sudo apt-get install -y jq
22+
23+
- name: Read current version
24+
id: current
25+
run: |
26+
current=$(jq -r '.version' android/capawesome.json)
27+
echo "version=$current" >> $GITHUB_OUTPUT
28+
29+
- name: Read previous version
30+
id: previous
31+
run: |
32+
# Get previous commit’s package.json (if it existed)
33+
if git show HEAD^:android/capawesome.json >/dev/null 2>&1; then
34+
previous=$(git show HEAD^:android/capawesome.json | jq -r '.version')
35+
else
36+
previous="none"
37+
fi
38+
echo "version=$previous" >> $GITHUB_OUTPUT
39+
40+
- name: Check version change
41+
id: check
42+
run: |
43+
echo "current=${{ steps.current.outputs.version }}"
44+
echo "previous=${{ steps.previous.outputs.version }}"
45+
if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then
46+
echo "changed=false" >> $GITHUB_OUTPUT
47+
else
48+
echo "changed=true" >> $GITHUB_OUTPUT
49+
fi
50+
51+
- name: Setup Node.js
52+
if: steps.check.outputs.changed == 'true'
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version: '22'
56+
57+
- name: Perform live update
58+
if: steps.check.outputs.changed == 'true'
59+
run: yarn android-live-update

android/capawesome.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": 1
3+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"clean-install": "./scripts/install.sh",
1919
"build-web-view": "./scripts/build_web_view.sh",
2020
"build-sync-android": "./scripts/build_sync_android.sh",
21+
"android-live-update": "./scripts/android_live_update.sh",
2122
"sync-android": "./scripts/sync_android.sh",
2223
"migrate": "./scripts/migrate.sh",
2324
"test": "yarn workspaces run test",

scripts/android_live_update.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd "$(dirname "$0")"/..
6+
7+
yarn build-web-view
8+
9+
npx @capawesome/cli apps:bundles:create \
10+
--app-id 969bc540-8077-492f-8403-b554bee5de50 \
11+
--channel default \
12+
--commit-message $(git log -1 --pretty=format:"%s") \
13+
--commit-ref 'd699ceae3890f70a7bc66720bc980398f799a6e1' \
14+
--commit-sha 'd699ceae3890f70a7bc66720bc980398f799a6e1' \
15+
--path web/out

web/pages/_app.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ if (Capacitor.isNativePlatform()) {
3131
})
3232

3333
App.addListener("resume", async () => {
34+
const newChannelName = 'default'
35+
try {
36+
await LiveUpdate.setChannel({channel: newChannelName})
37+
console.log(`Device channel set to: ${newChannelName}`)
38+
} catch (error) {
39+
console.error('Failed to set channel', error)
40+
}
3441
const {nextBundleId} = await LiveUpdate.sync()
3542
if (nextBundleId) {
3643
// Ask the user if they want to apply the update immediately

0 commit comments

Comments
 (0)