Skip to content

docs: adapt workflow to upload json schema #3

docs: adapt workflow to upload json schema

docs: adapt workflow to upload json schema #3

Workflow file for this run

name: Generate Swagger UI for API specs of data models
on:
push:
# Adjust branches as needed
branches:
- '**'
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
update-docs:
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: 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 }}