# SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project # # SPDX-License-Identifier: Apache-2.0 name: Publish Swagger on: push: branches: - main jobs: build: runs-on: ubuntu-latest outputs: swagger_valid: ${{ steps.validate-swagger.outputs.swagger_valid }} steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Build and Run Docker Compose run: | docker compose -f ${{ github.workspace }}/apps/Server/docker-compose.yml up -d - name: Generate Swagger JSON run: | echo "Fetching Swagger JSON..." curl --retry 3 --retry-delay 3 --retry-all-errors -o swagger.json http://localhost:8080/docs/json - name: Validate Swagger JSON id: validate-swagger run: | if jq empty swagger.json; then echo "swagger_valid=true" >> $GITHUB_OUTPUT else echo "swagger_valid=false" >> $GITHUB_OUTPUT && exit 1 fi - name: Upload Swagger JSON as Artifact uses: actions/upload-artifact@v4 with: name: swagger-json path: swagger.json - name: Clean up Docker run: docker compose -f ${{ github.workspace }}/apps/Server/docker-compose.yml down publish-swagger: needs: build if: needs.build.outputs.swagger_valid == 'true' runs-on: ubuntu-latest steps: - name: Download Swagger Artifact uses: actions/download-artifact@v4 with: name: swagger-json - name: Checkout citrineos.github.io uses: actions/checkout@v4 with: repository: citrineos/citrineos.github.io ssh-key: ${{ secrets.CITRINEOS_GITHUB_IO_DEPLOY_KEY }} path: citrineos.github.io - name: Push Swagger JSON run: | cd citrineos.github.io git checkout -b swagger-updates || git checkout swagger-updates cp ../swagger.json ./docs/assets git config user.name "GitHub Actions" git config user.email "actions@github.com" git add ./docs/assets/swagger.json git commit -m "Update Swagger JSON from PR" git push -f origin swagger-updates --verbose