Skip to content

Commit e673c6d

Browse files
committed
Add CI
1 parent 1444e4c commit e673c6d

5 files changed

Lines changed: 3209 additions & 0 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
jobs:
19+
deploy:
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '20'
32+
cache: 'npm'
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Build Swagger UI
38+
run: npm run build:swagger
39+
40+
- name: Setup Pages
41+
uses: actions/configure-pages@v4
42+
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
45+
with:
46+
path: './dist'
47+
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v4
51+

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
dist/
3+
.DS_Store
4+
*.log
5+
.env
6+
.idea/
7+
.vscode/
8+

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "ddi-api",
3+
"version": "1.0.0",
4+
"description": "DDI RESTful API specification",
5+
"scripts": {
6+
"build:swagger": "node scripts/build-swagger.js",
7+
"preview:swagger": "npx serve dist -p 8080",
8+
"deploy": "npm run build:swagger && gh-pages -d dist"
9+
},
10+
"devDependencies": {
11+
"gh-pages": "^6.0.0",
12+
"swagger-ui": "^5.9.0"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/NicoLaval/DDI-API.git"
17+
},
18+
"keywords": [
19+
"ddi",
20+
"rest",
21+
"api",
22+
"openapi",
23+
"swagger"
24+
],
25+
"author":"NicoLaval",
26+
"license": "MIT",
27+
"scarfSettings": {
28+
"enabled": false
29+
}
30+
}
31+

scripts/build-swagger.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Build Swagger UI HTML file
5+
*
6+
* Copies Swagger UI files and creates an HTML file that loads the OpenAPI specification.
7+
*/
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
12+
const specPath = path.join(__dirname, '..', 'ddi-rest.yaml');
13+
const outputPath = path.join(__dirname, '..', 'dist', 'index.html');
14+
const distDir = path.dirname(outputPath);
15+
const swaggerUiPath = path.join(__dirname, '..', 'node_modules', 'swagger-ui', 'dist');
16+
17+
// Ensure dist directory exists
18+
if (!fs.existsSync(distDir)) {
19+
fs.mkdirSync(distDir, { recursive: true });
20+
}
21+
22+
// Check if swagger-ui is installed
23+
if (!fs.existsSync(swaggerUiPath)) {
24+
console.error('❌ Error: swagger-ui not found. Please run: npm install');
25+
process.exit(1);
26+
}
27+
28+
// Copy YAML file to dist
29+
const distSpecPath = path.join(distDir, 'ddi-rest.yaml');
30+
fs.copyFileSync(specPath, distSpecPath);
31+
console.log('📄 Copied ddi-rest.yaml');
32+
33+
// Copy Swagger UI files to dist
34+
const swaggerUiFiles = [
35+
'swagger-ui-bundle.js',
36+
'swagger-ui-standalone-preset.js',
37+
'swagger-ui.css'
38+
];
39+
40+
swaggerUiFiles.forEach(file => {
41+
const src = path.join(swaggerUiPath, file);
42+
const dest = path.join(distDir, file);
43+
if (fs.existsSync(src)) {
44+
fs.copyFileSync(src, dest);
45+
console.log(`📄 Copied ${file}`);
46+
} else {
47+
console.warn(`⚠️ Warning: ${file} not found at ${src}`);
48+
}
49+
});
50+
51+
// Create HTML file
52+
const html = `<!DOCTYPE html>
53+
<html lang="en">
54+
<head>
55+
<meta charset="UTF-8">
56+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
57+
<title>DDI RESTful API Documentation</title>
58+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
59+
<style>
60+
html {
61+
box-sizing: border-box;
62+
overflow: -moz-scrollbars-vertical;
63+
overflow-y: scroll;
64+
}
65+
*, *:before, *:after {
66+
box-sizing: inherit;
67+
}
68+
body {
69+
margin: 0;
70+
background: #fafafa;
71+
}
72+
</style>
73+
</head>
74+
<body>
75+
<div id="swagger-ui"></div>
76+
<script src="./swagger-ui-bundle.js"></script>
77+
<script src="./swagger-ui-standalone-preset.js"></script>
78+
<script>
79+
window.onload = function() {
80+
SwaggerUIBundle({
81+
url: "./ddi-rest.yaml",
82+
dom_id: '#swagger-ui',
83+
presets: [
84+
SwaggerUIBundle.presets.apis,
85+
SwaggerUIStandalonePreset
86+
],
87+
layout: "StandaloneLayout",
88+
deepLinking: true,
89+
showExtensions: true,
90+
showCommonExtensions: true
91+
});
92+
};
93+
</script>
94+
</body>
95+
</html>`;
96+
97+
fs.writeFileSync(outputPath, html, 'utf8');
98+
console.log(`✅ Swagger UI built successfully: ${outputPath}`);
99+

0 commit comments

Comments
 (0)