|
| 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 |
0 commit comments