This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch ci/merge-pr-artifact-comment-into-build in repository https://gitbox.apache.org/repos/asf/struts-intellij-plugin.git
commit bf53c2b2620f6ee94567f0f677089c7082cb302e Author: Lukasz Lenart <[email protected]> AuthorDate: Tue Feb 24 10:04:57 2026 +0100 ci: merge PR artifact comment into build workflow The workflow_run-based pr-artifact.yml fails for cross-fork PRs because the pull_requests array is empty. Moving the comment logic directly into build.yml as a conditional job eliminates this issue by using the natively available context.payload.pull_request.number. š¤ Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --- .github/workflows/build.yml | 48 +++++++++++++++- .github/workflows/pr-artifact.yml | 117 -------------------------------------- 2 files changed, 47 insertions(+), 118 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f122bf..446d6b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,7 @@ jobs: runs-on: ubuntu-latest outputs: pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }} + artifact_name: ${{ steps.artifact.outputs.filename }} steps: # Check out the current repository @@ -234,4 +235,49 @@ jobs: uses: actions/upload-artifact@v6 with: name: pluginVerifier-result - path: ${{ github.workspace }}/build/reports/pluginVerifier \ No newline at end of file + path: ${{ github.workspace }}/build/reports/pluginVerifier + + # Comment on PR with artifact download link + pr-comment: + name: Comment on PR with artifact link + needs: [ build ] + if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Comment on PR + uses: actions/github-script@v8 + with: + script: | + const prNumber = context.payload.pull_request.number; + const artifactName = '${{ needs.build.outputs.artifact_name }}' || 'plugin-artifact'; + const runId = context.runId; + + const marker = '<!-- plugin-artifact-comment -->'; + const body = `${marker}\nš **Plugin artifact ready for testing!**\n\nDownload from [Actions artifacts](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}#artifacts)\n\nArtifact: \`${artifactName}\``; + + // Find existing comment with marker + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + 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: body + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: body + }); + } \ No newline at end of file diff --git a/.github/workflows/pr-artifact.yml b/.github/workflows/pr-artifact.yml deleted file mode 100644 index edfb5be..0000000 --- a/.github/workflows/pr-artifact.yml +++ /dev/null @@ -1,117 +0,0 @@ -# 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. - -# Workflow to comment on PRs with artifact download link -# Triggered after Build workflow completes, skipped for Dependabot PRs - -name: PR Artifact Comment - -on: - workflow_run: - workflows: [ "Build" ] - types: - - completed - -jobs: - comment: - name: Comment on PR with artifact link - # Only run for successful PR builds, skip Dependabot - if: > - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' && - github.event.workflow_run.actor.login != 'dependabot[bot]' - runs-on: ubuntu-latest - permissions: - pull-requests: write - actions: read - steps: - - name: Get PR number and artifact info - id: pr-info - uses: actions/github-script@v8 - with: - script: | - // Get the PR associated with this workflow run - const { data: { pull_requests } } = await github.rest.actions.getWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id - }); - - if (!pull_requests || pull_requests.length === 0) { - core.setFailed('No PR found for this workflow run'); - return; - } - - const prNumber = pull_requests[0].number; - core.setOutput('pr_number', prNumber); - - // Get artifacts from the workflow run - const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id - }); - - // Find the plugin artifact (exclude pr-metadata, tests-result, pluginVerifier-result) - const pluginArtifact = artifacts.find(a => - !['pr-metadata', 'tests-result', 'pluginVerifier-result'].includes(a.name) - ); - - if (pluginArtifact) { - core.setOutput('artifact_name', pluginArtifact.name); - } else { - core.setOutput('artifact_name', 'plugin-artifact'); - } - - - name: Comment on PR - uses: actions/github-script@v8 - with: - script: | - const prNumber = ${{ steps.pr-info.outputs.pr_number }}; - const artifactName = '${{ steps.pr-info.outputs.artifact_name }}'; - const runId = context.payload.workflow_run.id; - - const marker = '<!-- plugin-artifact-comment -->'; - const body = `${marker} - š **Plugin artifact ready for testing!** - - Download from [Actions artifacts](${{ github.server_url }}/${{ github.repository }}/actions/runs/${runId}#artifacts) - - Artifact: \`${artifactName}\``; - - // Find existing comment with marker - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); - - 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: body - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: body - }); - }
