Merge pull request #69 from Commute-ai/develop #131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Node.js CI | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| contents: write | |
| on: | |
| push: | |
| branches: [master, main, develop] | |
| pull_request: | |
| branches: [master, main, develop] | |
| env: | |
| NODE_VERSION: 22.x | |
| CI: 1 | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: π₯ Checkout | |
| uses: actions/checkout@v4 | |
| - name: π§ Set up Node.js ${{ env.NODE_VERSION }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: "npm" | |
| - name: π¦ Install dependencies | |
| run: npm ci | |
| - name: π Lint | |
| run: npm run lint | |
| - name: π§ͺ Test | |
| run: npm test | |
| # OTA update on every push | |
| ota-update: | |
| needs: test | |
| if: | | |
| github.event_name == 'push' && | |
| !startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: π₯ Checkout | |
| uses: actions/checkout@v4 | |
| - name: π§ Set up Node.js ${{ env.NODE_VERSION }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: "npm" | |
| - name: π¨ Setup Expo and EAS | |
| uses: expo/expo-github-action@v8 | |
| with: | |
| eas-version: latest | |
| token: ${{ secrets.EXPO_TOKEN }} | |
| - name: π¦ Install dependencies | |
| run: npm ci | |
| - name: π― Determine update channel | |
| id: channel | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main ]] || [[ $GITHUB_REF == refs/heads/master ]]; then | |
| echo "channel=production" >> $GITHUB_OUTPUT | |
| echo "branch_name=main" >> $GITHUB_OUTPUT | |
| echo "environment=production" >> $GITHUB_OUTPUT | |
| else | |
| echo "channel=staging" >> $GITHUB_OUTPUT | |
| echo "branch_name=develop" >> $GITHUB_OUTPUT | |
| echo "environment=preview" >> $GITHUB_OUTPUT | |
| fi | |
| - name: π Push OTA Update | |
| run: | | |
| echo "π± Pushing update to ${{ steps.channel.outputs.channel }} channel" | |
| eas update \ | |
| --branch ${{ steps.channel.outputs.channel }} \ | |
| --message "${{ github.event.head_commit.message }}" \ | |
| --environment "${{ steps.channel.outputs.environment }}" | |
| echo "β Update published! All installed apps will receive it automatically." | |
| - name: π Add job summary | |
| if: always() | |
| run: | | |
| if [[ "${{ job.status }}" == "success" ]]; then | |
| echo "### β OTA Update Published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Channel:** \`${{ steps.channel.outputs.channel }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit:** ${{ github.event.head_commit.message }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Branch:** \`${GITHUB_REF#refs/heads/}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "All devices with the app installed will receive this update automatically on next launch." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "### β OTA Update Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Check the job logs for details." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: π¬ Comment on commit | |
| uses: actions/github-script@v6 | |
| if: always() && github.event_name == 'push' | |
| with: | |
| script: | | |
| const emoji = '${{ job.status }}' === 'success' ? 'β ' : 'β'; | |
| const status = '${{ job.status }}' === 'success' ? 'published' : 'failed'; | |
| const message = `${emoji} OTA Update ${status} to \`${{ steps.channel.outputs.channel }}\` channel\n\n` + | |
| `All devices with the app installed will receive this update automatically on next launch.`; | |
| github.rest.repos.createCommitComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: context.sha, | |
| body: message | |
| }); |