Skip to content

Commit 777f6bd

Browse files
committed
chore(swagger): preview openapi doc at gh-pages
1 parent ed5f869 commit 777f6bd

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: OpenAPI generation
2+
3+
on:
4+
push:
5+
pull_request:
6+
jobs:
7+
openapi-generate:
8+
runs-on: ubuntu-latest
9+
env:
10+
APP_ENV: testing
11+
APP_DEBUG: true
12+
APP_KEY: base64:4vh0op/S1dAsXKQ2bbdCfWRyCI9r8NNIdPXyZWt9PX4=
13+
DEV_EMAIL_TO: smarcet@gmail.com
14+
APP_URL: http://localhost
15+
DB_CONNECTION: mysql
16+
DB_HOST: 127.0.0.1
17+
DB_PORT: 3306
18+
DB_DATABASE: idp_test
19+
DB_USERNAME: root
20+
DB_PASSWORD: 1qaz2wsx
21+
REDIS_HOST: 127.0.0.1
22+
REDIS_PORT: 6379
23+
REDIS_DB: 0
24+
REDIS_PASSWORD: 1qaz2wsx
25+
REDIS_DATABASES: 16
26+
SSL_ENABLED: false
27+
SESSION_DRIVER: redis
28+
PHP_VERSION: 8.3
29+
OTEL_SDK_DISABLED: true
30+
OTEL_SERVICE_ENABLED: false
31+
32+
services:
33+
mysql:
34+
image: mysql:8.0
35+
env:
36+
MYSQL_ROOT_PASSWORD: ${{env.DB_PASSWORD}}
37+
MYSQL_DATABASE: ${{env.DB_DATABASE}}
38+
ports:
39+
- 3306:3306
40+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
41+
steps:
42+
- name: Create Redis
43+
uses: supercharge/redis-github-action@1.8.1
44+
with:
45+
redis-port: ${{env.REDIS_PORT}}
46+
redis-password: ${{env.REDIS_PASSWORD}}
47+
48+
- name: Check out repository code
49+
uses: actions/checkout@v4
50+
51+
- name: Install PHP
52+
uses: shivammathur/setup-php@v2
53+
with:
54+
php-version: ${{ env.PHP_VERSION }}
55+
extensions: pdo_mysql, mbstring, exif, pcntl, bcmath, sockets, gettext, apcu, redis, igbinary, memcached
56+
57+
- name: Install dependencies
58+
uses: "ramsey/composer-install@v3"
59+
env:
60+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }'
61+
62+
- name: Generate OpenAPI docs
63+
run: php artisan l5-swagger:generate
64+
65+
- name: Build Swagger UI preview
66+
run: |
67+
mkdir -p swagger-ui
68+
cp storage/api-docs/api-docs.json swagger-ui/api-docs.json
69+
cat > swagger-ui/index.html << 'HTMLEOF'
70+
<!doctype html>
71+
<html lang="en">
72+
<head>
73+
<meta charset="utf-8" />
74+
<title>OpenStackID API - Swagger UI</title>
75+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css" />
76+
</head>
77+
<body>
78+
<div id="swagger-ui"></div>
79+
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
80+
<script>
81+
window.onload = () => {
82+
window.ui = SwaggerUIBundle({
83+
url: 'api-docs.json',
84+
dom_id: '#swagger-ui'
85+
});
86+
};
87+
</script>
88+
</body>
89+
</html>
90+
HTMLEOF
91+
92+
- name: Upload Swagger UI artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: swagger-ui
96+
path: swagger-ui/
97+
if-no-files-found: error
98+
99+
pages-preview:
100+
name: Publish Swagger UI to GitHub Pages
101+
needs: openapi-generate
102+
if: github.event_name == 'pull_request'
103+
runs-on: ubuntu-latest
104+
105+
permissions:
106+
contents: write
107+
issues: write
108+
pull-requests: write
109+
110+
steps:
111+
- name: Checkout repository
112+
uses: actions/checkout@v4
113+
114+
- name: Download Swagger UI artifact
115+
uses: actions/download-artifact@v4
116+
with:
117+
name: swagger-ui
118+
path: swagger-ui
119+
120+
- name: Build public directory for GitHub Pages
121+
run: |
122+
PR_PATH="openapi/pr-${{ github.event.number }}"
123+
mkdir -p "public/${PR_PATH}"
124+
cp -R swagger-ui/* "public/${PR_PATH}/"
125+
echo "Built GitHub Pages content at public/${PR_PATH}"
126+
127+
- name: Publish to GitHub Pages
128+
uses: peaceiris/actions-gh-pages@v4
129+
with:
130+
github_token: ${{ secrets.GITHUB_TOKEN }}
131+
publish_dir: ./public
132+
keep_files: true
133+
134+
- name: Comment preview URL on PR
135+
uses: actions/github-script@v7
136+
with:
137+
github-token: ${{ secrets.GITHUB_TOKEN }}
138+
script: |
139+
const prNumber = context.payload.pull_request.number;
140+
const owner = context.repo.owner;
141+
const repo = context.repo.repo;
142+
const baseUrl = `https://${owner}.github.io/${repo}`;
143+
const previewPath = `/openapi/pr-${prNumber}/`;
144+
const url = `${baseUrl}${previewPath}`;
145+
146+
const body = [
147+
'📘 **OpenAPI / Swagger preview**',
148+
'',
149+
`➡️ ${url}`,
150+
'',
151+
'This page is automatically updated on each push to this PR.'
152+
].join('\n');
153+
154+
await github.rest.issues.createComment({
155+
owner,
156+
repo,
157+
issue_number: prNumber,
158+
body,
159+
});
160+

0 commit comments

Comments
 (0)