-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (73 loc) · 2.98 KB
/
deploy-api-docs.yml
File metadata and controls
86 lines (73 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# .github/workflows/deploy-api-docs.yml
# Generates ReDoc HTML from your OpenAPI spec and deploys it with GitHub Pages
name: Generate & Deploy API Docs
on:
# Build on pushes to the default branch
push:
branches: ["main"]
# Re-run automatically after the “Validate OpenAPI spec” workflow succeeds
workflow_run:
workflows: ["Validate OpenAPI spec"]
types: [completed]
# Allow manual runs from the Actions tab
workflow_dispatch:
# Required for committing to the generated-docs branch and for the Pages deploy
permissions:
contents: write # commit generated files
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false # let any in-progress production deploy finish
jobs:
build-docs:
# Only run when manually triggered, on push, or after a successful spec-validation run
if: ${{ github.event_name == 'workflow_dispatch'
|| github.event_name == 'push'
|| github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
with:
fetch-depth: 0
# For workflow_run events, build the exact commit that was validated
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Setup Pages (env vars, paths)
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Generate HTML with ReDoc
run: |
mkdir -p _site
npx --yes redoc-cli@0.13.21 \
bundle spec/openapi.yaml \
-o _site/index.html
# ── (Optional) keep a copy on the generated-docs branch ────────────
- name: Commit docs to generated-docs
run: |
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git fetch origin
git checkout -B generated-docs
git rm -rf . >/dev/null 2>&1 || true
cp -r _site/* .
git add .
git commit -m "docs: regenerate from ${GITHUB_SHA}" || echo "No changes"
git push --force origin generated-docs
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
# ─────────────────── Deploy exactly like the original Jekyll workflow ───────────────────
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build-docs
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4