Skip to content

Commit e3f4b72

Browse files
authored
chore: Add build and publish OpenAPI UI workflow (#261)
# Problem OpenAPI specs need to be published in the mono-repo. Closes #260 # Solution - Updated github workflows to publish the OpenAPI spec for each service ## Steps to Verify: 1. Verify that the docs are published correctly on github pages. 2. The link tree: https://amplicalabs.github.io/gateway/ ```bash ├── account │ ├── index.html (OpenAPI spec) ├── content-watcher │ ├── index.html (OpenAPI spec) ├── content-publishing │ ├── index.html (OpenAPI spec) ├── graph │ ├── index.html (OpenAPI spec) ├── index.html (mdbook) ```
1 parent 0dbd4a9 commit e3f4b72

File tree

9 files changed

+129
-15
lines changed

9 files changed

+129
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Publish OpenAPI UI
2+
description: "Build and publish OpenAPI UI for a service"
3+
4+
inputs:
5+
service:
6+
description: "The name of the service to build OpenAPI UI for"
7+
required: true
8+
type: string
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
shell: bash
24+
working-directory: ./services/${{ inputs.service }}
25+
26+
- name: Generate Swagger Metadata
27+
run: npm run build:metadata
28+
shell: bash
29+
working-directory: ./services/${{ inputs.service }}
30+
31+
- name: Generate OpenAPI/Swagger JSON
32+
run: npm run build:swagger
33+
shell: bash
34+
working-directory: ./services/${{ inputs.service }}
35+
36+
- name: Generate OpenAPI/Swagger UI
37+
run: npm run generate-swagger-ui
38+
shell: bash
39+
working-directory: ./services/${{ inputs.service }}
40+
41+
- name: Copy OpenAPI Spec (index.html) to root docs directory
42+
run: cp ./services/${{ inputs.service }}/docs/index.html ./docs/${{ inputs.service }}/
43+
shell: bash

.github/workflows/deploy-gh-pages.yaml

+77-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ permissions:
1515
id-token: write
1616

1717
jobs:
18-
build:
18+
# Build mdbook
19+
build-mdbook:
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Checkout
@@ -33,19 +34,89 @@ jobs:
3334
working-directory: docs
3435
run: mdbook build && ls book
3536

36-
- name: Upload artifact
37-
uses: actions/upload-pages-artifact@v3
37+
# Upload the mdBook output to GitHub Pages
38+
- name: Upload mdbook to GitHub Pages
39+
uses: actions/upload-artifact@v4
3840
with:
39-
path: ./docs/book
41+
name: mdbook
42+
path: ./docs
43+
44+
build:
45+
runs-on: ubuntu-latest
46+
strategy:
47+
matrix:
48+
service:
49+
- account
50+
- content-watcher
51+
- content-publishing
52+
- graph
53+
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
# Publish OpenAPI specs for each microservice
59+
- name: Build and Publish OpenAPI spec for ${{ matrix.service }}
60+
uses: ./.github/workflows/common/openapi-build
61+
with:
62+
service: ${{ matrix.service }}
63+
64+
- name: Upload OpenAPI UI artifact for ${{ matrix.service }}
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: openapi-${{ matrix.service }}
68+
path: ./docs/${{ matrix.service }}
4069

4170
# Deployment job
4271
deploy:
72+
name: Deploy mdbook and OpenAPI microservices to GitHub Pages
73+
runs-on: ubuntu-latest
74+
needs: [build, build-mdbook]
4375
environment:
4476
name: github-pages
4577
url: ${{ steps.deployment.outputs.page_url }}
46-
runs-on: ubuntu-latest
47-
needs: build
4878
steps:
79+
- name: Checkout
80+
uses: actions/checkout@v4
81+
82+
- name: Download mdbook artifact
83+
uses: actions/download-artifact@v4
84+
with:
85+
name: mdbook
86+
path: ./docs
87+
88+
- name: Move mdbook to root
89+
run: mv ./docs/book/* ./docs
90+
shell: bash
91+
92+
- name: Download account OpenAPI artifacts
93+
uses: actions/download-artifact@v4
94+
with:
95+
name: openapi-account
96+
path: ./docs/account
97+
98+
- name: Download content-watcher OpenAPI artifacts
99+
uses: actions/download-artifact@v4
100+
with:
101+
name: openapi-content-watcher
102+
path: ./docs/content-watcher
103+
104+
- name: Download content-publishing OpenAPI artifacts
105+
uses: actions/download-artifact@v4
106+
with:
107+
name: openapi-content-publishing
108+
path: ./docs/content-publishing
109+
110+
- name: Download graph OpenAPI artifacts
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: openapi-graph
114+
path: ./docs/graph
115+
116+
- name: Upload final result to GitHub Pages
117+
uses: actions/upload-pages-artifact@v3
118+
with:
119+
path: ./docs
49120
- name: Deploy to GitHub Pages
50121
id: deployment
51122
uses: actions/deploy-pages@v4

docs/account/.gitkeep

Whitespace-only changes.

docs/content-publishing/.gitkeep

Whitespace-only changes.

docs/content-watcher/.gitkeep

Whitespace-only changes.

docs/graph/.gitkeep

Whitespace-only changes.

services/content-publishing/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "dist/apps/api/main.js",
66
"scripts": {
77
"build": "nest build api && nest build worker",
8-
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
9-
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
10-
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
8+
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
9+
"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
10+
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
1111
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
1212
"start:api": "nest start api",
1313
"start:api:watch": "nest start api --watch",

services/content-watcher/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"start:dev": "set -a ; . .env ; nest start api --watch",
1111
"start:debug": "set -a ; . .env ; nest start api --debug --watch",
1212
"build": "nest build",
13-
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
14-
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
15-
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
13+
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
14+
"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
15+
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
1616
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
1717
"docker-build": "docker build -t content-watcher-service .",
1818
"docker-build:dev": "docker-compose build",

services/graph/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "dist/apps/api/main.js",
66
"scripts": {
77
"build": "nest build api && nest build worker",
8-
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
9-
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
10-
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
8+
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
9+
"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
10+
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
1111
"generate-webhook-types": "npx openapi-client-axios-typegen graph-webhooks.openapi.yaml > libs/common/src/types/webhook-types.d.ts",
1212
"start:api": "nest start api",
1313
"start:api:watch": "nest start api --watch",

0 commit comments

Comments
 (0)