Skip to content

Commit 4dd386b

Browse files
authored
🚀 Preview docs for external PRs (fastapi#1738)
* 🍱 Save docs zip when building docs * 🙈 Add docs.zip artifact to .gitignore * 🚀 Update deploy artifact name * ♻️ Upload artifact directory * ✨ Add WIP trigger docs preview * ♻️ Update trigger docs preview * 👷 Update env vars for docs preview * 👷 Update PR extraction * 👷 Try to show GitHub event * 💚 Try to see if GitHub context templates is causing the problem * 💚 Try to debug context GitHub event * 🔊 Debug GitHub event context * 👷 Update debugging action * 👷 Update debug * 👷 Update Action * ♻️ Update script to trigger docs preview * ⚡️ Try to use Zip again to improve speed * 🔧 Update zip scripts * ✨ Add preview docs on event * 🚀 Trigger deploy preview on PRs * 🐛 Fix trigger script env vars
1 parent b7251f1 commit 4dd386b

File tree

7 files changed

+103
-1
lines changed

7 files changed

+103
-1
lines changed

.github/workflows/deploy-docs.yml renamed to .github/workflows/build-docs.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Deploy to Netlify
1+
name: Build Docs
22
on:
33
push:
44
pull_request:
@@ -18,6 +18,18 @@ jobs:
1818
run: python3.7 -m flit install --extras doc
1919
- name: Build Docs
2020
run: python3.7 ./scripts/docs.py build-all
21+
- name: Zip docs
22+
run: bash ./scripts/zip-docs.sh
23+
- uses: actions/upload-artifact@v2
24+
with:
25+
name: docs-zip-${{ github.sha }}
26+
path: ./docs.zip
27+
- name: Trigger Docs Preview
28+
env:
29+
PR: "${{ github.event.number }}"
30+
NAME: "docs-zip-${{ github.sha }}"
31+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
32+
run: bash ./scripts/trigger-docs-preview.sh
2133
- name: Deploy to Netlify
2234
uses: nwtgck/actions-netlify@v1.0.3
2335
with:

.github/workflows/preview-docs.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy Docs
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
pr:
6+
description: Pull Request number
7+
required: true
8+
name:
9+
description: Artifact name for zip file with docs
10+
required: true
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-18.04
15+
steps:
16+
- uses: actions/download-artifact@v2
17+
with:
18+
name: ${{ github.event.inputs.name }}
19+
path: ./docs.zip
20+
- name: Unzip docs
21+
run: bash ./scripts/unzip-docs.sh
22+
- name: Deploy to Netlify
23+
id: netlify
24+
uses: nwtgck/actions-netlify@v1.0.3
25+
with:
26+
publish-dir: './site'
27+
production-deploy: false
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
env:
30+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
31+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
32+
- name: Comment Deploy
33+
run: bash ./scripts/docs-comment-deploy.sh
34+
env:
35+
PR: "${{ github.event.inputs.pr }}"
36+
DEPLOY_URL: "${{ steps.netlify.outputs.deploy-url }}"
37+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ env3.*
1717
env
1818
docs_build
1919
venv
20+
docs.zip
2021

2122
# vim temporary files
2223
*~

scripts/docs-comment-deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env bash
2+
3+
set -x
4+
set -e
5+
6+
PR=${PR:?Variable not set}
7+
DEPLOY_URL=${DEPLOY_URL:?Variable not set}
8+
GITHUB_TOKEN=${GITHUB_TOKEN:?Variable not set}
9+
10+
curl \
11+
-H "Authorization: token ${GITHUB_TOKEN}" \
12+
https://api.github.com/repos/tiangolo/fastapi/issues/${PR}/comments \
13+
-d '{"body": "📝 Docs preview: '"${DEPLOY_URL}"'"}'

scripts/trigger-docs-preview.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env bash
2+
3+
set -x
4+
set -e
5+
6+
PR=${PR}
7+
8+
if [ -z "$PR" ]; then
9+
echo "Not a PR build, skip trigger docs preview"
10+
exit 0
11+
fi
12+
13+
NAME=${NAME:?Variable not set}
14+
GITHUB_TOKEN=${GITHUB_TOKEN:?Variable not set}
15+
16+
curl \
17+
-X POST \
18+
-H "Authorization: token ${GITHUB_TOKEN}" \
19+
-H "Accept: application/vnd.github.v3+json" \
20+
https://api.github.com/repos/tiangolo/fastapi/actions/workflows/preview-docs.yml/dispatches \
21+
-d '{"ref":"master", "inputs": {"pr": "'"${PR}"'", "name": "'"${NAME}"'"}}'

scripts/unzip-docs.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /usr/bin/env bash
2+
3+
set -x
4+
set -e
5+
6+
if [ -d ./site/ ]; then
7+
rm -rf ./site/
8+
fi
9+
unzip docs.zip

scripts/zip-docs.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /usr/bin/env bash
2+
3+
set -x
4+
set -e
5+
6+
if [ -f docs.zip ]; then
7+
rm -rf docs.zip
8+
fi
9+
zip -r docs.zip ./site

0 commit comments

Comments
 (0)