Skip to content

chore: update environment vars #17

chore: update environment vars

chore: update environment vars #17

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_PATH: example_building_automation/deploy
API_DOCS_PATH: example_building_automation/api_docs
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 "api_docs" directory
specs=$(find "$API_DOCS_PATH" -type f -name "*.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)
echo "found base name: $base"
# 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}\", \"base\":\"${base}\"}"
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.base }}
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.base }}
uses: actions/upload-artifact@v4
with:
# Each artifact is named after the folder, ensuring uniqueness
name: ${{ matrix.base }}
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
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:
path: ${{ env.OUTPUT_ROOT_PATH }}/swagger-ui
- name: Copy JSON data
run: |
mkdir -p "$OUTPUT_ROOT_PATH/schemas"
cp -R $JSON_SCHEMA_PATH/*.json $OUTPUT_ROOT_PATH/schemas/
- name: Generate resource list
shell: bash
run: |
echo "Generating resource list dynamically..."
schema_dir="$OUTPUT_ROOT_PATH/schemas"
swagger_dir="$OUTPUT_ROOT_PATH/swagger-ui"
repo_name=${GITHUB_REPOSITORY##*/}
site_url="https://${GITHUB_REPOSITORY_OWNER}.github.io/${repo_name}"
echo "---"
for file in "$schema_dir"/*.json; do
base=$(basename "$file" .json)
echo "**${base}**"
echo "- [Schema](${site_url}/${schema_dir}/${base}.json)"
echo "- [Swagger document](${site_url}/${swagger_dir}/${base}/)"
echo ""
done
echo "---"
echo "Done. See the resource list above."
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ env.OUTPUT_ROOT_PATH }}
destination_dir: ${{ env.OUTPUT_ROOT_PATH }}