Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add build and publish OpenAPI UI workflow #261

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/common/openapi-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Publish OpenAPI UI
description: "Build and publish OpenAPI UI for a service"

inputs:
service:
description: "The name of the service to build OpenAPI UI for"
required: true
type: string

runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm ci
shell: bash
working-directory: ./services/${{ inputs.service }}

- name: Generate Swagger Metadata
run: npm run build:metadata
shell: bash
working-directory: ./services/${{ inputs.service }}

- name: Generate OpenAPI/Swagger JSON
run: npm run build:swagger
shell: bash
working-directory: ./services/${{ inputs.service }}

- name: Generate OpenAPI/Swagger UI
run: npm run generate-swagger-ui
shell: bash
working-directory: ./services/${{ inputs.service }}
Comment on lines +26 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I'm about to publish a PR standardizing on the following pattern for these targets:

generate:metadata
generate:openapi
generate:swagger-ui

Once this is merged, I'll pull into my PR & update the workflows.


- name: Copy OpenAPI Spec (index.html) to root docs directory
run: cp ./services/${{ inputs.service }}/docs/index.html ./docs/${{ inputs.service }}/
shell: bash
83 changes: 77 additions & 6 deletions .github/workflows/deploy-gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ permissions:
id-token: write

jobs:
build:
# Build mdbook
build-mdbook:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -33,19 +34,89 @@ jobs:
working-directory: docs
run: mdbook build && ls book

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
# Upload the mdBook output to GitHub Pages
- name: Upload mdbook to GitHub Pages
uses: actions/upload-artifact@v4
with:
path: ./docs/book
name: mdbook
path: ./docs

build:
runs-on: ubuntu-latest
strategy:
matrix:
service:
- account
- content-watcher
- content-publishing
- graph

steps:
- name: Checkout
uses: actions/checkout@v4

# Publish OpenAPI specs for each microservice
- name: Build and Publish OpenAPI spec for ${{ matrix.service }}
uses: ./.github/workflows/common/openapi-build
with:
service: ${{ matrix.service }}

- name: Upload OpenAPI UI artifact for ${{ matrix.service }}
uses: actions/upload-artifact@v4
with:
name: openapi-${{ matrix.service }}
path: ./docs/${{ matrix.service }}

# Deployment job
deploy:
name: Deploy mdbook and OpenAPI microservices to GitHub Pages
runs-on: ubuntu-latest
needs: [build, build-mdbook]
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download mdbook artifact
uses: actions/download-artifact@v4
with:
name: mdbook
path: ./docs

- name: Move mdbook to root
run: mv ./docs/book/* ./docs
shell: bash

- name: Download account OpenAPI artifacts
uses: actions/download-artifact@v4
with:
name: openapi-account
path: ./docs/account

- name: Download content-watcher OpenAPI artifacts
uses: actions/download-artifact@v4
with:
name: openapi-content-watcher
path: ./docs/content-watcher

- name: Download content-publishing OpenAPI artifacts
uses: actions/download-artifact@v4
with:
name: openapi-content-publishing
path: ./docs/content-publishing

- name: Download graph OpenAPI artifacts
uses: actions/download-artifact@v4
with:
name: openapi-graph
path: ./docs/graph

- name: Upload final result to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./docs
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Empty file added docs/account/.gitkeep
Empty file.
Empty file.
Empty file added docs/content-watcher/.gitkeep
Empty file.
Empty file added docs/graph/.gitkeep
Empty file.
6 changes: 3 additions & 3 deletions services/content-publishing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "dist/apps/api/main.js",
"scripts": {
"build": "nest build api && nest build worker",
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added env.template to each service openapi build because the build was failing without the environment variables.

"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
"start:api": "nest start api",
"start:api:watch": "nest start api --watch",
Expand Down
6 changes: 3 additions & 3 deletions services/content-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"start:dev": "set -a ; . .env ; nest start api --watch",
"start:debug": "set -a ; . .env ; nest start api --debug --watch",
"build": "nest build",
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
"docker-build": "docker build -t content-watcher-service .",
"docker-build:dev": "docker-compose build",
Expand Down
6 changes: 3 additions & 3 deletions services/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "dist/apps/api/main.js",
"scripts": {
"build": "nest build api && nest build worker",
"build:swagger": "npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
"build:metadata": "npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"build:swagger": "set -a ; . ./env.template ; npx ts-node -r tsconfig-paths/register apps/api/src/build-openapi.ts",
"build:metadata": "set -a ; . ./env.template ; npx ts-node apps/api/src/generate-metadata.ts",
"generate-swagger-ui": "set -a ; . ./env.template ; npx --yes @redocly/cli build-docs swagger.json --output=./docs/index.html",
"generate-webhook-types": "npx openapi-client-axios-typegen graph-webhooks.openapi.yaml > libs/common/src/types/webhook-types.d.ts",
"start:api": "nest start api",
"start:api:watch": "nest start api --watch",
Expand Down