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

Auto-generate site URL if one is not given using CI/CD environment variables #93

Open
choldgraf opened this issue Dec 31, 2022 · 1 comment

Comments

@choldgraf
Copy link
Contributor

The ogp_site_url field is the only one strictly required by this extension, but I find that folks often forget to set it nonetheless. On many CI/CD systems, there are often environment variables that could be used as a fallback if site_url isn't present. This might be helpful for folks that forget or that simply don't want to have to worry about manually specifying the URL.

For example:

GitHub or ReadTheDocs examples

GitHub Actions have default environment variables for all actions. ReadTheDocs also has default environment variables.

Assuming that a person building Sphinx with GitHub Actions is using GitHub Pages (and same w/ ReadTheDocs) you could create a site URL using these variables.
For example:

import os
env = os.environ

if "GITHUB_ACTION" in env:
	site_url = f"https://{env['GITHUB_REPOSITORY_OWNER']}.github.io/{env['GITHUB_REPOSITORY']}"
elif "READTHEDOCS" in env:
    site_url = f"https://{env['READTHEDOCS_PROJECT']}.readthedocs.io/{env['READTHEDOCS_LANGUAGE']}/{env['READTHEDOCS_VERSION_NAME']}"
@TheTripleV
Copy link
Member

The site url is already autopopulated on ReadTheDocs so that case is taken care of.
I'm weary of automatically setting the site url in Github Actions. If a user uses Github Actions to build their docs and deploys the built docs/artifacts elsewhere, the url will silently be wrong.

If there's a way on Github Actions to detect if the build is being deployed to Github Pages, then I'd be open to adding the auto site url there too.

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

No branches or pull requests

2 participants