From 7a3acba94dc49ca2250d94d3d4beb1c7b9da200a Mon Sep 17 00:00:00 2001 From: noracami Date: Sun, 13 Oct 2024 12:42:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20add=20gha=20to=20generate=20swag?= =?UTF-8?q?ger=20[no=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-swagger.yml | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/build-swagger.yml diff --git a/.github/workflows/build-swagger.yml b/.github/workflows/build-swagger.yml new file mode 100644 index 0000000..5966d9c --- /dev/null +++ b/.github/workflows/build-swagger.yml @@ -0,0 +1,59 @@ +name: Deploy Swagger UI to GitHub Pages + +on: + push: + branches: [main] + paths: + - "spec/**" + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + deploy: + environment: + name: swagger-ui + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + - name: Generate UI assets for Swagger + env: + RAILS_ENV: test + run: | + bundle exec rake rswag:ui:copy_assets[public/api-docs] + cp -r public/api-docs/* public/ + mv public/generated_swagger_index.html public/index.html + - name: Generate Swagger YAML + env: + RAILS_ENV: test + API_DOC_MODE: 1 + run: | + bundle exec rake rswag:specs:swaggerize + mkdir -p public/api-docs/v1 + cp swagger/v1/swagger.yaml public/api-docs/v1/swagger.yaml + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: "./public" + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4