From a4f030be54559245cf3219a43cefafd09589bc98 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 25 Apr 2023 01:24:21 -0600 Subject: [PATCH 1/5] Replace Netlify with Read the Docs build previews --- .github/workflows/documentation-links.yml | 21 +++++++++++++++++++++ .readthedocs.yml | 18 ++++++++++++++++++ Doc/conf.py | 11 ++++++----- Doc/tools/templates/layout.html | 5 ----- netlify.toml | 11 ----------- 5 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/documentation-links.yml create mode 100644 .readthedocs.yml delete mode 100644 netlify.toml diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml new file mode 100644 index 00000000000000..21d21ec550cd84 --- /dev/null +++ b/.github/workflows/documentation-links.yml @@ -0,0 +1,21 @@ +name: Read the Docs PR preview +on: + pull_request_target: + types: + - opened + paths: + - 'Doc/**' + - 'Misc/**' + - '.github/workflows/doc.yml' + +permissions: + pull-requests: write + +jobs: + documentation-links: + runs-on: ubuntu-latest + steps: + - uses: readthedocs/actions/preview@v1 + with: + project-slug: "cpython-devguide" + single-version: "true" diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 00000000000000..898a9ae89dbb92 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,18 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details +# Project page: https://readthedocs.org/projects/cpython-previews/ + +version: 2 + +sphinx: + configuration: Doc/conf.py + +build: + os: ubuntu-22.04 + tools: + python: "3" + + commands: + - make -C Doc venv html + - mkdir _readthedocs + - mv Doc/build/html _readthedocs/html diff --git a/Doc/conf.py b/Doc/conf.py index 42c23bf77c7034..4f614cfd3ff262 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -114,12 +114,13 @@ # Short title used e.g. for HTML tags. html_short_title = '%s Documentation' % release -# Deployment preview information, from Netlify -# (See netlify.toml and https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) +# Deployment preview information +# (See .readthedocs.yml and https://docs.readthedocs.io/en/stable/reference/environment-variables.html) +repository_url = os.getenv("READTHEDOCS_GIT_CLONE_URL") html_context = { - "is_deployment_preview": os.getenv("IS_DEPLOYMENT_PREVIEW"), - "repository_url": os.getenv("REPOSITORY_URL"), - "pr_id": os.getenv("REVIEW_ID") + "is_deployment_preview": os.getenv("READTHEDOCS"), + "repository_url": repository_url.removesuffix(".git") if repository_url else None, + "pr_id": os.getenv("READTHEDOCS_VERSION") } # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, diff --git a/Doc/tools/templates/layout.html b/Doc/tools/templates/layout.html index 460161cd320223..b91f8138553e62 100644 --- a/Doc/tools/templates/layout.html +++ b/Doc/tools/templates/layout.html @@ -11,11 +11,6 @@ {%- if is_deployment_preview %} <div id="deployment-preview-warning" style="padding: .5em; text-align: center; background-color: #fff2ba; color: #6a580e;"> - <div style="float: right; margin-top: -10px; margin-left: 10px;"> - <a href="https://www.netlify.com"> - <img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" alt="Deploys by Netlify" /> - </a> - </div> {% trans %}This is a deploy preview created from a <a href="{{ repository_url }}/pull/{{ pr_id }}">pull request</a>. For authoritative documentation, see the {% endtrans %} <a href="https://docs.python.org/3/{{ pagename }}{{ file_suffix }}">{% trans %} the current stable release{% endtrans %}</a>. diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index f5790fc5fec74f..00000000000000 --- a/netlify.toml +++ /dev/null @@ -1,11 +0,0 @@ -[build] - base = "Doc/" - command = "make html" - publish = "build/html" - # Do not trigger netlify builds if docs were not changed. - # Changed files should be in sync with `.github/workflows/doc.yml` - ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../netlify.toml" - -[build.environment] - PYTHON_VERSION = "3.8" - IS_DEPLOYMENT_PREVIEW = "true" From 8008308032325f9e5ee7b6f30f96e2dfa2d85940 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <hugovk@users.noreply.github.com> Date: Wed, 26 Apr 2023 12:34:36 -0600 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Oleg Iarygin <dralife@yandex.ru> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> --- .github/workflows/documentation-links.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml index 21d21ec550cd84..138bbe8be14fc9 100644 --- a/.github/workflows/documentation-links.yml +++ b/.github/workflows/documentation-links.yml @@ -5,7 +5,6 @@ on: - opened paths: - 'Doc/**' - - 'Misc/**' - '.github/workflows/doc.yml' permissions: @@ -17,5 +16,5 @@ jobs: steps: - uses: readthedocs/actions/preview@v1 with: - project-slug: "cpython-devguide" + project-slug: "cpython-previews" single-version: "true" From c421383d9dead2544015434652ed1c15accaf93c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <hugovk@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:38:33 +0300 Subject: [PATCH 3/5] Cancel in-progress workflows --- .github/workflows/documentation-links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml index 138bbe8be14fc9..cfe3859d689cd3 100644 --- a/.github/workflows/documentation-links.yml +++ b/.github/workflows/documentation-links.yml @@ -10,6 +10,10 @@ on: permissions: pull-requests: write +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: documentation-links: runs-on: ubuntu-latest From 2d049975a18cce6d171e703ac4d8b37955fad88b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <hugovk@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:40:48 +0300 Subject: [PATCH 4/5] Set is_deployment_preview flag for PR builds instead of all RtD builds --- Doc/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/conf.py b/Doc/conf.py index 4f614cfd3ff262..cef2a0e2837f6a 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -118,7 +118,7 @@ # (See .readthedocs.yml and https://docs.readthedocs.io/en/stable/reference/environment-variables.html) repository_url = os.getenv("READTHEDOCS_GIT_CLONE_URL") html_context = { - "is_deployment_preview": os.getenv("READTHEDOCS"), + "is_deployment_preview": os.getenv("READTHEDOCS_VERSION_TYPE") == "external", "repository_url": repository_url.removesuffix(".git") if repository_url else None, "pr_id": os.getenv("READTHEDOCS_VERSION") } From 8d7a5713737997e4c340ad2af8c477a25da272ef Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <hugovk@users.noreply.github.com> Date: Thu, 27 Apr 2023 11:00:03 +0300 Subject: [PATCH 5/5] Add a comment describing the purpose of the workflow --- .github/workflows/documentation-links.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml index cfe3859d689cd3..43a7afec73884e 100644 --- a/.github/workflows/documentation-links.yml +++ b/.github/workflows/documentation-links.yml @@ -1,4 +1,7 @@ name: Read the Docs PR preview +# Automatically edits a pull request's descriptions with a link +# to the documentation's preview on Read the Docs. + on: pull_request_target: types: