]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
👷 Build and deploy docs only on docs changes (#9728)
authorSebastián Ramírez <tiangolo@gmail.com>
Fri, 23 Jun 2023 17:55:09 +0000 (19:55 +0200)
committerGitHub <noreply@github.com>
Fri, 23 Jun 2023 17:55:09 +0000 (19:55 +0200)
.github/workflows/build-docs.yml
.github/workflows/preview-docs.yml

index a0e83e5c864034f6c478c7f94f67767cac924919..fb1fa6f098a0e94506a02046b8caf1cc88400422 100644 (file)
@@ -4,9 +4,33 @@ on:
     branches:
       - master
   pull_request:
-    types: [opened, synchronize]
+    types:
+      - opened
+      - synchronize
 jobs:
+  changes:
+    runs-on: ubuntu-latest
+    # Required permissions
+    permissions:
+      pull-requests: read
+    # Set job outputs to values from filter step
+    outputs:
+      docs: ${{ steps.filter.outputs.docs }}
+    steps:
+    - uses: actions/checkout@v3
+    # For pull requests it's not necessary to checkout the code but for master it is
+    - uses: dorny/paths-filter@v2
+      id: filter
+      with:
+        filters: |
+            docs:
+              - README.md
+              - docs/**
+              - docs_src/**
+              - requirements-docs.txt
   build-docs:
+    needs: changes
+    if: ${{ needs.changes.outputs.docs == 'true' }}
     runs-on: ubuntu-latest
     steps:
       - name: Dump GitHub context
index 298f75b026180a0fdb5ec3a2275c6abd2e807c44..da98f5d2bdd4ddbb92d49e5d0b37feb2017ca2f1 100644 (file)
@@ -16,19 +16,23 @@ jobs:
           rm -rf ./site
           mkdir ./site
       - name: Download Artifact Docs
+        id: download
         uses: dawidd6/action-download-artifact@v2.27.0
         with:
+          if_no_artifact_found: ignore
           github_token: ${{ secrets.FASTAPI_PREVIEW_DOCS_DOWNLOAD_ARTIFACTS }}
           workflow: build-docs.yml
           run_id: ${{ github.event.workflow_run.id }}
           name: docs-zip
           path: ./site/
       - name: Unzip docs
+        if: steps.download.outputs.found_artifact == 'true'
         run: |
           cd ./site
           unzip docs.zip
           rm -f docs.zip
       - name: Deploy to Netlify
+        if: steps.download.outputs.found_artifact == 'true'
         id: netlify
         uses: nwtgck/actions-netlify@v2.0.0
         with:
@@ -40,6 +44,7 @@ jobs:
           NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
           NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
       - name: Comment Deploy
+        if: steps.netlify.outputs.deploy-url != ''
         uses: ./.github/actions/comment-docs-preview-in-pr
         with:
           token: ${{ secrets.FASTAPI_PREVIEW_DOCS_COMMENT_DEPLOY }}