Skip to content

Commit 1703262

Browse files
authored
[3.12] Convert doc.yml workflow to be reusable (GH-103914 + GH-105151) (#107042)
Co-authored-by: Sviatoslav Sydorenko <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]> (cherry picked from commit 88d14da) (cherry picked from commit eaa6702)
1 parent ac6b0fb commit 1703262

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ permissions:
2828
contents: read
2929

3030
concurrency:
31-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
31+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-reusable
3232
cancel-in-progress: true
3333

3434
jobs:
@@ -37,6 +37,7 @@ jobs:
3737
runs-on: ubuntu-latest
3838
timeout-minutes: 10
3939
outputs:
40+
run-docs: ${{ steps.docs-changes.outputs.run-docs || false }}
4041
run_tests: ${{ steps.check.outputs.run_tests }}
4142
run_hypothesis: ${{ steps.check.outputs.run_hypothesis }}
4243
config_hash: ${{ steps.config_hash.outputs.hash }}
@@ -79,6 +80,29 @@ jobs:
7980
id: config_hash
8081
run: |
8182
echo "hash=${{ hashFiles('configure', 'configure.ac', '.github/workflows/build.yml') }}" >> $GITHUB_OUTPUT
83+
- name: Get a list of the changed documentation-related files
84+
if: github.event_name == 'pull_request'
85+
id: changed-docs-files
86+
uses: Ana06/[email protected]
87+
with:
88+
filter: |
89+
Doc/**
90+
Misc/**
91+
.github/workflows/reusable-docs.yml
92+
format: csv # works for paths with spaces
93+
- name: Check for docs changes
94+
if: >-
95+
github.event_name == 'pull_request'
96+
&& steps.changed-docs-files.outputs.added_modified_renamed != ''
97+
id: docs-changes
98+
run: |
99+
echo "run-docs=true" >> "${GITHUB_OUTPUT}"
100+
101+
check-docs:
102+
name: Docs
103+
needs: check_source
104+
if: fromJSON(needs.check_source.outputs.run-docs)
105+
uses: ./.github/workflows/reusable-docs.yml
82106

83107
check_abi:
84108
name: 'Check if the ABI has changed'

.github/workflows/doc.yml renamed to .github/workflows/reusable-docs.yml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
name: Docs
22

33
on:
4+
workflow_call:
45
workflow_dispatch:
5-
#push:
6-
# branches:
7-
# - 'main'
8-
# - '3.12'
9-
# - '3.11'
10-
# - '3.10'
11-
# - '3.9'
12-
# - '3.8'
13-
# - '3.7'
14-
# paths:
15-
# - 'Doc/**'
16-
pull_request:
17-
branches:
18-
- 'main'
19-
- '3.12'
20-
- '3.11'
21-
- '3.10'
22-
- '3.9'
23-
- '3.8'
24-
- '3.7'
25-
paths:
26-
- 'Doc/**'
27-
- 'Misc/**'
28-
- '.github/workflows/doc.yml'
296

307
permissions:
318
contents: read
@@ -61,12 +38,14 @@ jobs:
6138
uses: Ana06/[email protected]
6239
with:
6340
filter: "Doc/**"
41+
format: csv # works for paths with spaces
6442
- name: 'Build changed files in nit-picky mode'
6543
if: github.event_name == 'pull_request'
6644
continue-on-error: true
6745
run: |
46+
set -Eeuo pipefail
6847
# Mark files the pull request modified
69-
touch ${{ steps.changed_files.outputs.added_modified }}
48+
python Doc/tools/touch-clean-files.py --clean '${{ steps.changed_files.outputs.added_modified }}'
7049
# Build docs with the '-n' (nit-picky) option; convert warnings to annotations
7150
make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n --keep-going" html 2>&1 |
7251
python Doc/tools/warnings-to-gh-actions.py

Doc/tools/touch-clean-files.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Touch files that must pass Sphinx nit-picky mode
44
so they are rebuilt and we can catch regressions.
55
"""
6-
6+
import argparse
7+
import csv
8+
import sys
79
from pathlib import Path
810

911
wrong_directory_msg = "Must run this script from the repo root"
@@ -28,14 +30,33 @@
2830
rst for rst in Path("Doc/").rglob("*.rst") if rst.parts[1] not in EXCLUDE_SUBDIRS
2931
}
3032

31-
with Path("Doc/tools/.nitignore").open() as clean_files:
32-
DIRTY = {
33+
34+
parser = argparse.ArgumentParser(
35+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
36+
)
37+
parser.add_argument("-c", "--clean", help="Comma-separated list of clean files")
38+
args = parser.parse_args()
39+
40+
if args.clean:
41+
clean_files = next(csv.reader([args.clean]))
42+
CLEAN = {
3343
Path(filename.strip())
3444
for filename in clean_files
35-
if filename.strip() and not filename.startswith("#")
45+
if Path(filename.strip()).is_file()
3646
}
37-
38-
CLEAN = ALL_RST - DIRTY - EXCLUDE_FILES
47+
elif args.clean is not None:
48+
print(
49+
"Not touching any files: an empty string `--clean` arg value passed.",
50+
)
51+
sys.exit(0)
52+
else:
53+
with Path("Doc/tools/.nitignore").open() as ignored_files:
54+
IGNORED = {
55+
Path(filename.strip())
56+
for filename in ignored_files
57+
if filename.strip() and not filename.startswith("#")
58+
}
59+
CLEAN = ALL_RST - IGNORED - EXCLUDE_FILES
3960

4061
print("Touching:")
4162
for filename in sorted(CLEAN):

0 commit comments

Comments
 (0)