diff --git a/.github/workflows/tauri-build.yml b/.github/workflows/tauri-build.yml index 86f5b0e3b..a0bcdaf23 100644 --- a/.github/workflows/tauri-build.yml +++ b/.github/workflows/tauri-build.yml @@ -25,6 +25,7 @@ on: permissions: contents: read + pull-requests: write jobs: determine-matrix: @@ -639,6 +640,100 @@ jobs: fi done + pr-comment: + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' && needs.build.result == 'success' + permissions: + pull-requests: write + steps: + - name: Harden the runner + uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 + with: + egress-policy: audit + + - name: Post/Update PR Comment with Download Links + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const prNumber = context.issue.number; + const runId = context.runId; + + // Fetch artifacts for this workflow run + const { data: artifactsList } = await github.rest.actions.listWorkflowRunArtifacts({ + owner, + repo, + run_id: runId + }); + + // Map of expected artifact names to display info + const artifactMap = { + 'Stirling-PDF-windows-x86_64': { icon: '🪟', platform: 'Windows x64', files: '.exe, .msi' }, + 'Stirling-PDF-macos-aarch64': { icon: '🍎', platform: 'macOS ARM64', files: '.dmg' }, + 'Stirling-PDF-macos-x86_64': { icon: '🍎', platform: 'macOS Intel', files: '.dmg' }, + 'Stirling-PDF-linux-x86_64': { icon: '🐧', platform: 'Linux x64', files: '.deb, .AppImage' } + }; + + let commentBody = `## 📦 Tauri Desktop Builds Ready!\n\n`; + commentBody += `The desktop applications have been built and are ready for testing.\n\n`; + commentBody += `### Download Artifacts:\n\n`; + + // Add links for each found artifact + let foundArtifacts = 0; + for (const artifact of artifactsList.artifacts) { + const info = artifactMap[artifact.name]; + if (info) { + foundArtifacts++; + // GitHub doesn't provide direct download URLs via API, but we can link to the artifact on the Actions page + const artifactUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id}`; + commentBody += `${info.icon} **${info.platform}**: [Download ${artifact.name}](${artifactUrl}) `; + commentBody += `(${info.files}) - ${(artifact.size_in_bytes / 1024 / 1024).toFixed(1)} MB\n`; + } + } + + if (foundArtifacts === 0) { + commentBody += `⚠️ **Warning**: No artifacts found in workflow run.\n`; + commentBody += `[View workflow run](https://github.com/${owner}/${repo}/actions/runs/${runId})\n`; + } + + commentBody += `\n---\n`; + commentBody += `_Built from commit ${context.sha.substring(0, 7)}_\n`; + commentBody += `_Artifacts expire in 7 days_`; + + // Find existing comment + const { data: comments } = await github.rest.issues.listComments({ + owner, + repo, + issue_number: prNumber + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('📦 Tauri Desktop Builds Ready!') + ); + + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: botComment.id, + body: commentBody + }); + console.log('Updated existing comment'); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner, + repo, + issue_number: prNumber, + body: commentBody + }); + console.log('Created new comment'); + } + report: needs: build runs-on: ubuntu-latest