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

Skip to content

Commit 6fc3088

Browse files
committed
ci: Post doc results as reviews
1 parent a691980 commit 6fc3088

File tree

2 files changed

+99
-3
lines changed

2 files changed

+99
-3
lines changed

.circleci/fetch_doc_logs.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import json
2+
import os
3+
from pathlib import Path
4+
import sys
5+
from urllib.parse import urlparse
6+
from urllib.request import urlopen
7+
8+
9+
if len(sys.argv) != 2:
10+
print('USAGE: fetch_doc_results.py CircleCi-build-url')
11+
sys.exit()
12+
13+
target_url = urlparse(sys.argv[1])
14+
*_, organization, repository, build_id = target_url.path.split('/')
15+
print(f'Fetching artifacts from {organization}/{repository} for {build_id}')
16+
17+
artifact_url = (
18+
f'https://circleci.com/api/v2/project/gh/'
19+
f'{organization}/{repository}/{build_id}/artifacts'
20+
)
21+
print(artifact_url)
22+
with urlopen(artifact_url) as response:
23+
artifacts = json.load(response)
24+
artifact_count = len(artifacts['items'])
25+
print(f'Found {artifact_count} artifacts')
26+
27+
with open(os.environ['GITHUB_OUTPUT'], 'w+') as fd:
28+
fd.write(f'count={artifact_count}\n')
29+
30+
logs = Path('logs')
31+
logs.mkdir(exist_ok=True)
32+
33+
found = False
34+
for item in artifacts['items']:
35+
path = item['path']
36+
if path.startswith('doc/logs/'):
37+
path = Path(path).name
38+
print(f'Downloading {path} from {item["url"]}')
39+
with urlopen(item['url']) as response:
40+
(logs / path).write_bytes(response.read())
41+
found = True
42+
43+
if not found:
44+
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)