ci(test): add Swagger endpoint tests workflow #57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Swagger Endpoint Tests | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref_name || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| files-changed: | |
| name: detect what files changed | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 3 | |
| outputs: | |
| swagger-endpoint-test: ${{ steps.changes.outputs.swagger-endpoint-test || steps.workflow_dispatch_changes.outputs.swagger-endpoint-test }} | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Check for file changes | |
| if: github.event_name == 'pull_request' | |
| uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | |
| id: changes | |
| with: | |
| filters: .github/config/.files.yaml | |
| - name: Dispatch swagger-endpoint-test job | |
| if: github.event_name == 'workflow_dispatch' | |
| id: workflow_dispatch_changes | |
| run: echo "swagger-endpoint-test=true" >> $GITHUB_OUTPUT | |
| build-jar: | |
| if: needs.files-changed.outputs.swagger-endpoint-test == 'true' | |
| needs: files-changed | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Set up Java 21 | |
| uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| - name: Build Stirling PDF application | |
| run: ./gradlew :stirling-pdf:bootJar | |
| env: | |
| DISABLE_ADDITIONAL_FEATURES: false | |
| STIRLING_PDF_DESKTOP_UI: false | |
| - name: Locate and upload JAR | |
| run: | | |
| JAR_PATH=$(ls app/core/build/libs/stirling-pdf-*.jar | head -n 1) | |
| if [ -z "$JAR_PATH" ]; then | |
| echo "Unable to find built jar" >&2 | |
| exit 1 | |
| fi | |
| echo "JAR_PATH=$JAR_PATH" >> $GITHUB_ENV | |
| echo "Uploading $JAR_PATH as artifact..." | |
| - name: Upload JAR artifact | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: stirling-pdf-jar | |
| path: ${{ env.JAR_PATH }} | |
| retention-days: 1 | |
| swagger-ci: | |
| if: needs.files-changed.outputs.swagger-endpoint-test == 'true' | |
| needs: [files-changed, build-jar] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include-tags: | |
| [ | |
| "Filter", | |
| "Security", | |
| "Analysis", | |
| "Misc", | |
| "Info", | |
| "Job Management", | |
| "Convert", | |
| "General", | |
| ] | |
| # exclude-tags: | |
| # [ | |
| # "Authentication", | |
| # "Database", | |
| # "Database Management", | |
| # "Audit", | |
| # "Admin Job Management", | |
| # "Admin License Management", | |
| # "Admin Settings", | |
| # "Pipeline", | |
| # ] | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Download JAR artifact | |
| uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 | |
| with: | |
| name: stirling-pdf-jar | |
| path: . | |
| - name: Locate downloaded JAR | |
| run: | | |
| JAR_PATH=$(ls stirling-pdf-*.jar | head -n 1) | |
| if [ -z "$JAR_PATH" ]; then | |
| echo "Downloaded JAR not found!" >&2 | |
| exit 1 | |
| fi | |
| echo "JAR_PATH=$JAR_PATH" >> $GITHUB_ENV | |
| - name: Set up Java 21 | |
| uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| - name: Start Stirling PDF | |
| run: | | |
| export SECURITY_CUSTOMGLOBALAPIKEY=123456789 | |
| java -jar "$JAR_PATH" > server.log 2>&1 & | |
| echo $! > server.pid | |
| - name: Wait for application to be ready | |
| run: | | |
| for attempt in $(seq 1 30); do | |
| status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/v1/api-docs || true) | |
| if [ "$status" != "000" ] && [ "$status" -lt 500 ]; then | |
| echo "Server is ready (HTTP $status)" | |
| exit 0 | |
| fi | |
| echo "Waiting for server... (attempt $attempt)" | |
| sleep 5 | |
| done | |
| echo "Application did not become ready in time" >&2 | |
| cat server.log || true | |
| exit 1 | |
| - name: Set up Python | |
| uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 | |
| with: | |
| python-version: "3.12" | |
| cache: pip | |
| - name: Install Python dependencies | |
| run: pip install --require-hashes -r ./.github/scripts/requirements_swagger.txt | |
| - name: Run Swagger endpoint tests - ${{ matrix.include-tags }} | |
| run: python testing/swagger_endpoint_test.py --base-url http://localhost:8080 --include-tags "${{ matrix.include-tags }}" --x-api-key 123456789 | |
| - name: Stop Stirling PDF | |
| if: always() | |
| run: | | |
| if [ -f server.pid ]; then | |
| kill $(cat server.pid) || true | |
| wait $(cat server.pid) 2>/dev/null || true | |
| fi | |
| - name: Upload server logs | |
| if: failure() | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: swagger-server-logs-${{ matrix.include-tags }} | |
| path: server.log | |
| if-no-files-found: ignore | |
| retention-days: 3 |