Skip to content

Commit 5549b5b

Browse files
committed
rtd build fix
1 parent 2fc1e4b commit 5549b5b

2 files changed

Lines changed: 158 additions & 164 deletions

File tree

.github/workflows/docs.yml

Lines changed: 0 additions & 164 deletions
This file was deleted.

.github/workflows/tests.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
branches:
55
- master
66
- '*'
7+
tags:
8+
- '**'
79
pull_request:
810
branches:
911
- master
@@ -61,6 +63,24 @@ jobs:
6163
- name: run django tests
6264
run: tox -e ${{ matrix.tox }}
6365

66+
docs:
67+
name: "docs"
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
- uses: actions/setup-python@v5
72+
with:
73+
python-version: '3.12'
74+
cache: pip
75+
- name: install dependencies
76+
run: |
77+
pip install -e ".[html]"
78+
pip install sphinx -r docs/requirements.txt
79+
- name: build docs
80+
run: sphinx-build -W -b html docs docs/_build/html
81+
- name: run doctests
82+
run: sphinx-build -b doctest docs docs/_build/doctest
83+
6484
typecheck:
6585
name: "typecheck"
6686
runs-on: ubuntu-latest
@@ -115,3 +135,141 @@ jobs:
115135
SMTP_TEST_LOCAL_PORT: 1025
116136
SMTP_TEST_LOCAL_WITHOUT_TLS: true
117137
run: tox -e ${{ matrix.tox }} -- -m e2e
138+
139+
publish_rtd:
140+
name: "publish read the docs"
141+
needs:
142+
- tests
143+
- django
144+
- docs
145+
- typecheck
146+
- e2e
147+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
148+
runs-on: ubuntu-latest
149+
env:
150+
RTD_API_TOKEN: ${{ secrets.RTD_API_TOKEN }}
151+
RTD_PROJECT_SLUG: python-emails
152+
steps:
153+
- name: Trigger Read the Docs build
154+
run: |
155+
set -euo pipefail
156+
157+
: "${RTD_API_TOKEN:?RTD_API_TOKEN secret is required}"
158+
159+
api_base="https://app.readthedocs.org/api/v3/projects/${RTD_PROJECT_SLUG}"
160+
auth_header="Authorization: Token ${RTD_API_TOKEN}"
161+
162+
get_version_details() {
163+
local version_slug="$1"
164+
local response_file="${2:-version.json}"
165+
166+
curl \
167+
--silent \
168+
--show-error \
169+
--output "${response_file}" \
170+
--write-out '%{http_code}' \
171+
--header "${auth_header}" \
172+
"${api_base}/versions/${version_slug}/"
173+
}
174+
175+
wait_for_version_slug() {
176+
local version_name="$1"
177+
178+
for attempt in {1..12}; do
179+
local status_code
180+
local version_slug
181+
status_code="$(
182+
curl \
183+
--silent \
184+
--show-error \
185+
--output versions.json \
186+
--write-out '%{http_code}' \
187+
--get \
188+
--header "${auth_header}" \
189+
--data-urlencode "type=tag" \
190+
--data-urlencode "verbose_name=${version_name}" \
191+
"${api_base}/versions/"
192+
)"
193+
194+
if [[ "${status_code}" == "200" ]]; then
195+
version_slug="$(
196+
jq \
197+
--raw-output \
198+
--arg version_name "${version_name}" \
199+
'.results[] | select(.verbose_name == $version_name) | .slug' \
200+
versions.json | head -n 1
201+
)"
202+
203+
if [[ -n "${version_slug}" && "${version_slug}" != "null" ]]; then
204+
printf '%s\n' "${version_slug}"
205+
return 0
206+
fi
207+
fi
208+
209+
sleep 5
210+
done
211+
212+
echo "Read the Docs version '${version_name}' was not found after sync."
213+
if [[ -f versions.json ]]; then
214+
cat versions.json
215+
fi
216+
return 1
217+
}
218+
219+
trigger_build() {
220+
local version_slug="$1"
221+
222+
curl \
223+
--fail-with-body \
224+
--silent \
225+
--show-error \
226+
--request POST \
227+
--header "${auth_header}" \
228+
"${api_base}/versions/${version_slug}/builds/"
229+
}
230+
231+
if [[ "${GITHUB_REF_TYPE}" == "branch" ]]; then
232+
trigger_build latest
233+
exit 0
234+
fi
235+
236+
version_name="${GITHUB_REF_NAME}"
237+
238+
curl \
239+
--fail-with-body \
240+
--silent \
241+
--show-error \
242+
--request POST \
243+
--header "${auth_header}" \
244+
"${api_base}/sync-versions/"
245+
246+
version_slug="$(wait_for_version_slug "${version_name}")"
247+
status_code="$(get_version_details "${version_slug}")"
248+
249+
if [[ "${status_code}" != "200" ]]; then
250+
echo "Failed to fetch Read the Docs version details for '${version_slug}'."
251+
cat version.json
252+
exit 1
253+
fi
254+
255+
active="$(jq -r '.active' version.json)"
256+
hidden="$(jq -r '.hidden' version.json)"
257+
258+
if [[ "${active}" == "true" && "${hidden}" == "false" ]]; then
259+
trigger_build "${version_slug}"
260+
exit 0
261+
fi
262+
263+
curl \
264+
--fail-with-body \
265+
--silent \
266+
--show-error \
267+
--request PATCH \
268+
--header "${auth_header}" \
269+
--header "Content-Type: application/json" \
270+
--data '{"active": true, "hidden": false}' \
271+
"${api_base}/versions/${version_slug}/"
272+
273+
if [[ "${active}" == "true" ]]; then
274+
trigger_build "${version_slug}"
275+
fi

0 commit comments

Comments
 (0)