Skip to content

Commit 6157e20

Browse files
committed
1 parent c923cac commit 6157e20

File tree

2 files changed

+133
-16
lines changed

2 files changed

+133
-16
lines changed

.github/workflows/pr-comment.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Pull Request Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: [ 'Publish wiki' ]
6+
types:
7+
- completed
8+
9+
# Cancels all previous workflow runs for pull requests that have not completed.
10+
concurrency:
11+
# The concurrency group contains the workflow name and the branch name for pull requests
12+
# or the commit hash for any other events.
13+
group: ${{ github.workflow }}-${{ github.sha }}
14+
15+
jobs:
16+
artifact-review-comment:
17+
if: >
18+
github.repository == 'PHPCSStandards/PHP_CodeSniffer-documentation' &&
19+
github.event.workflow_run.event == 'pull_request' &&
20+
github.event.workflow_run.conclusion == 'success'
21+
22+
runs-on: ubuntu-latest
23+
24+
permissions:
25+
# Needed for the PR comment.
26+
pull-requests: write
27+
28+
name: Comment on a pull request
29+
30+
steps:
31+
- name: Download PR info artifact
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
run_id: context.payload.workflow_run.id,
39+
});
40+
41+
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
42+
return artifact.name == "pr_info"
43+
})[0];
44+
45+
if ( ! matchArtifact ) {
46+
core.setFailed( 'No artifact found!' );
47+
return;
48+
}
49+
50+
const download = await github.rest.actions.downloadArtifact({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
artifact_id: matchArtifact.id,
54+
archive_format: 'zip',
55+
});
56+
57+
const fs = require('fs');
58+
const path = require('path');
59+
const temp = '${{ runner.temp }}/artifacts';
60+
if (!fs.existsSync(temp)){
61+
fs.mkdirSync(temp);
62+
}
63+
fs.writeFileSync(path.join(temp, 'pr_info.zip'), Buffer.from(download.data));
64+
65+
- name: Unzip PR info artifact
66+
run: unzip pr_info.zip -d "${{ runner.temp }}/artifacts"
67+
68+
- name: "DEBUG: show dir layout"
69+
run: ls -aohR "${{ runner.temp }}/artifacts"
70+
71+
- name: Read PR number
72+
id: pr_number
73+
shell: bash
74+
run: |
75+
value=`cat "${{ runner.temp }}/artifacts/pr_number"`
76+
echo "PR_NR=$value" >> "$GITHUB_OUTPUT"
77+
78+
- name: Read Wiki artifact URL
79+
id: artifact_url
80+
shell: bash
81+
run: |
82+
value=`cat "${{ runner.temp }}/artifacts/artifact_url"`
83+
echo "URL=$value" >> "$GITHUB_OUTPUT"
84+
85+
- name: "DEBUG: show grabbed PR nr"
86+
run: echo ${{ steps.pr_number.outputs.PR_NR }}
87+
88+
- name: "DEBUG: show grabbed artifact URL"
89+
run: echo ${{ steps.artifact_url.outputs.URL }}
90+
91+
- name: "Post comment to review artifact"
92+
uses: mshick/add-pr-comment@v2
93+
with:
94+
issue: ${{ steps.pr_number.outputs.PR_NR }}
95+
repo-token: ${{ secrets.GITHUB_TOKEN }}
96+
message: |
97+
**_=== This is an auto-generated comment ===_**
98+
99+
Thank you for your PR.
100+
A dry-run has been executed on your PR, executing all markdown pre-processing for the wiki files.
101+
102+
Please review the resulting final markdown files via the [created artifact](${{ steps.artifact_url.outputs.URL }}).
103+
This is especially important when adding new pages or updating auto-generated output blocks.
104+
105+
_N.B.: the above link will automatically be updated when this PR is updated._

.github/workflows/publish-wiki.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ jobs:
126126
if-no-files-found: error
127127
retention-days: 10
128128

129-
- name: "[PR only] Post comment to review artifact"
130-
if: ${{ github.event_name == 'pull_request' }}
131-
uses: mshick/add-pr-comment@v2
132-
with:
133-
repo-token: ${{ secrets.COMMENT_ON_PRS_TOKEN }}
134-
message: |
135-
**_=== This is an auto-generated comment ===_**
136-
137-
Thank you for your PR.
138-
A dry-run has been executed on your PR, executing all markdown pre-processing for the wiki files.
139-
140-
Please review the resulting final markdown files via the [created artifact](${{ steps.artifact.outputs.artifact-url }}).
141-
This is especially important when adding new pages or updating auto-generated output blocks.
142-
143-
_N.B.: the above link will automatically be updated when this PR is updated._
144-
145129

146130
# ################################################################################
147131
# Deploy to the wiki in the PHPCS repo.
@@ -166,3 +150,31 @@ jobs:
166150
dry-run: ${{ github.event_name == 'pull_request' }}
167151
disable-empty-commits: true
168152
preprocess: false
153+
154+
155+
# ################################################################################
156+
# Dry-run/PRs: save PR info for use in Pull Request Comment workflow.
157+
# ################################################################################
158+
159+
- name: Create temporary directory
160+
if: ${{ github.event_name == 'pull_request' }}
161+
run: mkdir -p ./pr
162+
163+
- name: Save PR number
164+
if: ${{ github.event_name == 'pull_request' }}
165+
env:
166+
PR_NUMBER: ${{ github.event.number }}
167+
run: echo "${PR_NUMBER}" > ./pr/pr_number
168+
169+
- name: Save artifact URL
170+
if: ${{ github.event_name == 'pull_request' }}
171+
env:
172+
ARTIFACT_URL: ${{ steps.artifact.outputs.artifact-url }}
173+
run: echo "${ARTIFACT_URL}" > ./pr/artifact_url
174+
175+
- name: Upload PR info as artifact
176+
if: ${{ github.event_name == 'pull_request' }}
177+
uses: actions/upload-artifact@v4
178+
with:
179+
name: pr_info
180+
path: pr/

0 commit comments

Comments
 (0)