ci: add PR comment with build artifact download links #25
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 | |
| on: | |
| push: | |
| branches: [main, v2] | |
| pull_request: | |
| branches: [main, v2] | |
| workflow_dispatch: | |
| inputs: | |
| display_dj_cli_version: | |
| description: 'display-dj-cli version to use (e.g. v0.4.1). Leave empty for default from package.json.' | |
| required: false | |
| default: '' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: macos-latest | |
| target: aarch64-apple-darwin | |
| artifact_name: macOS (Apple Silicon ARM64) | |
| - platform: macos-latest | |
| target: x86_64-apple-darwin | |
| artifact_name: macOS (Intel x64) | |
| - platform: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| artifact_name: Windows (x64) | |
| - platform: ubuntu-22.04 | |
| target: x86_64-unknown-linux-gnu | |
| artifact_name: Linux (x64) | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install Linux dependencies | |
| if: matrix.platform == 'ubuntu-22.04' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| libwebkit2gtk-4.1-dev \ | |
| libappindicator3-dev \ | |
| librsvg2-dev \ | |
| patchelf \ | |
| libxdo-dev \ | |
| libssl-dev | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run frontend tests | |
| run: npm test | |
| - name: Run Rust tests | |
| working-directory: src-tauri | |
| shell: bash | |
| env: | |
| DISPLAY_DJ_CLI_VERSION: ${{ github.event.inputs.display_dj_cli_version }} | |
| run: | | |
| if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then | |
| # Skip integration smoke test on Windows CI — Dxva2.dll (DDC/CI) is not | |
| # available on Server SKUs, so the smoke binary crashes at load time. | |
| cargo test --target ${{ matrix.target }} --lib | |
| else | |
| cargo test --target ${{ matrix.target }} | |
| fi | |
| - name: Build Tauri app | |
| uses: tauri-apps/tauri-action@v0 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| DISPLAY_DJ_CLI_VERSION: ${{ github.event.inputs.display_dj_cli_version }} | |
| with: | |
| args: --target ${{ matrix.target }} | |
| - name: Upload bundle artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: | | |
| src-tauri/target/${{ matrix.target }}/release/bundle/dmg/*.dmg | |
| src-tauri/target/${{ matrix.target }}/release/bundle/macos/*.app | |
| src-tauri/target/${{ matrix.target }}/release/bundle/nsis/*.exe | |
| src-tauri/target/${{ matrix.target }}/release/bundle/msi/*.msi | |
| src-tauri/target/${{ matrix.target }}/release/bundle/deb/*.deb | |
| src-tauri/target/${{ matrix.target }}/release/bundle/appimage/*.AppImage | |
| src-tauri/target/${{ matrix.target }}/release/bundle/rpm/*.rpm | |
| compression-level: 9 | |
| if-no-files-found: ignore | |
| # Post a comment on PRs with download links for each platform's build artifacts | |
| pr_comment: | |
| if: github.event_name == 'pull_request' | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Post artifact links on PR | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.runId, | |
| }); | |
| let body = `## Build Artifacts\n\n`; | |
| if (artifacts.data.artifacts.length === 0) { | |
| body += `No artifacts were produced.\n`; | |
| } else { | |
| body += `| Platform | Size | Download |\n|----------|------|----------|\n`; | |
| for (const a of artifacts.data.artifacts) { | |
| const sizeMB = (a.size_in_bytes / 1024 / 1024).toFixed(1); | |
| const downloadUrl = `${runUrl}/artifacts/${a.id}`; | |
| body += `| ${a.name} | ${sizeMB} MB | [Download](${downloadUrl}) |\n`; | |
| } | |
| } | |
| body += `\n[View full run](${runUrl})`; | |
| // Find and update existing comment or create new one | |
| const marker = '<!-- build-artifacts -->'; | |
| body = marker + '\n' + body; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); | |
| } |