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: expose VCS-related environment variables #10168

Merged
merged 16 commits into from
Mar 28, 2023
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
25 changes: 25 additions & 0 deletions docs/user/reference/environment-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ All :doc:`build processes </builds>` have the following environment variables au
:Example: ``https://docs.readthedocs.io/ja/stable/``
:Example: ``https://example--17.org.readthedocs.build/fr/17/``

.. envvar:: READTHEDOCS_GIT_CLONE_URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clearer 👍


URL for the remote source repository, from which the documentation is cloned.
It could be HTTPS, SSH or any other URL scheme supported by Git.
This is the same URL defined in your Project's :term:`dashboard` in :menuselection:`Admin --> Settings --> Repository URL`.

:Example: ``https://github.com/readthedocs/readthedocs.org``
:Example: ``[email protected]:readthedocs/readthedocs.org.git``

.. envvar:: READTHEDOCS_GIT_IDENTIFIER

Contains the Git identifier that was *checked out* from the remote repository URL.
Possible values are either a branch or tag name.

:Example: ``v1.x``
:Example: ``bugfix/docs-typo``
:Example: ``feature/signup``
:Example: ``update-readme``

.. envvar:: READTHEDOCS_GIT_COMMIT_HASH

Git commit hash identifier checked out from the repository URL.
humitos marked this conversation as resolved.
Show resolved Hide resolved

:Example: ``1f94e04b7f596c309b7efab4e7630ed78e85a1f1``

.. seealso::

:doc:`/environment-variables`
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ def get_rtd_env_vars(self):
"READTHEDOCS_OUTPUT": os.path.join(
self.data.project.checkout_path(self.data.version.slug), "_readthedocs/"
),
"READTHEDOCS_GIT_CLONE_URL": self.data.project.repo,
# TODO: we don't have access to the database from the builder.
# We need to find a way to expose HTML_URL here as well.
# "READTHEDOCS_GIT_HTML_URL": self.data.project.remote_repository.html_url,
"READTHEDOCS_GIT_IDENTIFIER": self.data.version.identifier,
"READTHEDOCS_GIT_COMMIT_HASH": self.data.build["commit"],
}
return env

Expand Down
3 changes: 3 additions & 0 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ def test_get_env_vars(self, load_yaml_config, build_environment, config, externa
"READTHEDOCS_OUTPUT": os.path.join(
self.project.checkout_path(self.version.slug), "_readthedocs/"
),
"READTHEDOCS_GIT_CLONE_URL": self.project.repo,
"READTHEDOCS_GIT_IDENTIFIER": self.version.identifier,
"READTHEDOCS_GIT_COMMIT_HASH": self.build.commit,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the self.build.commit is None here?
And subprocess.popen doesn't accept a None value for environment variables?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that some of these values may be None if there is an error, we use docker, not sure if that also has a problem with None. Are you hitting this problem somwhere?

}

self._trigger_update_docs_task()
Expand Down