Skip to content

fix error

fix error #5

Workflow file for this run

name: Generate Swagger UI for API specs of data models
env:
JSON_SCHEMA_PATH: ./example_building_automation/schemas
OUTPUT_ROOT: ./example_building_automation
on:
push:
# Adjust branches as needed
branches:
- main
jobs:
set-matrix:
runs-on: ubuntu-latest
concurrency:
group: gh-pages-deployment
cancel-in-progress: false
outputs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Find API spec files and build matrix
id: build-matrix
run: |
# Find all YAML files under any "api_docs" directory
specs=$(find . -type f -path "*/api_docs/*.yaml")
echo "Found spec files:"
echo "$specs"
# Build a JSON matrix: for each spec, the output directory is under the same api_docs folder.
matrix="[]"
for spec in $specs; do
# Remove the .yaml extension from the file name
base=$(basename "$spec" .yaml)
# Get the directory of the spec file
spec_dir=$(dirname "$spec")
# For each spec, the generated output will reside in: <spec_dir>/swagger-ui/<basename>
output_dir="${spec_dir}/swagger-ui/${base}"
newEntry="{\"spec\":\"${spec}\", \"output\":\"${output_dir}\"}"
if [ "$matrix" = "[]" ]; then
matrix="[$newEntry]"
else
matrix="${matrix%]}"
matrix+=",${newEntry}]"
fi
done
echo "Matrix JSON: $matrix"
# Set the matrix output (using the GITHUB_OUTPUT mechanism)
echo "matrix=$matrix" >> $GITHUB_OUTPUT
generate-swagger-ui:
needs: set-matrix
runs-on: ubuntu-latest
strategy:
# Use the dynamically generated matrix.
# Each job will process one API spec file.
matrix:
include: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create output folder if not present
run: mkdir -p "${{ matrix.output }}"
- name: Generate Swagger UI for ${{ matrix.spec }}
uses: Legion2/swagger-ui-action@v1
with:
# The file to process from the matrix.
spec-file: ${{ matrix.spec }}
# The output directory, computed in the matrix (e.g. swagger-ui/ActuatorFiware)
output: ${{ matrix.output }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact for ${{ matrix.folder }}
uses: actions/upload-artifact@v4
with:
# Each artifact is named after the folder, ensuring uniqueness
name: ${{ matrix.output }}
path: ${{ matrix.output }}
- name: Copy schemas folder if available
run: |
# For a spec like "./module/api_docs/my-api.yaml", the related schemas folder is assumed to be at "./module/schemas"
parent_dir=$(dirname "$(dirname "${{ matrix.spec }}")")
schemas_dir="$parent_dir/schemas"
if [ -d "$schemas_dir" ]; then
echo "Found schemas directory: $schemas_dir"
# Copy the entire schemas folder into the output folder (as a subfolder named "schemas")
mkdir -p "${{ matrix.output }}/schemas"
cp -r "$schemas_dir/"* "${{ matrix.output }}/schemas/"
echo "Copied schemas from $schemas_dir to ${{ matrix.output }}/schemas/"
else
echo "No schemas folder found at $parent_dir/schemas"
fi
# - name: Deploy to GitHub Pages
# uses: peaceiris/actions-gh-pages@v4
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# # Change the publish_dir to the folder you want served.
# # Here we deploy the directory containing the generated swagger-ui (and now also the schemas folder, if available).
# publish_dir: ${{ matrix.output }}
# destination_dir: ${{ matrix.output }}
deploy-gh-pages:
runs-on: ubuntu-latest
needs: generate-swagger-ui
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all UI artifacts
uses: actions/download-artifact@v4
with:
# This downloads all artifacts (each will be placed in its own folder
# under the "deploy" directory)
path: $OUTPUT_ROOT
# (Optional) In case you want to include JSON data as well:
- name: Copy JSON data
run: |
mkdir -p "$OUTPUT_ROOT/schemas"
cp -R $JSON_SCHEMA_PATH/*.json $OUTPUT_ROOT/schemas/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: $OUTPUT_ROOT