You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "Pearl1594 (via GitHub)" <gi...@apache.org> on 2026/02/03 16:33:18 UTC

[PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Pearl1594 opened a new pull request, #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "shwstppr (via GitHub)" <gi...@apache.org>.
shwstppr commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2798462254


##########
.github/workflows/comment-pr-build.yml:
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Comment on PR build results
+
+on:
+  workflow_run:
+    workflows: ["Build cmk binaries on PR"]
+    types:
+      - completed
+
+permissions:
+  contents: read
+  issues: write
+  pull-requests: write
+  actions: read
+
+jobs:
+  comment:
+    runs-on: ubuntu-24.04
+    if: >
+      github.event.workflow_run.event == 'pull_request'
+    steps:
+      - name: Download artifact metadata
+        uses: actions/github-script@v7
+        id: artifact-metadata
+        with:
+          script: |
+            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              run_id: context.payload.workflow_run.id,
+            });
+            
+            const prArtifact = artifacts.data.artifacts.find(a => a.name.startsWith('cmk-binaries.pr'));
+            
+            if (prArtifact) {
+              const prNumber = prArtifact.name.match(/pr(\d+)/)?.[1];
+              return {
+                artifact_url: prArtifact.archive_download_url,
+                pr_number: prNumber,
+                conclusion: context.payload.workflow_run.conclusion
+              };
+            }
+            
+            return {
+              pr_number: null,
+              conclusion: context.payload.workflow_run.conclusion
+            };
+
+      - name: Get PR number from workflow run
+        id: get-pr
+        uses: actions/github-script@v7
+        env:
+          METADATA: ${{ steps.artifact-metadata.outputs.result }}
+        with:
+          script: |
+            // Primary source: PRs attached to the workflow_run (for pull_request-triggered runs)
+            const runPRs = context.payload.workflow_run.pull_requests;
+            if (runPRs && runPRs.length > 0) {
+              return runPRs[0].number;
+            }
+            // Fallback 1: PR number discovered from artifact metadata
+            let metadata = {};
+            if (process.env.METADATA) {
+              try {
+                metadata = JSON.parse(process.env.METADATA);
+              } catch (e) {
+                core.warning(`Failed to parse artifact metadata: ${e.message}`);
+              }
+            }
+            if (metadata.pr_number) {
+              return metadata.pr_number;
+            }
+            // Fallback 2: look up PRs associated with the workflow run head SHA
+            const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              commit_sha: context.payload.workflow_run.head_sha,
+            });
+            if (associated.data.length > 0) {
+              return associated.data[0].number;
+            }
+            return null;
+
+      - name: Comment or update build result on PR
+        uses: actions/github-script@v7
+        with:
+          script: |
+            const { execSync } = require('child_process');
+            const prNumber = ${{ steps.get-pr.outputs.result }};
+            
+            if (!prNumber) {
+              core.warning('Could not determine PR number, skipping comment');
+              return;
+            }
+
+            const identifier = "cmk-build-artifact-comment";
+            const owner = context.repo.owner;
+            const repo = context.repo.repo;
+            const conclusion = '${{ github.event.workflow_run.conclusion }}';
+            const runId = '${{ github.event.workflow_run.id }}';
+            const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
+
+            core.info(`Commenting on PR #${prNumber}`);
+            core.info(`Build conclusion: ${conclusion}`);
+
+            let body = `<!-- ${identifier} -->\n`;
+            
+            if (conclusion === 'success') {
+              const expiryDate = execSync("date -d '+10 days' '+%B %d, %Y'").toString().trim();
+              body += `βœ… Build complete for PR #${prNumber}.\n\n`;
+              body += `πŸ“¦ Binary artifacts are available in the [workflow run](${runUrl}) (expires on ${expiryDate}).\n\n`;
+              body += `> **Note:** Download artifacts by clicking on the workflow run link above, then scroll to the "Artifacts" section.\n`;
+              body += `> _Artifacts from PR builds are for testing only and may contain unreviewed code._`;

Review Comment:
   @DaanHoogland I feel that if the intention is to simply mention that binaries can contain malicious code, then we should state that directly
   ```suggestion
                 body += `> _Artifacts from PR builds are for testing only and may contain unreviewed, malicious code._`;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "Pearl1594 (via GitHub)" <gi...@apache.org>.
Pearl1594 commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2762164568


##########
.github/workflows/build-pr-cmk.yml:
##########
@@ -18,7 +18,7 @@
 name: Build cmk binaries on PR
 
 on:
-  pull_request_target:
+  pull_request:

Review Comment:
   Seems to work on forks @yadvr; Raised a PR from my fork to this PR and the gha ran: https://github.com/apache/cloudstack-cloudmonkey/pull/205



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "yadvr (via GitHub)" <gi...@apache.org>.
yadvr commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2762079647


##########
.github/workflows/build-pr-cmk.yml:
##########
@@ -18,7 +18,7 @@
 name: Build cmk binaries on PR
 
 on:
-  pull_request_target:
+  pull_request:

Review Comment:
   I think without this, gha won't run for PRs from forks. Need to double check cc @Pearl1594 @shwstppr @DaanHoogland @vishesh92 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#issuecomment-3842368553

   <!-- cmk-build-artifact-comment -->
   βœ… Build complete for PR #204.
   
   πŸ”— Download the [cmk binaries](https://github.com/apache/cloudstack-cloudmonkey/actions/runs/21638598064/artifacts/5360904502) (expires on February 13, 2026)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2789592047


##########
.github/workflows/build-pr-cmk.yml:
##########
@@ -36,10 +36,9 @@ jobs:
       outcome: ${{ steps.meta.outputs.outcome }}
       artifact_url: ${{ steps.meta.outputs.artifact_url }}
     steps:
-      - name: Checkout PR HEAD
+      - name: Checkout PR code
         uses: actions/checkout@v4
         with:
-          ref: ${{ github.event.pull_request.head.sha }}
           persist-credentials: false

Review Comment:
   The PR title indicates the build should check out the base branch, but with `on: pull_request` and no explicit `ref`, `actions/checkout` will check out the PR merge ref (`refs/pull/<n>/merge`) by default (i.e., merged PR tip, not base). If the intention is truly to build the base branch, set `ref` to the base ref/SHA; otherwise the PR title/description should be updated to match the behavior.



##########
.github/workflows/build-pr-cmk.yml:
##########
@@ -68,53 +67,3 @@ jobs:
         run: |
           echo "outcome=${{ steps.build.outcome }}" >> $GITHUB_OUTPUT
           echo "artifact_url=${{ steps.upload_artifact.outputs.artifact-url }}" >> $GITHUB_OUTPUT

Review Comment:
   This workflow currently captures `steps.build.outcome` in `meta`, but the run’s overall conclusion can still be `success` even when `make dist` fails because the build step uses `continue-on-error: true`. The new comment workflow keys off `workflow_run.conclusion`, so it may post a βœ… success comment for a failed build. Ensure the job fails when the build fails (e.g., remove `continue-on-error` or add a final `exit 1` step when `steps.build.outcome != 'success'`).



##########
.github/workflows/comment-pr-build.yml:
##########
@@ -0,0 +1,153 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Comment on PR build results
+
+on:
+  workflow_run:
+    workflows: ["Build cmk binaries on PR"]
+    types:
+      - completed
+
+permissions:
+  contents: read
+  issues: write
+  pull-requests: write
+

Review Comment:
   `listWorkflowRunArtifacts` requires the `actions: read` permission. Since this workflow sets an explicit `permissions:` block without `actions: read`, the first github-script step will likely fail with a 403 and the comment job won’t run. Add `actions: read` (or remove the artifact-listing call if it’s not needed).



##########
.github/workflows/build-pr-cmk.yml:
##########
@@ -36,10 +36,9 @@ jobs:
       outcome: ${{ steps.meta.outputs.outcome }}
       artifact_url: ${{ steps.meta.outputs.artifact_url }}
     steps:

Review Comment:
   After removing the in-workflow `comment` job, the job-level `outputs` (`outcome`, `artifact_url`) (and the `meta` step that produces them) are no longer consumed by any downstream job in this workflow. Consider removing these outputs/step to avoid confusion, or adjust the new comment workflow to consume the needed data via artifacts/metadata instead.



##########
.github/workflows/comment-pr-build.yml:
##########
@@ -0,0 +1,153 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Comment on PR build results
+
+on:
+  workflow_run:
+    workflows: ["Build cmk binaries on PR"]
+    types:
+      - completed
+
+permissions:
+  contents: read
+  issues: write
+  pull-requests: write
+
+jobs:
+  comment:
+    runs-on: ubuntu-24.04
+    if: >
+      github.event.workflow_run.event == 'pull_request'
+    steps:
+      - name: Download artifact metadata
+        uses: actions/github-script@v7
+        id: artifact-metadata
+        with:
+          script: |
+            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              run_id: context.payload.workflow_run.id,
+            });
+            
+            const prArtifact = artifacts.data.artifacts.find(a => a.name.startsWith('cmk-binaries.pr'));
+            
+            if (prArtifact) {
+              const prNumber = prArtifact.name.match(/pr(\d+)/)?.[1];
+              return {
+                artifact_url: prArtifact.archive_download_url,
+                pr_number: prNumber,
+                conclusion: context.payload.workflow_run.conclusion
+              };
+            }
+            
+            return {
+              pr_number: null,
+              conclusion: context.payload.workflow_run.conclusion
+            };
+
+      - name: Get PR number from workflow run
+        id: get-pr
+        uses: actions/github-script@v7
+        with:
+          script: |
+            const metadata = ${{ steps.artifact-metadata.outputs.result }};
+            
+            if (metadata.pr_number) {
+              return metadata.pr_number;
+            }
+            
+            // Fallback: get PR from workflow run
+            const pulls = await github.rest.pulls.list({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              state: 'open',
+              head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`
+            });
+            
+            if (pulls.data.length > 0) {
+              return pulls.data[0].number;
+            }
+            
+            return null;
+

