Skip to content

Commit 9a25c4a

Browse files
authored
Merge pull request #9 from ESMCI/more-github-tests
More GitHub tests; update minimum Python to 3.7
2 parents d16e162 + f7a56c3 commit 9a25c4a

17 files changed

+842
-494
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ce25647921a8f82c3b5009bdd07a620545b91a0c

.github/workflows/test-doc-builder.yml

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ on:
1414
permissions:
1515
contents: read
1616
jobs:
17+
18+
test-python-oldest:
19+
name: Test in Python ${{ matrix.python-version }}
20+
runs-on: ubuntu-22.04
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
# If testing with in "act" on Macs, make sure to add '--container-architecture linux/amd64'.
25+
python-version: [3.7]
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
lfs: true
31+
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
37+
- name: Unit/system tests
38+
if: success() || failure()
39+
run: |
40+
make -C test
41+
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error
42+
43+
test-python-latest:
44+
name: Test in Python ${{ matrix.python-version }}
45+
runs-on: ubuntu-latest
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
# If testing with in "act" on Macs, make sure to add '--container-architecture linux/amd64'.
50+
# Even then, old Python versions might not be available.
51+
python-version: [3.x]
52+
steps:
53+
- uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0
56+
lfs: true
57+
58+
- name: Set up Python ${{ matrix.python-version }}
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
63+
- name: Unit/system tests
64+
if: success() || failure()
65+
run: |
66+
make -C test
67+
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error
68+
1769
lint-and-test-conda:
1870
name: Lint and test in Conda env
1971
runs-on: ubuntu-latest
@@ -26,28 +78,34 @@ jobs:
2678
- name: Set up conda environment
2779
uses: conda-incubator/setup-miniconda@v3
2880
with:
29-
activate-environment: doc-builder-python3.6
30-
environment-file: test/python3.6_test_conda.yml
81+
activate-environment: doc-builder-testing
82+
environment-file: test/python_test_conda.yml
3183
channels: conda-forge
3284
auto-activate-base: false
3385

3486
- name: Pylint
3587
run: |
3688
cd test
37-
conda run -n doc-builder-python3.6 make lint
89+
conda run -n doc-builder-testing make lint
90+
91+
- name: Black
92+
if: success() || failure()
93+
run: |
94+
cd test
95+
conda run -n doc-builder-testing make black
3896
3997
- name: Unit/system tests
4098
if: success() || failure()
4199
run: |
42-
conda run -n doc-builder-python3.6 make -C test
100+
conda run -n doc-builder-testing make -C test
43101
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error
44102

45-
# File an issue if test failed during a scheduled or manual run
103+
# File an issue if any of above jobs failed during a scheduled or manual run
46104
file-issue-on-failure:
47105
if: |
48-
failure() &&
106+
(needs.test-python-oldest.result == 'failure' || needs.test-python-latest.result == 'failure' || needs.lint-and-test-conda.result == 'failure') &&
49107
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
50-
needs: lint-and-test-conda
108+
needs: [test-python-oldest, test-python-latest, lint-and-test-conda]
51109
runs-on: ubuntu-latest
52110
steps:
53111
- uses: actions/checkout@v3
@@ -60,4 +118,3 @@ jobs:
60118
filename: .github/workflows/docs-ctsm_pylib.issue_template.md
61119
update_existing: true
62120
search_existing: open
63-

build_docs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ building the documentation.
1010

1111
from doc_builder import build_docs
1212

13-
if __name__ == '__main__':
13+
if __name__ == "__main__":
1414
build_docs.main()

doc_builder/build_commands.py

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# The path in Docker's filesystem where the user's home directory is mounted
1212
_DOCKER_HOME = "/home/user/mounted_home"
1313

14+
1415
def get_build_dir(build_dir=None, repo_root=None, version=None):
1516
"""Return a string giving the path to the build directory.
1617
@@ -43,8 +44,10 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
4344
if not version_explicit:
4445
branch_found, version = sys_utils.git_current_branch()
4546
if not branch_found:
46-
raise RuntimeError("Problem determining version based on git branch; "
47-
"set --version on the command line.")
47+
raise RuntimeError(
48+
"Problem determining version based on git branch; "
49+
"set --version on the command line."
50+
)
4851

4952
build_dir_no_version = os.path.join(repo_root, "versions")
5053
if not os.path.isdir(build_dir_no_version):
@@ -60,6 +63,7 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
6063

6164
return build_dir, version
6265

66+
6367
def get_build_command(
6468
build_dir,
6569
run_from_dir,
@@ -84,24 +88,26 @@ def get_build_command(
8488
with the given name
8589
"""
8690
if docker_name is None:
87-
return _get_make_command(build_dir=build_dir,
88-
build_target=build_target,
89-
num_make_jobs=num_make_jobs,
90-
warnings_as_warnings=warnings_as_warnings,
91-
)
91+
return _get_make_command(
92+
build_dir=build_dir,
93+
build_target=build_target,
94+
num_make_jobs=num_make_jobs,
95+
warnings_as_warnings=warnings_as_warnings,
96+
)
9297

9398
# But if we're using Docker, we have more work to do to create the command....
9499

95100
# Mount the user's home directory in the Docker image; this assumes that both
96101
# run_from_dir and build_dir reside somewhere under the user's home directory (we
97102
# check this assumption below).
98-
docker_mountpoint = os.path.expanduser('~')
103+
docker_mountpoint = os.path.expanduser("~")
99104

105+
errmsg_if_not_under_mountpoint = "build_docs must be run from somewhere in your home directory"
100106
docker_workdir = _docker_path_from_local_path(
101107
local_path=run_from_dir,
102108
docker_mountpoint=docker_mountpoint,
103-
errmsg_if_not_under_mountpoint=
104-
"build_docs must be run from somewhere within your home directory")
109+
errmsg_if_not_under_mountpoint=errmsg_if_not_under_mountpoint,
110+
)
105111

106112
if os.path.isabs(build_dir):
107113
build_dir_abs = build_dir
@@ -110,31 +116,40 @@ def get_build_command(
110116
docker_build_dir = _docker_path_from_local_path(
111117
local_path=build_dir_abs,
112118
docker_mountpoint=docker_mountpoint,
113-
errmsg_if_not_under_mountpoint=
114-
"build directory must reside under your home directory")
119+
errmsg_if_not_under_mountpoint="build directory must reside under your home directory",
120+
)
115121

116122
# Get current user's UID and GID
117123
uid = os.getuid()
118124
gid = os.getgid()
119125

120-
make_command = _get_make_command(build_dir=docker_build_dir,
121-
build_target=build_target,
122-
num_make_jobs=num_make_jobs,
123-
warnings_as_warnings=warnings_as_warnings,
124-
)
125-
126-
docker_command = ["docker", "run",
127-
"--name", docker_name,
128-
"--user", f"{uid}:{gid}",
129-
"--mount",
130-
f"type=bind,source={docker_mountpoint},target={_DOCKER_HOME}",
131-
"--workdir", docker_workdir,
132-
"-t", # "-t" is needed for colorful output
133-
"--rm",
134-
"-e", f"current_version={version}",
135-
docker_image] + make_command
126+
make_command = _get_make_command(
127+
build_dir=docker_build_dir,
128+
build_target=build_target,
129+
num_make_jobs=num_make_jobs,
130+
warnings_as_warnings=warnings_as_warnings,
131+
)
132+
133+
docker_command = [
134+
"docker",
135+
"run",
136+
"--name",
137+
docker_name,
138+
"--user",
139+
f"{uid}:{gid}",
140+
"--mount",
141+
f"type=bind,source={docker_mountpoint},target={_DOCKER_HOME}",
142+
"--workdir",
143+
docker_workdir,
144+
"-t", # "-t" is needed for colorful output
145+
"--rm",
146+
"-e",
147+
f"current_version={version}",
148+
docker_image,
149+
] + make_command
136150
return docker_command
137151

152+
138153
def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnings):
139154
"""Return the make command to run (as a list)
140155
@@ -149,6 +164,7 @@ def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnin
149164
sphinxopts += "-W --keep-going"
150165
return ["make", sphinxopts, builddir_arg, "-j", str(num_make_jobs), build_target]
151166

167+
152168
def _docker_path_from_local_path(local_path, docker_mountpoint, errmsg_if_not_under_mountpoint):
153169
"""Given a path on the local file system, return the equivalent path in Docker space
154170

0 commit comments

Comments
 (0)