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

Conversation

humitos
Copy link
Member

@humitos humitos commented Mar 21, 2023

Introduce 3 new variables:

  • READTHEDOCS_REPOSITORY_URL
  • READTHEDOCS_REPOSITORY_IDENTIFIER
  • READTHEDOCS_REPOSITORY_IDENTIFIER_HASH

Closes #9423
Based on #10166


📚 Documentation previews 📚

humitos and others added 9 commits March 21, 2023 10:56
This variable communicates what's the canonical URL for the version it's running
the build. It will allow doctool/theme authors to implement the correct HTML tag
required:

```
<link rel="canonical" href="" />
```

Note the final `href` on each page will be `READTHEDOCS_CANONICAL_URL` + `page`.

Closes readthedocs/readthedocs-ops#1320
Add it to the reference page.
Co-authored-by: Benjamin Balder Bach <benjamin@readthedocs.org>
Co-authored-by: Benjamin Balder Bach <benjamin@readthedocs.org>
Introduce 3 new variables:

* `READTHEDOCS_REPOSITORY_URL`
* `READTHEDOCS_REPOSITORY_IDENTIFIER`
* `READTHEDOCS_REPOSITORY_IDENTIFIER_HASH`

Closes #9423
@humitos humitos requested review from a team as code owners March 21, 2023 12:11
@humitos humitos requested a review from benjaoming March 21, 2023 12:11
Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

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

I had a look at the tests for this, and it looks solid! It's a very nice pattern to be able to expand with more environment variables 💯

I'd like the documentation to be updated with a few tweaks, but otherwise I think that these 3 environment variables are good to ship and support in the future 👍

docs/user/reference/environment-variables.rst Outdated Show resolved Hide resolved
docs/user/reference/environment-variables.rst Outdated Show resolved Hide resolved
docs/user/reference/environment-variables.rst Outdated Show resolved Hide resolved
docs/user/reference/environment-variables.rst Show resolved Hide resolved
docs/user/reference/environment-variables.rst Outdated Show resolved Hide resolved
Co-authored-by: Benjamin Balder Bach <benjamin@readthedocs.org>
@humitos
Copy link
Member Author

humitos commented Mar 21, 2023

I think I accepted all the suggestions properly. -- let's see

@benjaoming
Copy link
Contributor

Yes, all looks good 👍

Base automatically changed from humitos/canonical-env to main March 22, 2023 08:26
@benjaoming
Copy link
Contributor

Git is weird sometimes... the base used to be humitos/canonical-env and that one got merged into main -- however, I still had to resolve a merge conflict in this PR with main... and the merge conflict was a block with changes and an empty block.. a merge conflict basically without any conflicting content 🤷

@benjaoming
Copy link
Contributor

Docs build failure = 2 warnings fixed in #10176

@humitos
Copy link
Member Author

humitos commented Mar 22, 2023

  • READTHEDOCS_REPOSITORY_URL

I just realized that this variable should probably be READTHEDOCS_REPOSITORY_CLONE_URL (project.repo) and we should have a READTHEDOCS_REPOSITORY_HTML_URL (project.remote_repository.html_url)

There are some use cases where we have the clone url, but we don't have the html one. They could be different and the clone url is not useful to generate links

@benjaoming
Copy link
Contributor

I did suggest it earlier :)
#9423 (comment)

We will want to expose `HTML_URL` as well, but that will require some extra work
since we don't have access to `RemoteRepository` from the builder.

I'm keeping it commented for now, but reserving the names.
@humitos humitos requested a review from ericholscher March 23, 2023 14:16
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

I have some quibbles on the naming, but I see it's been heavily discussed already, and I didn't read the backlog 🤣 . I think the examples are 💯 for making it very explicit what we're talking about, and the names aren't hugely important.

@@ -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_REPOSITORY_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.

Is there a reason we're calling it CLONE_URL, instead of REPOSITORY_URL to match the help_text?

This is the same URL defined in your Project's :term:dashboard in :menuselection:Admin --> Settings --> Repository URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's because the repository will also have a "web URL", i.e. the base URL for where the file can be viewed and edited, so ssh://git@webserver.com/repo is different from https://frontend.com/repo/

Copy link
Member

@ericholscher ericholscher Mar 23, 2023

Choose a reason for hiding this comment

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

Seems the doc is not correct then when it says it's the same as your Repository URL in the dashboard?

Users are definitely going to be confused if it's different, but only in some cases 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

"Repository URL in the dashboard" is what we use as Project.repo, which is the same of the content of this variable. Do you have a suggestion how to make this clearer? I think having all these URLs is just confusing, but necessary, tho.

I want to make the distinction between HTML_URL and CLONE_URL mainly because they are not going to be always the same. In community, they will mostly be the same, tho.

:Example: ``feature/signup``
:Example: ``update-readme``

.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER_HASH
Copy link
Member

Choose a reason for hiding this comment

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

I don't love how long this name is, but it seems reasonably explicit.

I think IDENTIFIER and HASH are kind of the same thing, but I'm not sure if git has a canonical name for this. I couldn't quickly find it in the docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added HASH here to be explicit about a commit in particular. We are using IDENTIFIER for the branch/tag name as well. I didn't find a better name for this 😞

:Example: ``https://github.com/readthedocs/readthedocs.org``
:Example: ``git@github.com:readthedocs/readthedocs.org.git``

.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER
Copy link
Member

@ericholscher ericholscher Mar 23, 2023

Choose a reason for hiding this comment

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

Is this a repository id? Or a version ID?

This is probably the name I'm the most unclear on whether it's correct.

Again though, perfect naming is hard, and the examples tell most of the story.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like READTHEDOCS_GIT_IDENTIFIER better. In fact I like everything better with git :)

READTHEDOCS_GIT_CLONE_URL
READTHEDOCS_GIT_COMMIT_HASH
READTHEDOCS_GIT_IDENTIFIER

it's easier to understand. I think the old VCS semi-supported backends can just have to deal with that. If we want to really support something, we might as well re-introduce "VCS" or have stuff like READTHEDOCS_HG_CLONE_URL... but that's not relevant now.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, if we wanted it to be generic, we could use VCS, but I agree GIT is probably better, and forward looking 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'm going to change the names to use GIT 👍🏼

@humitos
Copy link
Member Author

humitos commented Mar 27, 2023

the names aren't hugely important

I'd like to think a little more if necessary, since this is something we will need to maintain for a long time 😄 . However, it seems with the latest updates, we are all in the same page and the names communicate better what we are talking about.

We need to figure it out to expose READTHEDOCS_GIT_HTML_URL. However, I didn't want to block this PR on it because that will require a modification in the API and I'm not sure yet how to do it.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

These names are much more explicit with GIT in them 💯

We need to figure it out to expose READTHEDOCS_GIT_HTML_URL. However, I didn't want to block this PR on it because that will require a modification in the API and I'm not sure yet how to do it.

Can we copy GitHub here with naming? Is that what we're doing?

"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",

Via: https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-a-repository-readme

I couldn't find these names explained anywhere though 🙃 Naming is hard.

@@ -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 👍

@humitos
Copy link
Member Author

humitos commented Mar 28, 2023

Can we copy GitHub here with naming? Is that what we're doing?

Yes, something like that is what we are trying to follow. Hence the _URL and _CLONE urls.

@humitos humitos merged commit 8dd6732 into main Mar 28, 2023
@humitos humitos deleted the humitos/repository-env-variables branch March 28, 2023 08:33
@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Build: expose VCS-related environment variables
5 participants