Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce25647921a8f82c3b5009bdd07a620545b91a0c
73 changes: 65 additions & 8 deletions .github/workflows/test-doc-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,58 @@ on:
permissions:
contents: read
jobs:

test-python-oldest:
name: Test in Python ${{ matrix.python-version }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
# If testing with in "act" on Macs, make sure to add '--container-architecture linux/amd64'.
python-version: [3.7]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Unit/system tests
if: success() || failure()
run: |
make -C test
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error

test-python-latest:
name: Test in Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# If testing with in "act" on Macs, make sure to add '--container-architecture linux/amd64'.
# Even then, old Python versions might not be available.
python-version: [3.x]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Unit/system tests
if: success() || failure()
run: |
make -C test
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error

lint-and-test-conda:
name: Lint and test in Conda env
runs-on: ubuntu-latest
Expand All @@ -26,28 +78,34 @@ jobs:
- name: Set up conda environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: doc-builder-python3.6
environment-file: test/python3.6_test_conda.yml
activate-environment: doc-builder-testing
environment-file: test/python_test_conda.yml
channels: conda-forge
auto-activate-base: false

- name: Pylint
run: |
cd test
conda run -n doc-builder-python3.6 make lint
conda run -n doc-builder-testing make lint

- name: Black
if: success() || failure()
run: |
cd test
conda run -n doc-builder-testing make black

- name: Unit/system tests
if: success() || failure()
run: |
conda run -n doc-builder-python3.6 make -C test
conda run -n doc-builder-testing make -C test
# -C test is needed because, if you just cd test/ beforehand, git commands in tests fail with an error

# File an issue if test failed during a scheduled or manual run
# File an issue if any of above jobs failed during a scheduled or manual run
file-issue-on-failure:
if: |
failure() &&
(needs.test-python-oldest.result == 'failure' || needs.test-python-latest.result == 'failure' || needs.lint-and-test-conda.result == 'failure') &&
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
needs: lint-and-test-conda
needs: [test-python-oldest, test-python-latest, lint-and-test-conda]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -60,4 +118,3 @@ jobs:
filename: .github/workflows/docs-ctsm_pylib.issue_template.md
update_existing: true
search_existing: open

2 changes: 1 addition & 1 deletion build_docs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ building the documentation.

from doc_builder import build_docs

if __name__ == '__main__':
if __name__ == "__main__":
build_docs.main()
72 changes: 44 additions & 28 deletions doc_builder/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# The path in Docker's filesystem where the user's home directory is mounted
_DOCKER_HOME = "/home/user/mounted_home"


def get_build_dir(build_dir=None, repo_root=None, version=None):
"""Return a string giving the path to the build directory.

Expand Down Expand Up @@ -43,8 +44,10 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
if not version_explicit:
branch_found, version = sys_utils.git_current_branch()
if not branch_found:
raise RuntimeError("Problem determining version based on git branch; "
"set --version on the command line.")
raise RuntimeError(
"Problem determining version based on git branch; "
"set --version on the command line."
)

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

return build_dir, version


def get_build_command(
build_dir,
run_from_dir,
Expand All @@ -84,24 +88,26 @@ def get_build_command(
with the given name
"""
if docker_name is None:
return _get_make_command(build_dir=build_dir,
build_target=build_target,
num_make_jobs=num_make_jobs,
warnings_as_warnings=warnings_as_warnings,
)
return _get_make_command(
build_dir=build_dir,
build_target=build_target,
num_make_jobs=num_make_jobs,
warnings_as_warnings=warnings_as_warnings,
)

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

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

errmsg_if_not_under_mountpoint = "build_docs must be run from somewhere in your home directory"
docker_workdir = _docker_path_from_local_path(
local_path=run_from_dir,
docker_mountpoint=docker_mountpoint,
errmsg_if_not_under_mountpoint=
"build_docs must be run from somewhere within your home directory")
errmsg_if_not_under_mountpoint=errmsg_if_not_under_mountpoint,
)

if os.path.isabs(build_dir):
build_dir_abs = build_dir
Expand All @@ -110,31 +116,40 @@ def get_build_command(
docker_build_dir = _docker_path_from_local_path(
local_path=build_dir_abs,
docker_mountpoint=docker_mountpoint,
errmsg_if_not_under_mountpoint=
"build directory must reside under your home directory")
errmsg_if_not_under_mountpoint="build directory must reside under your home directory",
)

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

make_command = _get_make_command(build_dir=docker_build_dir,
build_target=build_target,
num_make_jobs=num_make_jobs,
warnings_as_warnings=warnings_as_warnings,
)

docker_command = ["docker", "run",
"--name", docker_name,
"--user", f"{uid}:{gid}",
"--mount",
f"type=bind,source={docker_mountpoint},target={_DOCKER_HOME}",
"--workdir", docker_workdir,
"-t", # "-t" is needed for colorful output
"--rm",
"-e", f"current_version={version}",
docker_image] + make_command
make_command = _get_make_command(
build_dir=docker_build_dir,
build_target=build_target,
num_make_jobs=num_make_jobs,
warnings_as_warnings=warnings_as_warnings,
)

docker_command = [
"docker",
"run",
"--name",
docker_name,
"--user",
f"{uid}:{gid}",
"--mount",
f"type=bind,source={docker_mountpoint},target={_DOCKER_HOME}",
"--workdir",
docker_workdir,
"-t", # "-t" is needed for colorful output
"--rm",
"-e",
f"current_version={version}",
docker_image,
] + make_command
return docker_command


def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnings):
"""Return the make command to run (as a list)

Expand All @@ -149,6 +164,7 @@ def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnin
sphinxopts += "-W --keep-going"
return ["make", sphinxopts, builddir_arg, "-j", str(num_make_jobs), build_target]


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

Expand Down
Loading
Loading