GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pmd/.github/workflows/publish-pull-requests.yml at main · pmd/pmd

Expand file tree

/

publish-pull-requests.yml

Copy path
View runs
More file actions
More file actions

Latest commit

 

History

History
History
215 lines (206 loc) · 10.1 KB
/

publish-pull-requests.yml

Copy path

File metadata and controls

215 lines (206 loc) · 10.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Publish Results from Pull Requests
run-name: Publish Results for "${{ github.event.workflow_run.display_title }}"
on:
workflow_run:
workflows: [Build Pull Request]
types:
- completed
permissions: {}
jobs:
publish:
# only run in the official pmd repo, where we have access to the secrets and not on forks
# and only run for _successful_ pull requests workflow runs.
if: ${{ github.repository == 'pmd/pmd'
&& github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
steps:
- uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc #v3.4.0
id: pmd-actions-helper-app-token
with:
client-id: ${{ secrets.PMD_ACTIONS_HELPER_CLIENT_ID }}
private-key: ${{ secrets.PMD_ACTIONS_HELPER_PRIVATE_KEY }}
owner: pmd
repositories: pmd
permission-actions: read # download workflow run artifacts
permission-checks: write
permission-statuses: write
permission-pull-requests: write # in order to add/update a comment
- name: 'Get PR context'
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
# If the PR is from a fork, prefix it with `<owner-login>:`, otherwise only the PR branch name is relevant:
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
PR_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
# Query the PR number by repo + branch, then assign to step output:
PR_NUMBER="$(gh pr view --repo pmd/pmd "${PR_BRANCH}" --json 'number' --jq '.number')"
echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_ENV}"
echo "PR_BRANCH=${PR_BRANCH}" >> "${GITHUB_ENV}"
echo "PR_SHA=${PR_SHA}" >> "${GITHUB_ENV}"
- name: Add Job Summary
env:
WORKFLOW_RUN_DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }}
WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_RUN_NUMBER: ${{ github.event.workflow_run.run_number }}
WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }}
run: |
echo "### Run Info" >> "${GITHUB_STEP_SUMMARY}"
echo "Triggered for PR [#${PR_NUMBER}](https://github.com/pmd/pmd/pull/${PR_NUMBER})" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
echo "Called by [${WORKFLOW_RUN_DISPLAY_TITLE} (${WORKFLOW_RUN_NAME} #${WORKFLOW_RUN_NUMBER})](${WORKFLOW_RUN_HTML_URL})" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
- name: Download docs-artifact
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
mkdir docs-artifact
cd docs-artifact
# gh run download "${RUN_ID}" --repo pmd/pmd --name docs-artifact
# apply workaround for https://github.com/cli/cli/issues/12437
download_url=$(gh api \
"/repos/pmd/pmd/actions/runs/$RUN_ID/artifacts?name=docs-artifact" \
--jq '.artifacts|sort_by(.created_at)|.[-1]|.archive_download_url' \
)
curl -L \
-H "Authorization: Bearer $GH_TOKEN" \
--output artifact.zip \
$download_url
unzip -q artifact.zip
rm artifact.zip
- name: Upload docs-artifact to s3://pmd-pull-requests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_PMD_PULL_REQUESTS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_PMD_PULL_REQUESTS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
run: |
aws s3 sync docs-artifact "s3://pmd-pull-requests/pr-${PR_NUMBER}/${PR_SHA}/docs" --no-progress
echo "public url: https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/docs"
- name: Add commit status (Documentation)
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/pmd/pmd/statuses/${PR_SHA}" \
-f "state=success" -f "target_url=https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/docs" \
-f "description=PMD Documentation Preview" -f "context=Published Results / Documentation"
- name: Add Check Status (Documentation)
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
run: |
timestamp="$(date -uIs)"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/pmd/pmd/check-runs \
-f "name=Documentation" -f "head_sha=${PR_SHA}" -f "status=completed" \
-f "started_at=${timestamp}" -f "conclusion=success" -f "completed_at=${timestamp}" \
-f "output[title]=Documentation Preview" -f "output[summary]=[Documentation Preview](https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/docs)"
- name: Download pmd-regression-tester
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
mkdir pmd-regression-tester
cd pmd-regression-tester
# gh run download "${RUN_ID}" --repo pmd/pmd --name pmd-regression-tester
# apply workaround for https://github.com/cli/cli/issues/12437
download_url=$(gh api \
"/repos/pmd/pmd/actions/runs/$RUN_ID/artifacts?name=pmd-regression-tester" \
--jq '.artifacts|sort_by(.created_at)|.[-1]|.archive_download_url' \
)
curl -L \
-H "Authorization: Bearer $GH_TOKEN" \
--output artifact.zip \
$download_url
unzip -q artifact.zip
rm artifact.zip
- name: Upload regression report to s3://pmd-pull-requests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_PMD_PULL_REQUESTS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_PMD_PULL_REQUESTS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
run: |
if [ -e "pmd-regression-tester/index.html" ]; then
aws s3 sync pmd-regression-tester "s3://pmd-pull-requests/pr-${PR_NUMBER}/${PR_SHA}/regression" --no-progress
echo "public url: https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/regression"
echo "REGRESSION_REPORT_UPLOADED=1" >> "${GITHUB_ENV}"
else
echo "No report available."
echo "REGRESSION_REPORT_UPLOADED=0" >> "${GITHUB_ENV}"
fi
- name: Add commit status (Regression Tester)
if: ${{ env.REGRESSION_REPORT_UPLOADED == 1 }}
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/pmd/pmd/statuses/${PR_SHA}" \
-f "state=success" -f "target_url=https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/regression" \
-f "description=PMD Regression Tester Report" -f "context=Published Results / Regression Tester"
- name: Prepare regression summary
run: |
summary="$(cat pmd-regression-tester/summary.txt)"
if [ "$REGRESSION_REPORT_UPLOADED" = "1" ]; then
summary="
${summary}
[Regression Tester Report](https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/regression)
"
fi
echo "${summary}" > pmd-regression-tester/summary.txt
- name: Add Check Status (Regression Tester)
env:
# Token required for GH CLI:
GH_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
run: |
timestamp="$(date -uIs)"
summary="$(cat pmd-regression-tester/summary.txt)"
# conclusion can be one of: action_required, cancelled, failure, neutral, success, skipped, stale, timed_out
conclusion="$(cat pmd-regression-tester/conclusion.txt)"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/pmd/pmd/check-runs \
-f "name=Regression Tester" -f "head_sha=${PR_SHA}" -f "status=completed" \
-f "started_at=${timestamp}" -f "conclusion=${conclusion}" -f "completed_at=${timestamp}" \
-f "output[title]=Regression Tester Report" -f "output[summary]=${summary}"
- name: Prepare comment text
run: |
summary="$(cat pmd-regression-tester/summary.txt)"
comment="[Documentation Preview](https://pull-requests.pmd-code.org/pr-${PR_NUMBER}/${PR_SHA}/docs)
${summary}
(comment created at $(date -u --rfc-3339=seconds) for ${PR_SHA})
"
echo "${comment}" > comment.txt
echo "### Result" >> "${GITHUB_STEP_SUMMARY}"
echo "${comment}" >> "${GITHUB_STEP_SUMMARY}"
- uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 #v3.0.5
with:
GITHUB_TOKEN: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
header: pmd-publish-pull-requests
number: ${{ env.PR_NUMBER }}
path: comment.txt
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.