-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hosting: manual integrations via build contract (#10127)
* Hosting: manual integrations via build contract * Use a single script to load everything * Include Read the Docs analytics to integrations * Initial work for hosting features * External version banner and doc-diff integration * Old version warning * Do not inject doc-diff on search page * Inject old version warning only for non-external versions * Comments! * More comments * Build: pass `PATH` environment variable to Docker container Instead of prepending all the commands with the `PATH=` variable, we pass the environment variable directly to the Docker container. This allow us to run multi-line shell script without failing with weird syntax errors. Besides, the implementation is cleaner since all the environment variables are passed to the commands in the same way. I added some _default paths_ that I found by checking the local Docker container. I'm also passing the users' path, depending if we are working locally as root or in production. This is not 100% complete and there may be some other issues that I'm not seeing yet, but I think it's a first step to behave in a way our users are expecting. Closes #10103 * Lint: for some reason fails at CircleCI otherwise Locally it tries to reverted back 🤷 * Feature flag for new hosting integrations X-RTD-Hosting-Integration: true/false This can be used from CloudFlare to decide whether or not inject a `<script>` into the resulting HTML or not. * Load `readthedocs-build.yaml` and generate `readthedocs-data.html` * Load READTHEDOCS_DATA async * Absolute proxied API path * Remove duplicated code * New approach using `readthedocs-client.js` and `/_/readthedocs-config.json` See https://github.com/humitos/readthedocs-client * Do not require `readthedocs-build.YAML` for now * Expand the JSON response with more data * Remove non-required files and rely on `readthedocs-client.js` only * Improve helper text * Builds: save `readthedocs-build.yaml` into database I added a `Version.build_data` field that may be used from `/_/readthedocs-config.json` to extend with data generated by the doctool at build time if necessary. * Use `Version.build_data` from the endpoint * Flyout: return data required to generate flyout dynamically * Updates to the API * Minor updates * Update the javascript client compiled version * doc-diff object returned * Build: check if the YAML file exists before trying to open it * Proxito: don't inject the header if the feature is turned off * Test: add hosting integrations tests * Remove JS This file will be deployed directly into S3. * Load the javascript from a local server for now * Update URL to remove .json from it * Remove non-required f-string * Allow saving `build_data` via API endpoint * Lint * Migrate nodejs installation to asdf * Change port to match `npm run dev` from readthedocs-client
- Loading branch information
Showing
13 changed files
with
368 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
# Generated by Django 3.2.18 on 2023-03-13 15:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("builds", "0047_build_default_triggered"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="version", | ||
name="build_data", | ||
field=models.JSONField( | ||
default=None, | ||
null=True, | ||
verbose_name="Data generated at build time by the doctool (`readthedocs-build.yaml`).", | ||
), | ||
), | ||
] |
This file contains 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 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 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 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 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 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 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,123 @@ | ||
"""Test hosting views.""" | ||
|
||
import django_dynamic_fixture as fixture | ||
import pytest | ||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
from readthedocs.builds.constants import EXTERNAL, INTERNAL, LATEST | ||
from readthedocs.builds.models import Build | ||
from readthedocs.projects.constants import PUBLIC | ||
from readthedocs.projects.models import Project | ||
|
||
|
||
@override_settings( | ||
PUBLIC_DOMAIN="dev.readthedocs.io", | ||
PUBLIC_DOMAIN_USES_HTTPS=True, | ||
) | ||
@pytest.mark.proxito | ||
class TestReadTheDocsConfigJson(TestCase): | ||
def setUp(self): | ||
self.user = fixture.get(User, username="user") | ||
self.user.set_password("user") | ||
self.user.save() | ||
|
||
self.project = fixture.get( | ||
Project, | ||
slug="project", | ||
language="en", | ||
privacy_level=PUBLIC, | ||
external_builds_privacy_level=PUBLIC, | ||
repo="git://10.10.0.1/project", | ||
programming_language="words", | ||
single_version=False, | ||
users=[self.user], | ||
main_language_project=None, | ||
) | ||
self.project.versions.update( | ||
privacy_level=PUBLIC, | ||
built=True, | ||
active=True, | ||
type=INTERNAL, | ||
identifier="1a2b3c", | ||
) | ||
self.version = self.project.versions.get(slug=LATEST) | ||
self.build = fixture.get( | ||
Build, | ||
version=self.version, | ||
) | ||
|
||
def test_get_config(self): | ||
r = self.client.get( | ||
reverse("proxito_readthedocs_config_json"), | ||
{"url": "https://project.dev.readthedocs.io/en/latest/"}, | ||
secure=True, | ||
HTTP_HOST="project.dev.readthedocs.io", | ||
) | ||
assert r.status_code == 200 | ||
|
||
expected = { | ||
"comment": "THIS RESPONSE IS IN ALPHA FOR TEST PURPOSES ONLY AND IT'S GOING TO CHANGE COMPLETELY -- DO NOT USE IT!", | ||
"project": { | ||
"slug": self.project.slug, | ||
"language": self.project.language, | ||
"repository_url": self.project.repo, | ||
"programming_language": self.project.programming_language, | ||
}, | ||
"version": { | ||
"slug": self.version.slug, | ||
"external": self.version.type == EXTERNAL, | ||
}, | ||
"build": { | ||
"id": self.build.pk, | ||
}, | ||
"domains": { | ||
"dashboard": settings.PRODUCTION_DOMAIN, | ||
}, | ||
"readthedocs": { | ||
"analytics": { | ||
"code": None, | ||
} | ||
}, | ||
"features": { | ||
"analytics": { | ||
"code": None, | ||
}, | ||
"external_version_warning": { | ||
"enabled": True, | ||
"query_selector": "[role=main]", | ||
}, | ||
"non_latest_version_warning": { | ||
"enabled": True, | ||
"query_selector": "[role=main]", | ||
"versions": [ | ||
"latest", | ||
], | ||
}, | ||
"doc_diff": { | ||
"enabled": True, | ||
"base_url": "https://project.dev.readthedocs.io/en/latest/index.html", | ||
"root_selector": "[role=main]", | ||
"inject_styles": True, | ||
"base_host": "", | ||
"base_page": "", | ||
}, | ||
"flyout": { | ||
"translations": [], | ||
"versions": [ | ||
{"slug": "latest", "url": "/en/latest/"}, | ||
], | ||
"downloads": [], | ||
"vcs": { | ||
"url": "https://github.com", | ||
"username": "readthedocs", | ||
"repository": "test-builds", | ||
"branch": self.version.identifier, | ||
"filepath": "/docs/index.rst", | ||
}, | ||
}, | ||
}, | ||
} | ||
assert r.json() == expected |
This file contains 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.