|
| 1 | +name: Build PR Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +env: |
| 8 | + NODE_VERSION: "22.x" |
| 9 | + |
| 10 | +jobs: |
| 11 | + check-permissions: |
| 12 | + name: Check if user has write access |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + has-write-access: ${{ steps.check.outputs.require-result }} |
| 16 | + steps: |
| 17 | + - name: Check user permission |
| 18 | + id: check |
| 19 | + uses: actions-cool/check-user-permission@v2 |
| 20 | + with: |
| 21 | + require: write |
| 22 | + username: ${{ github.event.pull_request.user.login }} |
| 23 | + |
| 24 | + build: |
| 25 | + name: Build ${{ matrix.os }} |
| 26 | + needs: check-permissions |
| 27 | + if: needs.check-permissions.outputs.has-write-access == 'true' |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + os: [macos-latest, ubuntu-latest, windows-latest] |
| 33 | + |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v5 |
| 36 | + |
| 37 | + - name: Install pnpm |
| 38 | + uses: pnpm/action-setup@v4 |
| 39 | + with: |
| 40 | + version: 10 |
| 41 | + run_install: false |
| 42 | + |
| 43 | + - name: Setup NodeJS |
| 44 | + if: startsWith(matrix.os, 'macOS') != true |
| 45 | + uses: actions/setup-node@v5 |
| 46 | + with: |
| 47 | + node-version: ${{ env.NODE_VERSION }} |
| 48 | + cache: 'pnpm' |
| 49 | + |
| 50 | + - name: Setup NodeJS for macOS |
| 51 | + if: startsWith(matrix.os, 'macOS') |
| 52 | + uses: actions/setup-node@v5 |
| 53 | + with: |
| 54 | + node-version: ${{ env.NODE_VERSION }} |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + run: pnpm install --frozen-lockfile |
| 58 | + |
| 59 | + - name: Build on macOS |
| 60 | + if: startsWith(matrix.os, 'macOS') |
| 61 | + run: | |
| 62 | + pnpm dist:mac |
| 63 | + pnpm dist:mac:arm64 |
| 64 | +
|
| 65 | + - name: Install Linux dependencies |
| 66 | + if: startsWith(matrix.os, 'ubuntu') |
| 67 | + run: | |
| 68 | + sudo snap install snapcraft --classic |
| 69 | + sudo apt update |
| 70 | + sudo apt install -y flatpak flatpak-builder |
| 71 | + sudo flatpak remote-add --if-not-exists --system flathub https://flathub.org/repo/flathub.flatpakrepo |
| 72 | + sudo flatpak install -y flathub org.freedesktop.Platform/x86_64/24.08 |
| 73 | + sudo flatpak install -y flathub org.freedesktop.Sdk/x86_64/24.08 |
| 74 | + sudo flatpak install -y flathub org.electronjs.Electron2.BaseApp/x86_64/24.08 |
| 75 | +
|
| 76 | + - name: Build on Linux |
| 77 | + if: startsWith(matrix.os, 'ubuntu') |
| 78 | + run: | |
| 79 | + pnpm dist:linux |
| 80 | + pnpm dist:linux:deb-arm64 |
| 81 | + pnpm dist:linux:rpm-arm64 |
| 82 | +
|
| 83 | + - name: Build on Windows |
| 84 | + if: startsWith(matrix.os, 'windows') |
| 85 | + run: | |
| 86 | + pnpm dist:win |
| 87 | +
|
| 88 | + - name: Upload artifacts |
| 89 | + uses: actions/upload-artifact@v4 |
| 90 | + with: |
| 91 | + name: build-artifacts-${{ matrix.os }} |
| 92 | + path: pack/ |
| 93 | + retention-days: 7 |
| 94 | + if-no-files-found: error |
| 95 | + |
| 96 | + comment: |
| 97 | + name: Comment on PR |
| 98 | + needs: [check-permissions, build] |
| 99 | + if: always() && needs.check-permissions.outputs.has-write-access == 'true' |
| 100 | + runs-on: ubuntu-latest |
| 101 | + permissions: |
| 102 | + pull-requests: write |
| 103 | + steps: |
| 104 | + - name: Create comment |
| 105 | + uses: actions/github-script@v7 |
| 106 | + with: |
| 107 | + script: | |
| 108 | + const runId = context.runId; |
| 109 | + const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; |
| 110 | +
|
| 111 | + const buildResult = '${{ needs.build.result }}'; |
| 112 | +
|
| 113 | + let comment; |
| 114 | + if (buildResult === 'success') { |
| 115 | + comment = `## 🚀 Build Artifacts Ready! |
| 116 | +
|
| 117 | + The builds have completed successfully. You can download the artifacts from the workflow run: |
| 118 | +
|
| 119 | + **[📦 Download Artifacts](${runUrl})** |
| 120 | +
|
| 121 | + ### Available builds: |
| 122 | + - **Windows**: \`build-artifacts-windows-latest\` |
| 123 | + - **macOS**: \`build-artifacts-macos-latest\` |
| 124 | + - **Linux**: \`build-artifacts-ubuntu-latest\` |
| 125 | +
|
| 126 | + *Note: Artifacts are available for 7 days.*`; |
| 127 | + } else if (buildResult === 'failure') { |
| 128 | + comment = `## ❌ Build Failed |
| 129 | +
|
| 130 | + Unfortunately, one or more builds failed. Please check the workflow run for details: |
| 131 | +
|
| 132 | + **[View Workflow Run](${runUrl})**`; |
| 133 | + } else { |
| 134 | + comment = `## ⚠️ Build Status: ${buildResult} |
| 135 | +
|
| 136 | + The build process completed with status: **${buildResult}** |
| 137 | +
|
| 138 | + **[View Workflow Run](${runUrl})**`; |
| 139 | + } |
| 140 | +
|
| 141 | + github.rest.issues.createComment({ |
| 142 | + issue_number: context.issue.number, |
| 143 | + owner: context.repo.owner, |
| 144 | + repo: context.repo.repo, |
| 145 | + body: comment |
| 146 | + }); |
0 commit comments