Add CI workflow for building PR artifacts across pla… #3
Workflow file for this run
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: Build PR Artifacts | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| - ready_for_review | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| concurrency: | |
| group: pr-build-artifacts-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| APP_DIR: open_wearable | |
| jobs: | |
| build_android: | |
| name: Build Android | |
| runs-on: ubuntu-latest | |
| outputs: | |
| artifact_id: ${{ steps.upload_android.outputs.artifact-id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: zulu | |
| java-version: "17" | |
| cache: gradle | |
| - name: Set up Flutter project | |
| uses: ./.github/actions/flutter-prepare | |
| with: | |
| app-dir: ${{ env.APP_DIR }} | |
| - name: Build Android APK | |
| working-directory: ${{ env.APP_DIR }} | |
| run: flutter build apk --release | |
| - name: Upload Android APK | |
| id: upload_android | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-apk | |
| path: open_wearable/build/app/outputs/flutter-apk/app-release.apk | |
| if-no-files-found: error | |
| build_linux: | |
| name: Build Linux | |
| runs-on: ubuntu-latest | |
| outputs: | |
| artifact_id: ${{ steps.upload_linux.outputs.artifact-id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Linux build dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| clang \ | |
| cmake \ | |
| libgtk-3-dev \ | |
| ninja-build \ | |
| pkg-config | |
| - name: Set up Flutter project | |
| uses: ./.github/actions/flutter-prepare | |
| with: | |
| app-dir: ${{ env.APP_DIR }} | |
| - name: Build Linux bundle | |
| working-directory: ${{ env.APP_DIR }} | |
| run: flutter build linux --release | |
| - name: Upload Linux bundle | |
| id: upload_linux | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-bundle | |
| path: open_wearable/build/linux/x64/release/bundle | |
| if-no-files-found: error | |
| build_windows: | |
| name: Build Windows | |
| runs-on: windows-latest | |
| outputs: | |
| artifact_id: ${{ steps.upload_windows.outputs.artifact-id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter project | |
| uses: ./.github/actions/flutter-prepare | |
| with: | |
| app-dir: ${{ env.APP_DIR }} | |
| - name: Build Windows runner | |
| working-directory: ${{ env.APP_DIR }} | |
| run: flutter build windows --release | |
| - name: Upload Windows runner | |
| id: upload_windows | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-runner | |
| path: open_wearable/build/windows/x64/runner/Release | |
| if-no-files-found: error | |
| build_web: | |
| name: Build Web | |
| runs-on: ubuntu-latest | |
| outputs: | |
| artifact_id: ${{ steps.upload_web.outputs.artifact-id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter project | |
| uses: ./.github/actions/flutter-prepare | |
| with: | |
| app-dir: ${{ env.APP_DIR }} | |
| - name: Build Web bundle | |
| working-directory: ${{ env.APP_DIR }} | |
| run: flutter build web --release | |
| - name: Upload Web bundle | |
| id: upload_web | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: web-bundle | |
| path: open_wearable/build/web | |
| if-no-files-found: error | |
| comment_artifact_links: | |
| name: Comment Artifact Links | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build_android | |
| - build_linux | |
| - build_windows | |
| - build_web | |
| if: always() | |
| steps: | |
| - name: Post or update PR comment with artifact links | |
| uses: actions/github-script@v7 | |
| env: | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| ANDROID_ARTIFACT_ID: ${{ needs.build_android.outputs.artifact_id }} | |
| LINUX_ARTIFACT_ID: ${{ needs.build_linux.outputs.artifact_id }} | |
| WINDOWS_ARTIFACT_ID: ${{ needs.build_windows.outputs.artifact_id }} | |
| WEB_ARTIFACT_ID: ${{ needs.build_web.outputs.artifact_id }} | |
| with: | |
| script: | | |
| const marker = '<!-- pr-build-artifacts -->'; | |
| const prNumber = context.payload.pull_request.number; | |
| const runUrl = process.env.RUN_URL; | |
| const repoUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}`; | |
| const linkFor = (id) => id | |
| ? `${repoUrl}/actions/runs/${context.runId}/artifacts/${id}` | |
| : runUrl; | |
| const body = `${marker} | |
| ### PR Build Artifacts | |
| - Android APK: [Download Android build](${linkFor(process.env.ANDROID_ARTIFACT_ID)}) | |
| - Linux Bundle: [Download Linux build](${linkFor(process.env.LINUX_ARTIFACT_ID)}) | |
| - Windows Runner: [Download Windows build](${linkFor(process.env.WINDOWS_ARTIFACT_ID)}) | |
| - Web Bundle: [Download Web build](${linkFor(process.env.WEB_ARTIFACT_ID)}) | |
| Full workflow run: ${runUrl}`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const previous = comments.find( | |
| (comment) => | |
| comment.user.type === 'Bot' && | |
| comment.body && | |
| comment.body.includes(marker) | |
| ); | |
| if (previous) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: previous.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } |