| 1 |
name: Deploy Docs |
| 2 |
on: |
| 3 |
workflow_run: # zizmor: ignore[dangerous-triggers] |
| 4 |
workflows: |
| 5 |
- Build Docs |
| 6 |
types: |
| 7 |
- completed |
| 8 |
|
| 9 |
permissions: {} |
| 10 |
|
| 11 |
jobs: |
| 12 |
deploy-docs: |
| 13 |
runs-on: ubuntu-latest |
| 14 |
permissions: |
| 15 |
deployments: write |
| 16 |
issues: write |
| 17 |
pull-requests: write |
| 18 |
statuses: write |
| 19 |
timeout-minutes: 5 |
| 20 |
steps: |
| 21 |
- name: Dump GitHub context |
| 22 |
env: |
| 23 |
GITHUB_CONTEXT: ${{ toJson(github) }} |
| 24 |
run: echo "$GITHUB_CONTEXT" |
| 25 |
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 26 |
with: |
| 27 |
persist-credentials: false |
| 28 |
- name: Set up Python |
| 29 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 |
| 30 |
with: |
| 31 |
python-version-file: ".python-version" |
| 32 |
- name: Setup uv |
| 33 |
uses: astral-sh/setup-uv@d31148d669074a8d0a63714ba94f3201e7020bc3 # v8.3.0 |
| 34 |
with: |
| 35 |
# Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum. |
| 36 |
# See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837 |
| 37 |
version: "0.11.18" |
| 38 |
enable-cache: false |
| 39 |
- name: Install GitHub Actions dependencies |
| 40 |
run: uv sync --locked --no-dev --group github-actions |
| 41 |
- name: Deploy Docs Status Pending |
| 42 |
run: uv run ./scripts/deploy_docs_status.py |
| 43 |
env: |
| 44 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 |
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 46 |
RUN_ID: ${{ github.run_id }} |
| 47 |
STATE: "pending" |
| 48 |
- name: Clean site |
| 49 |
run: | |
| 50 |
rm -rf ./site |
| 51 |
mkdir ./site |
| 52 |
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 53 |
with: |
| 54 |
path: ./site/ |
| 55 |
pattern: docs-site-* |
| 56 |
merge-multiple: true |
| 57 |
github-token: ${{ secrets.GITHUB_TOKEN }} |
| 58 |
run-id: ${{ github.event.workflow_run.id }} |
| 59 |
- name: Deploy to Cloudflare Pages |
| 60 |
# hashFiles returns an empty string if there are no files |
| 61 |
if: hashFiles('./site/*') |
| 62 |
id: deploy |
| 63 |
env: |
| 64 |
PROJECT_NAME: fastapitiangolo |
| 65 |
BRANCH: ${{ ( github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch == 'master' && 'main' ) || ( github.event.workflow_run.head_sha ) }} |
| 66 |
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 |
| 67 |
with: |
| 68 |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} # zizmor: ignore[secrets-outside-env] |
| 69 |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} # zizmor: ignore[secrets-outside-env] |
| 70 |
command: pages deploy ./site --project-name=${{ env.PROJECT_NAME }} --branch=${{ env.BRANCH }} |
| 71 |
- name: Deploy Docs Status Error |
| 72 |
if: failure() |
| 73 |
run: uv run ./scripts/deploy_docs_status.py |
| 74 |
env: |
| 75 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 |
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 77 |
RUN_ID: ${{ github.run_id }} |
| 78 |
STATE: "error" |
| 79 |
- name: Comment Deploy |
| 80 |
run: uv run ./scripts/deploy_docs_status.py |
| 81 |
env: |
| 82 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 |
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }} |
| 84 |
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 85 |
RUN_ID: ${{ github.run_id }} |
| 86 |
STATE: "success" |