-
Notifications
You must be signed in to change notification settings - Fork 22
RTD custom build #1096
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
Draft
atteggiani
wants to merge
3
commits into
development
Choose a base branch
from
davide/rtd_custom_build
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
RTD custom build #1096
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # This is a custom build script for mkdocs that checks for the branch name and exports | ||
| # a EDIT_URI env variable to be used in the mkdocs build to set edit_uri to the proper branch, | ||
| # especially for PR preview builds. | ||
| # If the build comes from a forked repo or from a tag, the EDIT_URI variable will not be set. | ||
| # This is needed to avoid the link-check workflow to fail for new pages if the edit_uri points to | ||
| # a non-existing file in the main branch. | ||
|
|
||
| set -e | ||
|
|
||
| if [ "$READTHEDOCS_VERSION_TYPE" == external ]; then # PR preview build | ||
| # Download jq | ||
| export JQ_EXE=$(pwd)/jq | ||
| JQ_VERSION='jq-1.8.1' | ||
| wget -q https://github.com/stedolan/jq/releases/download/$JQ_VERSION/jq-linux64 -O "$JQ_EXE" | ||
| chmod +x "$JQ_EXE" | ||
| "$JQ_EXE" --version | ||
| # Get full repo | ||
| full_repo=$(sed -E 's|.*github\.com[:/](.+)$|\1|' <<< "$READTHEDOCS_GIT_CLONE_URL") | ||
| # Remove .git suffix if present | ||
| full_repo=${full_repo%.git} | ||
| # Get repo and owner | ||
| IFS='/' read owner repo <<< "$full_repo" | ||
| # Check if the PR comes from a forked repo | ||
| gh_api_url="https://api.github.com/repos/$owner/$repo" | ||
| pr_info=$(curl -s "$gh_api_url/pulls/$READTHEDOCS_GIT_IDENTIFIER") | ||
| pr_head_owner=$("$JQ_EXE" -r '.head.user.login' <<< "$pr_info") | ||
| if [ "$owner" == "$pr_head_owner" ]; then # Not a fork | ||
| # Get the branch name | ||
| branch_name=$("$JQ_EXE" -r '.head.ref' <<< "$pr_info") | ||
| fi | ||
| elif git show-ref --heads "$READTHEDOCS_GIT_IDENTIFIER" --quiet; then # Branch build | ||
| branch_name="$READTHEDOCS_GIT_IDENTIFIER" | ||
| fi | ||
|
|
||
| # Download yq | ||
| export YQ_EXE=$(pwd)/yq | ||
| YQ_VERSION='v4.50.1' | ||
| wget -q https://github.com/mikefarah/yq/releases/download/$YQ_VERSION/yq_linux_amd64 -O "$YQ_EXE" | ||
| chmod +x "$YQ_EXE" | ||
| "$YQ_EXE" --version | ||
|
|
||
| # Get RTD config path | ||
| rtd_config_path=$(find "$READTHEDOCS_REPOSITORY_PATH" -type f \( -name ".readthedocs.yaml" -o -name ".readthedocs.yml" \)) | ||
| # Get mkdocs config path | ||
| mkdocs_path=$("$YQ_EXE" '.mkdocs.configuration' "$rtd_config_path") | ||
| if [ -n "$branch_name" ]; then | ||
| # Get docs_dir from mkdocs config or set to default 'docs' | ||
| docs_dir=$("$YQ_EXE" '.docs_dir // "docs"' "$mkdocs_path") | ||
| EDIT_URI="edit/$branch_name/$docs_dir" | ||
| echo "This is a branch build. EDIT_URI set to to '$EDIT_URI'" | ||
| export EDIT_URI | ||
| fi | ||
|
|
||
| # Default RTD mkdocs build commands | ||
| echo ======= START OF mkdocs.yml ======= | ||
| cat "$mkdocs_path" | ||
| echo ======= ENF OF mkdocs.yml ======= | ||
| cmd="python -m mkdocs build --clean --site-dir $READTHEDOCS_OUTPUT/html --config-file $mkdocs_path" | ||
| eval "$cmd" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, if this is running on GitHub Runners,
ghis installed, and may be a bit easier to work with than calling the api viacurlUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, unfortunately I don't think
ghis available out of the box within AWS instances.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the choice might be whether to download
gh(and usingjqwithin it), or downloadjqand usecurl ...for API queries (as it is done currently).Not sure if there's any preferred approach as we would always need to download something.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as a general approach, do you think it might make more sense to pin the versions of the external software we download instead of using
latest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think if you can get away with using
ghwith it's inbuiltjqthat would be cleaner. However note that you would need to find a way to pass a suitable GitHub PAT toghto enable use of it.And yes, pin versions of external software. It means one day when any of the tools has a breaking change, you won't need to spend time figuring out why the workflow broke!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I remember now I chose to use
curloverghso I wouldn't need a PAT. The problem is that secrets cannot be set in RTD to be used by PRs. Secrets can only be used by "internal" builds, otherwise they will need to be set as plain env variables (i.e., they will be visible to anyone that has access to the RTD project settings/build, and that's definitely not what we want).Therefore, I think I'll keep the use of
jqandyqas it is, but update the script to pin specific versions.