-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (105 loc) · 3.81 KB
/
api-docs-pages.yml
File metadata and controls
123 lines (105 loc) · 3.81 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: API Docs Pages
on:
push:
branches: [main]
paths:
- "docs/api/**"
- "frontend/**"
- ".github/workflows/api-docs-pages.yml"
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
env:
NODE_VERSION: '22'
NPM_VERSION: '10.9.2'
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check Pages availability
id: pages_check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
http_code=$(curl -s -o /tmp/pages.json -w "%{http_code}" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pages")
if [ "${http_code}" = "200" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
echo "GitHub Pages API is available."
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
echo "GitHub Pages is not enabled for this repository; skipping deploy steps."
fi
- name: Configure Pages
if: steps.pages_check.outputs.enabled == 'true'
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
with:
enablement: true
- name: Setup Node
if: steps.pages_check.outputs.enabled == 'true'
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "22"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Pin npm version
if: steps.pages_check.outputs.enabled == 'true'
run: |
npm install -g npm@${NPM_VERSION}
echo "Node: $(node -v)"
echo "npm: $(npm -v)"
- name: Build frontend site
if: steps.pages_check.outputs.enabled == 'true'
working-directory: frontend
run: |
bash ../scripts/npm-ci-safe.sh
npm run build
- name: Prepare Pages artifact
if: steps.pages_check.outputs.enabled == 'true'
run: |
rm -rf .pages-site
mkdir -p .pages-site
# Publish the existing website at the Pages root.
cp -R frontend/dist/. .pages-site/
# Publish API docs under /api without replacing the site root.
mkdir -p .pages-site/api
cp -R docs/api/. .pages-site/api/
# Keep backward compatibility for existing /swagger-ui.html links.
cat > .pages-site/swagger-ui.html <<'EOF'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=./api/swagger-ui.html" />
<title>Sovereign Map API Docs</title>
</head>
<body>
<p>Redirecting to API docs...</p>
<p><a href="./api/swagger-ui.html">Open Swagger UI</a></p>
</body>
</html>
EOF
- name: Upload Pages artifact
if: steps.pages_check.outputs.enabled == 'true'
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: .pages-site
- name: Deploy to GitHub Pages
if: steps.pages_check.outputs.enabled == 'true'
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0
- name: Skip deploy when Pages is disabled
if: steps.pages_check.outputs.enabled != 'true'
run: echo "API docs deploy skipped because GitHub Pages is not enabled for this repository."