Skip to content

Commit 9ac80ba

Browse files
authored
build: Enhance PR workflow to comment on both issues and PRs (#1239)
1 parent c452870 commit 9ac80ba

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

.github/workflows/pr-package.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,15 @@ jobs:
3333
fi
3434
3535
- name: Package plugin
36-
if: steps.check_issue.outputs.has_issue == 'true'
3736
run: ./plugin-script/package_plugin.sh
3837

3938
- name: Get plugin filename
40-
if: steps.check_issue.outputs.has_issue == 'true'
4139
id: get_filename
4240
run: |
4341
FILENAME=$(ls plugin/easy-yapi-*.zip | xargs basename)
4442
echo "plugin_filename=${FILENAME}" >> $GITHUB_OUTPUT
4543
4644
- name: Upload plugin artifact
47-
if: steps.check_issue.outputs.has_issue == 'true'
4845
uses: actions/upload-artifact@v4
4946
with:
5047
name: ${{ steps.get_filename.outputs.plugin_filename }}
@@ -57,16 +54,28 @@ jobs:
5754
with:
5855
script: |
5956
const pr = context.payload.pull_request;
60-
const issueNumber = pr.body.match(/#(\d+)/)?.[1];
57+
const issueNumber = '${{ steps.check_issue.outputs.issue_number }}';
58+
const pluginFilename = '${{ steps.get_filename.outputs.plugin_filename }}';
59+
const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
60+
61+
await github.rest.issues.createComment({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: issueNumber,
65+
body: `A PR (#${pr.number}) has been opened to fix this issue. You can download the packaged plugin \`${pluginFilename}\` from the [GitHub Actions workflow run](${workflowRunUrl}) by clicking on the "Artifacts" dropdown.`
66+
});
67+
68+
- name: Comment on PR
69+
uses: actions/github-script@v6
70+
with:
71+
script: |
72+
const pr = context.payload.pull_request;
6173
const pluginFilename = '${{ steps.get_filename.outputs.plugin_filename }}';
74+
const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
6275
63-
if (issueNumber) {
64-
const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
65-
66-
await github.rest.issues.createComment({
67-
owner: context.repo.owner,
68-
repo: context.repo.repo,
69-
issue_number: issueNumber,
70-
body: `A PR (#${pr.number}) has been opened to fix this issue. You can download the packaged plugin \`${pluginFilename}\` from the [GitHub Actions workflow run](${workflowRunUrl}) by clicking on the "Artifacts" dropdown.`
71-
});
72-
}
76+
await github.rest.issues.createComment({
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
issue_number: pr.number,
80+
body: `📦 Plugin has been packaged for this PR. You can download \`${pluginFilename}\` from the [GitHub Actions workflow run](${workflowRunUrl}) by clicking on the "Artifacts" dropdown.`
81+
});

0 commit comments

Comments
 (0)