diff --git a/.github/workflows/build_artifact_comment.yml b/.github/workflows/build_artifact_comment.yml index b3414fceb241..6cb4dc973d21 100644 --- a/.github/workflows/build_artifact_comment.yml +++ b/.github/workflows/build_artifact_comment.yml @@ -2,7 +2,9 @@ name: Write build artifact comments on: workflow_run: - workflows: [🪟 MingW64 Windows 64bit Build] + workflows: + - "🪟 MingW64 Windows 64bit Build" + - "🪟 Windows Qt6" types: - completed @@ -11,7 +13,6 @@ permissions: jobs: on-success: - permissions: pull-requests: write @@ -22,86 +23,68 @@ jobs: uses: actions/github-script@v7 with: script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "QGIS for Windows 64bit" + const artifactName = context.payload.workflow_run.name.includes("MingW64") ? "QGIS for Windows 64bit" : "qgis-windows-qt6"; + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, }); - if (matchArtifacts.length>0) - { - let download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifacts[0].id, - archive_format: 'zip', + const artifact = artifacts.data.artifacts.find(a => a.name == artifactName); + if (artifact) { + const download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: artifact.id, + archive_format: 'zip', }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/QGIS for Windows 64bit.zip`, Buffer.from(download.data)); - core.setOutput('artifact_id', matchArtifacts[0].id); - } - else - { - core.setOutput('artifact_id', 0); - } - let matchArtifactsDebugSymbols = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "QGIS for Windows 64bit Debug Symbols" - }); - if (matchArtifactsDebugSymbols.length>0) - { - core.setOutput('debug_symbols_artifact_id', matchArtifactsDebugSymbols[0].id); - } - else - { - core.setOutput('debug_symbols_artifact_id', 0); + const fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}`, Buffer.from(download.data)); + core.setOutput('artifact_url', `${context.repo.owner}/${context.repo.repo}/suites/${context.payload.workflow_run.check_suite_id}/artifacts/${artifact.id}`); + } else { + core.setOutput('artifact_url', ''); } - - name: 'Unzip artifact' - if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0 - run: | - unzip "QGIS for Windows 64bit.zip" - unzip -j qgis-portable-win64.zip pr_number git_commit - - - name: 'Post artifact download link as comment on PR' - if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0 + - name: 'Post or update PR comment' uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - let fs = require('fs'); - let issue_number = Number(fs.readFileSync('./pr_number')); - let git_sha = String(fs.readFileSync('./git_commit')).trim(); + const fs = require('fs'); + const issue_number = Number(fs.readFileSync('./pr_number')); + const git_sha = String(fs.readFileSync('./git_commit')).trim(); + const artifactUrl = steps.download_artifact.outputs.artifact_url; + const buildType = context.payload.workflow_run.name.includes("MingW64") ? "Windows" : "Qt6"; + const bodyPart = artifactUrl ? `${buildType} builds of this PR are available for testing [here](https://github.com/${artifactUrl}).` : `${buildType} build N/A`; + const prComments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, }); - const PREFIX = "## 🪟 Windows builds ready!"; - let body = PREFIX + "\n\n" + - "Windows builds of this PR are available for testing [here](https://github.com/" + context.repo.owner + "/" + context.repo.repo + "/suites/" + context.payload.workflow_run.check_suite_id + "/artifacts/${{steps.download_artifact.outputs.artifact_id}})."; - if ( ${{steps.download_artifact.outputs.debug_symbols_artifact_id}} > 0 ) - { - body += " Debug symbols for this build are available [here](https://github.com/" + context.repo.owner + "/" + context.repo.repo + "/suites/" + context.payload.workflow_run.check_suite_id + "/artifacts/${{steps.download_artifact.outputs.debug_symbols_artifact_id}})."; - } - body += "\n\n*(Built from commit " + git_sha + ")*"; + const commentPrefix = "## 🪟 Build Details"; + const existingComment = prComments.data.find(comment => comment.body.startsWith(commentPrefix)); + let newBody; - const winBuildComment = prComments.data?.find(c => c.body.startsWith(PREFIX)); - if (!!winBuildComment) { - // update the existing comment + if (existingComment) { + const regex = new RegExp(`(## ${buildType} builds ready![\\s\\S]*?)(?=(## (Windows|Qt6) builds ready!|$))`, "g"); + const replacement = `## ${buildType} builds ready!\n\n${bodyPart}\n\n`; + if (existingComment.body.includes(`## ${buildType} builds ready!`)) { + newBody = existingComment.body.replace(regex, replacement); + } else { + newBody = existingComment.body + replacement; + } await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: winBuildComment.id, - body: body + comment_id: existingComment.id, + body: newBody }); } else { - // submit a new comment + newBody = `${commentPrefix}\n\n${replacement}\n\n*(Built from commit ${git_sha})*`; await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, - body: body + body: newBody }); } diff --git a/.github/workflows/windows-qt6.yml b/.github/workflows/windows-qt6.yml index fa337cbfbe1b..cfecf4401cee 100644 --- a/.github/workflows/windows-qt6.yml +++ b/.github/workflows/windows-qt6.yml @@ -104,6 +104,13 @@ jobs: path: | C:/src/**/*.log + - name: Save PR number to zips + run: | + echo ${{ github.event.number }} | tee pr_number + zip -u *-win64.zip pr_number + echo ${{ github.event.pull_request.head.sha }} | tee git_commit + zip -u *-win64.zip git_commit + - name: 📤 Upload bundle uses: actions/upload-artifact@v4 with: