]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🚀 Preview docs for external PRs (#1738)
authorSebastián Ramírez <tiangolo@gmail.com>
Sun, 19 Jul 2020 18:49:52 +0000 (20:49 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2020 18:49:52 +0000 (20:49 +0200)
* 🍱 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

.github/workflows/build-docs.yml [moved from .github/workflows/deploy-docs.yml with 65% similarity]
.github/workflows/preview-docs.yml [new file with mode: 0644]
.gitignore
scripts/docs-comment-deploy.sh [new file with mode: 0644]
scripts/trigger-docs-preview.sh [new file with mode: 0644]
scripts/unzip-docs.sh [new file with mode: 0644]
scripts/zip-docs.sh [new file with mode: 0644]

similarity index 65%
rename from .github/workflows/deploy-docs.yml
rename to .github/workflows/build-docs.yml
index 60f8e4b4ae4ef8fa351cdb4685146d0fb060df16..2b90c54b4c4b4bc78183b7ae8c4b5a5285cd6fa9 100644 (file)
@@ -1,4 +1,4 @@
-name: Build and Deploy to Netlify
+name: Build Docs
 on:
   push:
   pull_request:
@@ -18,6 +18,18 @@ jobs:
         run: python3.7 -m flit install --extras doc
       - name: Build Docs
         run: python3.7 ./scripts/docs.py build-all
+      - name: Zip docs
+        run: bash ./scripts/zip-docs.sh
+      - uses: actions/upload-artifact@v2
+        with:
+          name: docs-zip-${{ github.sha }}
+          path: ./docs.zip
+      - name: Trigger Docs Preview
+        env:
+          PR: "${{ github.event.number }}"
+          NAME: "docs-zip-${{ github.sha }}"
+          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
+        run: bash ./scripts/trigger-docs-preview.sh
       - name: Deploy to Netlify
         uses: nwtgck/actions-netlify@v1.0.3
         with:
diff --git a/.github/workflows/preview-docs.yml b/.github/workflows/preview-docs.yml
new file mode 100644 (file)
index 0000000..17a03b4
--- /dev/null
@@ -0,0 +1,37 @@
+name: Deploy Docs
+on:
+  workflow_dispatch:
+    inputs:
+      pr:
+        description: Pull Request number
+        required: true
+      name:
+        description: Artifact name for zip file with docs
+        required: true
+
+jobs:
+  deploy:
+    runs-on: ubuntu-18.04
+    steps:
+      - uses: actions/download-artifact@v2
+        with:
+          name: ${{ github.event.inputs.name }}
+          path: ./docs.zip
+      - name: Unzip docs
+        run: bash ./scripts/unzip-docs.sh
+      - name: Deploy to Netlify
+        id: netlify
+        uses: nwtgck/actions-netlify@v1.0.3
+        with:
+          publish-dir: './site'
+          production-deploy: false
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+        env:
+          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
+      - name: Comment Deploy
+        run: bash ./scripts/docs-comment-deploy.sh
+        env:
+          PR: "${{ github.event.inputs.pr }}"
+          DEPLOY_URL: "${{ steps.netlify.outputs.deploy-url }}"
+          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
index 93041658652dc69c050bc4390efbf29a0aaf1ab3..186c432f3cdbe47aaae023f96edab3291632f974 100644 (file)
@@ -17,6 +17,7 @@ env3.*
 env
 docs_build
 venv
+docs.zip
 
 # vim temporary files
 *~
diff --git a/scripts/docs-comment-deploy.sh b/scripts/docs-comment-deploy.sh
new file mode 100644 (file)
index 0000000..fa4214b
--- /dev/null
@@ -0,0 +1,13 @@
+#! /usr/bin/env bash
+
+set -x
+set -e
+
+PR=${PR:?Variable not set}
+DEPLOY_URL=${DEPLOY_URL:?Variable not set}
+GITHUB_TOKEN=${GITHUB_TOKEN:?Variable not set}
+
+curl \
+    -H "Authorization: token ${GITHUB_TOKEN}" \
+    https://api.github.com/repos/tiangolo/fastapi/issues/${PR}/comments \
+    -d '{"body": "📝 Docs preview: '"${DEPLOY_URL}"'"}'
diff --git a/scripts/trigger-docs-preview.sh b/scripts/trigger-docs-preview.sh
new file mode 100644 (file)
index 0000000..7dbb806
--- /dev/null
@@ -0,0 +1,21 @@
+#! /usr/bin/env bash
+
+set -x
+set -e
+
+PR=${PR}
+
+if [ -z "$PR" ]; then
+    echo "Not a PR build, skip trigger docs preview"
+    exit 0
+fi
+
+NAME=${NAME:?Variable not set}
+GITHUB_TOKEN=${GITHUB_TOKEN:?Variable not set}
+
+curl \
+  -X POST \
+  -H "Authorization: token ${GITHUB_TOKEN}" \
+  -H "Accept: application/vnd.github.v3+json" \
+  https://api.github.com/repos/tiangolo/fastapi/actions/workflows/preview-docs.yml/dispatches \
+  -d '{"ref":"master", "inputs": {"pr": "'"${PR}"'", "name": "'"${NAME}"'"}}'
diff --git a/scripts/unzip-docs.sh b/scripts/unzip-docs.sh
new file mode 100644 (file)
index 0000000..f022b7d
--- /dev/null
@@ -0,0 +1,9 @@
+#! /usr/bin/env bash
+
+set -x
+set -e
+
+if [ -d ./site/ ]; then
+    rm -rf ./site/
+fi
+unzip docs.zip
diff --git a/scripts/zip-docs.sh b/scripts/zip-docs.sh
new file mode 100644 (file)
index 0000000..f2b7ba3
--- /dev/null
@@ -0,0 +1,9 @@
+#! /usr/bin/env bash
+
+set -x
+set -e
+
+if [ -f docs.zip ]; then
+    rm -rf docs.zip
+fi
+zip -r docs.zip ./site