Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1da538

Browse files
authored
Merge pull request #24731 from QuLogic/doc-post-errors
DOC: Post warnings as reviews on PRs
2 parents cc85fb6 + 9954248 commit a1da538

File tree

3 files changed

+139
-12
lines changed

3 files changed

+139
-12
lines changed

.circleci/config.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ commands:
141141
[ "$CIRCLE_PR_NUMBER" = "" ]; then
142142
export RELEASE_TAG='-t release'
143143
fi
144+
mkdir -p logs
144145
make html O="-T $RELEASE_TAG -j4 -w /tmp/sphinxerrorswarnings.log"
145146
rm -r build/html/_sources
146147
working_directory: doc
@@ -154,20 +155,35 @@ commands:
154155
- run:
155156
name: Extract possible build errors and warnings
156157
command: |
157-
(grep "WARNING\|ERROR" /tmp/sphinxerrorswarnings.log ||
158-
echo "No errors or warnings")
158+
(grep "WARNING\|ERROR" /tmp/sphinxerrorswarnings.log ||
159+
echo "No errors or warnings")
160+
# Save logs as an artifact, and convert from absolute paths to
161+
# repository-relative paths.
162+
sed "s~$PWD/~~" /tmp/sphinxerrorswarnings.log > \
163+
doc/logs/sphinx-errors-warnings.log
159164
when: always
165+
- store_artifacts:
166+
path: doc/logs/sphinx-errors-warnings.log
160167

161168
doc-show-deprecations:
162169
steps:
163170
- run:
164171
name: Extract possible deprecation warnings in examples and tutorials
165172
command: |
166-
(grep DeprecationWarning -r -l doc/build/html/gallery ||
167-
echo "No deprecation warnings in gallery")
168-
(grep DeprecationWarning -r -l doc/build/html/tutorials ||
169-
echo "No deprecation warnings in tutorials")
173+
(grep -rl DeprecationWarning doc/build/html/gallery ||
174+
echo "No deprecation warnings in gallery")
175+
(grep -rl DeprecationWarning doc/build/html/plot_types ||
176+
echo "No deprecation warnings in plot_types")
177+
(grep -rl DeprecationWarning doc/build/html/tutorials ||
178+
echo "No deprecation warnings in tutorials")
179+
# Save deprecations that are from this absolute directory, and
180+
# convert to repository-relative paths.
181+
(grep -Ero --no-filename "$PWD/.+DeprecationWarning.+$" \
182+
doc/build/html/{gallery,plot_types,tutorials} || echo) | \
183+
sed "s~$PWD/~~" > doc/logs/sphinx-deprecations.log
170184
when: always
185+
- store_artifacts:
186+
path: doc/logs/sphinx-deprecations.log
171187

172188
doc-bundle:
173189
steps:

.circleci/fetch_doc_logs.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Download artifacts from CircleCI for a documentation build.
3+
4+
This is run by the :file:`.github/workflows/circleci.yml` workflow in order to
5+
get the warning/deprecation logs that will be posted on commits as checks. Logs
6+
are downloaded from the :file:`docs/logs` artifact path and placed in the
7+
:file:`logs` directory.
8+
9+
Additionally, the artifact count for a build is produced as a workflow output,
10+
by appending to the file specified by :env:`GITHUB_OUTPUT`.
11+
12+
If there are no logs, an "ERROR" message is printed, but this is not fatal, as
13+
the initial 'status' workflow runs when the build has first started, and there
14+
are naturally no artifacts at that point.
15+
16+
This script should be run by passing the CircleCI build URL as its first
17+
argument. In the GitHub Actions workflow, this URL comes from
18+
``github.event.target_url``.
19+
"""
20+
import json
21+
import os
22+
from pathlib import Path
23+
import sys
24+
from urllib.parse import urlparse
25+
from urllib.request import urlopen
26+
27+
28+
if len(sys.argv) != 2:
29+
print('USAGE: fetch_doc_results.py CircleCI-build-url')
30+
sys.exit(1)
31+
32+
target_url = urlparse(sys.argv[1])
33+
*_, organization, repository, build_id = target_url.path.split('/')
34+
print(f'Fetching artifacts from {organization}/{repository} for {build_id}')
35+
36+
artifact_url = (
37+
f'https://circleci.com/api/v2/project/gh/'
38+
f'{organization}/{repository}/{build_id}/artifacts'
39+
)
40+
print(artifact_url)
41+
with urlopen(artifact_url) as response:
42+
artifacts = json.load(response)
43+
artifact_count = len(artifacts['items'])
44+
print(f'Found {artifact_count} artifacts')
45+
46+
with open(os.environ['GITHUB_OUTPUT'], 'w+') as fd:
47+
fd.write(f'count={artifact_count}\n')
48+
49+
logs = Path('logs')
50+
logs.mkdir(exist_ok=True)
51+
52+
found = False
53+
for item in artifacts['items']:
54+
path = item['path']
55+
if path.startswith('doc/logs/'):
56+
path = Path(path).name
57+
print(f'Downloading {path} from {item["url"]}')
58+
with urlopen(item['url']) as response:
59+
(logs / path).write_bytes(response.read())
60+
found = True
61+
62+
if not found:
63+
print('ERROR: Did not find any artifact logs!')

.github/workflows/circleci.yml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2+
name: "CircleCI artifact handling"
23
on: [status]
3-
permissions:
4-
statuses: write
54
jobs:
65
circleci_artifacts_redirector_job:
7-
runs-on: ubuntu-latest
86
if: "${{ github.event.context == 'ci/circleci: docs-python38' }}"
7+
permissions:
8+
statuses: write
9+
runs-on: ubuntu-latest
910
name: Run CircleCI artifacts redirector
1011
steps:
1112
- name: GitHub Action step
@@ -15,7 +16,54 @@ jobs:
1516
artifact-path: 0/doc/build/html/index.html
1617
circleci-jobs: docs-python38
1718
job-title: View the built docs
18-
- name: Check the URL
19-
if: github.event.status != 'pending'
19+
20+
post_warnings_as_review:
21+
if: "${{ github.event.context == 'ci/circleci: docs-python38' }}"
22+
permissions:
23+
contents: read
24+
checks: write
25+
pull-requests: write
26+
runs-on: ubuntu-latest
27+
name: Post warnings/errors as review
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Fetch result artifacts
32+
id: fetch-artifacts
33+
run: |
34+
python .circleci/fetch_doc_logs.py "${{ github.event.target_url }}"
35+
36+
- name: Set up reviewdog
37+
if: "${{ steps.fetch-artifacts.outputs.count != 0 }}"
38+
uses: reviewdog/action-setup@v1
39+
with:
40+
reviewdog_version: latest
41+
42+
- name: Post review
43+
if: "${{ steps.fetch-artifacts.outputs.count != 0 }}"
44+
env:
45+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
REVIEWDOG_SKIP_DOGHOUSE: "true"
47+
CI_COMMIT: ${{ github.event.sha }}
48+
CI_REPO_OWNER: ${{ github.event.repository.owner.login }}
49+
CI_REPO_NAME: ${{ github.event.repository.name }}
2050
run: |
21-
curl --fail ${{ steps.step1.outputs.url }} | grep $GITHUB_SHA
51+
# The 'status' event does not contain information in the way that
52+
# reviewdog expects, so we unset those so it reads from the
53+
# environment variables we set above.
54+
unset GITHUB_ACTIONS GITHUB_EVENT_PATH
55+
cat logs/sphinx-errors-warnings.log | \
56+
reviewdog \
57+
-efm '%f\:%l: %tEBUG: %m' \
58+
-efm '%f\:%l: %tNFO: %m' \
59+
-efm '%f\:%l: %tARNING: %m' \
60+
-efm '%f\:%l: %tRROR: %m' \
61+
-efm '%f\:%l: %tEVERE: %m' \
62+
-efm '%f\:%s: %tARNING: %m' \
63+
-efm '%f\:%s: %tRROR: %m' \
64+
-name=sphinx -tee -fail-on-error=false \
65+
-reporter=github-check -filter-mode=nofilter
66+
cat logs/sphinx-deprecations.log | \
67+
reviewdog \
68+
-efm '%f\:%l: %m' \
69+
-name=examples -tee -reporter=github-check -filter-mode=nofilter

0 commit comments

Comments
 (0)