Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: implement build.jobs config file key #9016

Merged
merged 17 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,6 @@ def validate_build_config_with_tools(self):
)

build["jobs"] = {}
for job in BuildJobs.__slots__:
build["jobs"][job] = []

for job, commands in jobs.items():
with self.catch_validation_error(f"build.jobs.{job}"):
build["jobs"][job] = [
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class BuildJobs(Base):
"post_build",
)

def __init__(self, **kwargs):
humitos marked this conversation as resolved.
Show resolved Hide resolved
for step in self.__slots__:
kwargs.setdefault(step, [])
super().__init__(**kwargs)


class Python(Base):

Expand Down
27 changes: 27 additions & 0 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,33 @@ def build_epub(self):
return False

def run_build_job(self, job):
humitos marked this conversation as resolved.
Show resolved Hide resolved
"""
Run a command specified by the user under `build.jobs.` config key.

It uses the "VCS environment" for pre_/post_ checkout jobs and "build
environment" for the rest of them.

Note that user's commands:

- are not escaped
- are run with under the path where the repository was cloned
- are run as RTD_DOCKER_USER user
- users can't run commands as `root` user
- all the user's commands receive environment variables
humitos marked this conversation as resolved.
Show resolved Hide resolved

Example:

build:
jobs:
pre_install:
- echo `date`
- python path/to/myscript.py
pre_build:
- sed -i **/*.rst -e "s|{version}|v3.5.1|g"

In this case, `self.data.config.build.jobs.pre_build` will contains
`sed` command.
humitos marked this conversation as resolved.
Show resolved Hide resolved
"""
if (
getattr(self.data.config.build, "jobs", None) is None
or getattr(self.data.config.build.jobs, job, None) is None
Expand Down