mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-30 11:14:05 -04:00
Add CD for android live update
This commit is contained in:
59
.github/workflows/cd-android-live-update.yml
vendored
Normal file
59
.github/workflows/cd-android-live-update.yml
vendored
Normal 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 commit’s 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
3
android/capawesome.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": 1
|
||||
}
|
||||
@@ -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
15
scripts/android_live_update.sh
Executable 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user