Skip to content

Commit

Permalink
Merge pull request #994 from ninoseki/improve-ci
Browse files Browse the repository at this point in the history
ci: build ReDoc docs in CI
  • Loading branch information
ninoseki authored Jan 8, 2024
2 parents a09daee + b2458f1 commit 3124cc2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 918 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: frontend/package-lock.json
# Build YAML format Swagger doc
- name: Build Swagger doc
run: bundle exec rake build:swagger
# Build ReDoc docs & buld the frontend assets
- name: Buld frontend
run: |
npm install
npm run build
npm run docs
npm run build-only
working-directory: frontend
# Copy the frontend assets into lib
- name: Copy forntend assets
run: |
mkdir -p lib/mihari/web/public/
Expand Down
40 changes: 39 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,49 @@ RSpec::Core::RakeTask.new(:spec)

task default: :spec

desc "run rackup (via rerun)"
desc "Run rackup (with rerun)"
task :rackup do
sh "rerun --pattern '{Gemfile.lock,lib/**/*.rb,lib/*.rb}' -- rackup config.ru"
end

def recursive_delete(hash, to_remove)
hash.delete(to_remove)
hash.each_value do |value|
recursive_delete(value, to_remove) if value.is_a? Hash
end
end

def build_swagger_doc(path)
require_relative "lib/mihari"
require_relative "lib/mihari/web/application"

require "rack/test"

app = Mihari::Web::App.new
session = Rack::Test::Session.new(app)

res = session.request("/api/swagger_doc")

json = JSON.parse(res.body.to_s)
# remove host because it can be varied
keys_to_remove = %w[host]
keys_to_remove.each do |key|
recursive_delete json, key
end

f = File.open(path, "w")
f.write json.to_yaml
f.close
end

namespace :build do
desc "Build Swagger doc"
task :swagger, [:path] do |_t, args|
args.with_defaults(path: "./frontend/swagger.yaml")
build_swagger_doc args.path
end
end

def ci?
ENV.fetch("CI", false)
end
Expand Down
4 changes: 3 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ coverage
*.sln
*.sw?

# redoc
# Swagger & ReDoc
swagger.yaml
public/redoc-static.html

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"scripts": {
"build-only": "vite build",
"build-redoc": "npx @redocly/cli build-docs src/swagger.yaml -o public/redoc-static.html",
"build": "run-p type-check build-only build-redoc",
"docs": "npx @redocly/cli build-docs swagger.yaml -o public/redoc-static.html",
"build": "run-p type-check build-only",
"dev": "vite",
"format": "prettier --write src/",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
Expand Down
23 changes: 0 additions & 23 deletions frontend/scripts/swagger_doc_to_yaml.rb

This file was deleted.

Loading

0 comments on commit 3124cc2

Please sign in to comment.