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

Skip to content

Commit 9954248

Browse files
committed
ci: Post doc results as reviews
1 parent 3838195 commit 9954248

File tree

2 files changed

+118
-3
lines changed

2 files changed

+118
-3
lines changed

.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: 55 additions & 3 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,3 +16,54 @@ jobs:
1516
artifact-path: 0/doc/build/html/index.html
1617
circleci-jobs: docs-python38
1718
job-title: View the built docs
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 }}
50+
run: |
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)