Review Comment:
   PR number discovery is unreliable for failed builds and forked PRs: on failure there is no artifact (upload is gated on success), so `metadata.pr_number` will be null; the fallback `pulls.list` uses `head: ${context.repo.owner}:<branch>`, which won’t match fork heads and can also be ambiguous if multiple PRs share a branch name. Prefer using `context.payload.workflow_run.pull_requests[0].number` (available for `workflow_run` triggered by `pull_request`) as the primary source, and keep API lookups only as a fallback.
   ```suggestion
               // Primary source: PRs attached to the workflow_run (for pull_request-triggered runs)
               const runPRs = context.payload.workflow_run.pull_requests;
               if (runPRs && runPRs.length > 0) {
                 return runPRs[0].number;
               }
   
               // Fallback 1: PR number discovered from artifact metadata
               let metadata = {};
               if (process.env.METADATA) {
                 try {
                   metadata = JSON.parse(process.env.METADATA);
                 } catch (e) {
                   core.warning(`Failed to parse artifact metadata: ${e.message}`);
                 }
               }
   
               if (metadata.pr_number) {
                 return metadata.pr_number;
               }
   
               // Fallback 2: look up PRs associated with the workflow run head SHA
               const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({
                 owner: context.repo.owner,
                 repo: context.repo.repo,
                 commit_sha: context.payload.workflow_run.head_sha,
               });
   
               if (associated.data.length > 0) {
                 return associated.data[0].number;
               }
   
               return null;
             env:
               METADATA: ${{ steps.artifact-metadata.outputs.result }}
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#issuecomment-3842966547

   <!-- cmk-build-artifact-comment -->
   ❌ Build failed for PR #204.
   
   See the run: https://github.com/apache/cloudstack-cloudmonkey/actions/runs/21642666298


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland merged PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2794522161


##########
.github/workflows/comment-pr-build.yml:
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Comment on PR build results
+
+on:
+  workflow_run:
+    workflows: ["Build cmk binaries on PR"]
+    types:
+      - completed
+
+permissions:
+  contents: read
+  issues: write
+  pull-requests: write
+  actions: read
+
+jobs:
+  comment:
+    runs-on: ubuntu-24.04
+    if: >
+      github.event.workflow_run.event == 'pull_request'
+    steps:
+      - name: Download artifact metadata
+        uses: actions/github-script@v7
+        id: artifact-metadata
+        with:
+          script: |
+            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              run_id: context.payload.workflow_run.id,
+            });
+            
+            const prArtifact = artifacts.data.artifacts.find(a => a.name.startsWith('cmk-binaries.pr'));
+            
+            if (prArtifact) {
+              const prNumber = prArtifact.name.match(/pr(\d+)/)?.[1];
+              return {
+                artifact_url: prArtifact.archive_download_url,
+                pr_number: prNumber,
+                conclusion: context.payload.workflow_run.conclusion
+              };
+            }
+            
+            return {
+              pr_number: null,
+              conclusion: context.payload.workflow_run.conclusion
+            };
+
+      - name: Get PR number from workflow run
+        id: get-pr
+        uses: actions/github-script@v7
+        env:
+          METADATA: ${{ steps.artifact-metadata.outputs.result }}
+        with:
+          script: |
+            // Primary source: PRs attached to the workflow_run (for pull_request-triggered runs)
+            const runPRs = context.payload.workflow_run.pull_requests;
+            if (runPRs && runPRs.length > 0) {
+              return runPRs[0].number;
+            }
+            // Fallback 1: PR number discovered from artifact metadata
+            let metadata = {};
+            if (process.env.METADATA) {
+              try {
+                metadata = JSON.parse(process.env.METADATA);
+              } catch (e) {
+                core.warning(`Failed to parse artifact metadata: ${e.message}`);
+              }
+            }
+            if (metadata.pr_number) {
+              return metadata.pr_number;
+            }
+            // Fallback 2: look up PRs associated with the workflow run head SHA
+            const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              commit_sha: context.payload.workflow_run.head_sha,
+            });
+            if (associated.data.length > 0) {
+              return associated.data[0].number;
+            }
+            return null;
+
+      - name: Comment or update build result on PR
+        uses: actions/github-script@v7
+        with:
+          script: |
+            const { execSync } = require('child_process');
+            const prNumber = ${{ steps.get-pr.outputs.result }};
+            
+            if (!prNumber) {
+              core.warning('Could not determine PR number, skipping comment');
+              return;
+            }
+
+            const identifier = "cmk-build-artifact-comment";
+            const owner = context.repo.owner;
+            const repo = context.repo.repo;
+            const conclusion = '${{ github.event.workflow_run.conclusion }}';
+            const runId = '${{ github.event.workflow_run.id }}';
+            const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
+
+            core.info(`Commenting on PR #${prNumber}`);
+            core.info(`Build conclusion: ${conclusion}`);
+
+            let body = `<!-- ${identifier} -->\n`;
+            
+            if (conclusion === 'success') {
+              const expiryDate = execSync("date -d '+10 days' '+%B %d, %Y'").toString().trim();
+              body += `βœ… Build complete for PR #${prNumber}.\n\n`;
+              body += `πŸ“¦ Binary artifacts are available in the [workflow run](${runUrl}) (expires on ${expiryDate}).\n\n`;
+              body += `> **Note:** Download artifacts by clicking on the workflow run link above, then scroll to the "Artifacts" section.\n`;
+              body += `> _Artifacts from PR builds are for testing only and may contain unreviewed code._`;

Review Comment:
   ```suggestion
                 body += `> _Artifacts from PR builds are for testing only and may contain unreviewed code at best, and malicious code at worst._`;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#issuecomment-3885738587

   <!-- cmk-build-artifact-comment -->
   ❌ Build failed for PR #204.
   
   See the run: https://github.com/apache/cloudstack-cloudmonkey/actions/runs/21914741911


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Checkout base branch instead of PR head in build workflow [cloudstack-cloudmonkey]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #204:
URL: https://github.com/apache/cloudstack-cloudmonkey/pull/204#discussion_r2798442902


##########
.github/workflows/comment-pr-build.yml:
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Comment on PR build results
+
+on:
+  workflow_run:
+    workflows: ["Build cmk binaries on PR"]
+    types:
+      - completed
+
+permissions:
+  contents: read
+  issues: write
+  pull-requests: write
+  actions: read
+
+jobs:
+  comment:
+    runs-on: ubuntu-24.04
+    if: >
+      github.event.workflow_run.event == 'pull_request'
+    steps:
+      - name: Download artifact metadata
+        uses: actions/github-script@v7
+        id: artifact-metadata
+        with:
+          script: |
+            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              run_id: context.payload.workflow_run.id,
+            });
+            
+            const prArtifact = artifacts.data.artifacts.find(a => a.name.startsWith('cmk-binaries.pr'));
+            
+            if (prArtifact) {
+              const prNumber = prArtifact.name.match(/pr(\d+)/)?.[1];
+              return {
+                artifact_url: prArtifact.archive_download_url,
+                pr_number: prNumber,
+                conclusion: context.payload.workflow_run.conclusion
+              };
+            }
+            
+            return {
+              pr_number: null,
+              conclusion: context.payload.workflow_run.conclusion
+            };
+
+      - name: Get PR number from workflow run
+        id: get-pr
+        uses: actions/github-script@v7
+        env:
+          METADATA: ${{ steps.artifact-metadata.outputs.result }}
+        with:
+          script: |
+            // Primary source: PRs attached to the workflow_run (for pull_request-triggered runs)
+            const runPRs = context.payload.workflow_run.pull_requests;
+            if (runPRs && runPRs.length > 0) {
+              return runPRs[0].number;
+            }
+            // Fallback 1: PR number discovered from artifact metadata
+            let metadata = {};
+            if (process.env.METADATA) {
+              try {
+                metadata = JSON.parse(process.env.METADATA);
+              } catch (e) {
+                core.warning(`Failed to parse artifact metadata: ${e.message}`);
+              }
+            }
+            if (metadata.pr_number) {
+              return metadata.pr_number;
+            }
+            // Fallback 2: look up PRs associated with the workflow run head SHA
+            const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              commit_sha: context.payload.workflow_run.head_sha,
+            });
+            if (associated.data.length > 0) {
+              return associated.data[0].number;
+            }
+            return null;
+
+      - name: Comment or update build result on PR
+        uses: actions/github-script@v7
+        with:
+          script: |
+            const { execSync } = require('child_process');
+            const prNumber = ${{ steps.get-pr.outputs.result }};
+            
+            if (!prNumber) {
+              core.warning('Could not determine PR number, skipping comment');
+              return;
+            }
+
+            const identifier = "cmk-build-artifact-comment";
+            const owner = context.repo.owner;
+            const repo = context.repo.repo;
+            const conclusion = '${{ github.event.workflow_run.conclusion }}';
+            const runId = '${{ github.event.workflow_run.id }}';
+            const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
+
+            core.info(`Commenting on PR #${prNumber}`);
+            core.info(`Build conclusion: ${conclusion}`);
+
+            let body = `<!-- ${identifier} -->\n`;
+            
+            if (conclusion === 'success') {
+              const expiryDate = execSync("date -d '+10 days' '+%B %d, %Y'").toString().trim();
+              body += `βœ… Build complete for PR #${prNumber}.\n\n`;
+              body += `πŸ“¦ Binary artifacts are available in the [workflow run](${runUrl}) (expires on ${expiryDate}).\n\n`;
+              body += `> **Note:** Download artifacts by clicking on the workflow run link above, then scroll to the "Artifacts" section.\n`;
+              body += `> _Artifacts from PR builds are for testing only and may contain unreviewed code._`;

Review Comment:
   why @shwstppr ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org