restxq-rollback docs #12
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: CI | |
| on: | |
| push: | |
| branches: [ main, develop, dev, dev-* ] | |
| pull_request: | |
| branches: [ main, develop, dev ] | |
| workflow_dispatch: | |
| jobs: | |
| build-test: | |
| name: Build and Test Package | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build package (without data) | |
| run: npm run dist | |
| - name: Check package was created | |
| run: | | |
| if [ ! -f dist/api-*.xar ]; then | |
| echo "Error: Package file not created" | |
| exit 1 | |
| fi | |
| ls -lh dist/api-*.xar | |
| echo "Package size: $(du -h dist/api-*.xar | cut -f1)" | |
| - name: Upload package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: api-package | |
| path: dist/api-*.xar | |
| retention-days: 7 | |
| docker-build-test: | |
| name: Docker Build and Integration Test | |
| runs-on: ubuntu-latest | |
| needs: build-test | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| load: true | |
| tags: bw-api:test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Check image size | |
| run: | | |
| docker images bw-api:test | |
| SIZE=$(docker images bw-api:test --format "{{.Size}}") | |
| echo "Docker image size: $SIZE" | |
| - name: Start container | |
| run: | | |
| docker run -d --name bw-api-test \ | |
| -p 8080:8080 \ | |
| -e EXIST_PASSWORD=testpass123 \ | |
| bw-api:test | |
| echo "Container started, waiting for eXist-DB to initialize..." | |
| - name: Wait for eXist-DB startup | |
| run: | | |
| echo "Waiting 90 seconds for full startup (eXist + package deployment + RESTXQ registration)..." | |
| sleep 90 | |
| - name: Check container is running | |
| run: | | |
| if ! docker ps | grep -q bw-api-test; then | |
| echo "Error: Container not running" | |
| docker logs bw-api-test | |
| exit 1 | |
| fi | |
| echo "Container is running" | |
| - name: Test eXist-DB is accessible | |
| run: | | |
| echo "Testing eXist-DB main page..." | |
| curl -f http://localhost:8080/exist/ || { | |
| echo "Error: eXist-DB not accessible" | |
| docker logs bw-api-test | |
| exit 1 | |
| } | |
| echo "✓ eXist-DB is accessible" | |
| - name: Test API app is deployed | |
| run: | | |
| echo "Testing API application..." | |
| curl -f http://localhost:8080/exist/apps/api/ || { | |
| echo "Error: API app not deployed" | |
| docker logs bw-api-test | |
| exit 1 | |
| } | |
| echo "✓ API app is deployed" | |
| - name: Test RESTXQ endpoints are registered | |
| run: | | |
| echo "Testing RESTXQ endpoint..." | |
| RESPONSE=$(curl -s http://localhost:8080/exist/restxq/iiif/documents.json) | |
| # Check if we get a 405 error (RESTXQ not registered) | |
| if echo "$RESPONSE" | grep -q "405"; then | |
| echo "Error: RESTXQ endpoints not registered (got 405)" | |
| echo "Response: $RESPONSE" | |
| docker logs bw-api-test | grep -i "post-install\|restxq" | |
| exit 1 | |
| fi | |
| # Check if we get valid JSON with array structure | |
| if ! echo "$RESPONSE" | jq -e 'type == "array"' > /dev/null 2>&1; then | |
| echo "Error: Invalid response from RESTXQ endpoint" | |
| echo "Response: $RESPONSE" | |
| exit 1 | |
| fi | |
| echo "✓ RESTXQ endpoints are working" | |
| echo "Sample response:" | |
| echo "$RESPONSE" | jq -r '.[3] | if type == "array" then .[0] else . end | .id // empty' | head -3 | |
| - name: Test OpenAPI spec generation | |
| run: | | |
| echo "Testing OpenAPI spec..." | |
| SPEC=$(curl -s http://localhost:8080/exist/apps/api/openapi.json) | |
| # Validate it's valid JSON | |
| if ! echo "$SPEC" | jq empty 2>/dev/null; then | |
| echo "Error: OpenAPI spec is not valid JSON" | |
| echo "Response: $SPEC" | |
| exit 1 | |
| fi | |
| # Check OpenAPI version | |
| VERSION=$(echo "$SPEC" | jq -r '.openapi') | |
| if [ "$VERSION" != "3.0.0" ]; then | |
| echo "Error: Wrong OpenAPI version: $VERSION" | |
| exit 1 | |
| fi | |
| # Check number of paths | |
| PATHS=$(echo "$SPEC" | jq '.paths | length') | |
| if [ "$PATHS" -lt 40 ]; then | |
| echo "Error: Too few endpoints in OpenAPI spec: $PATHS (expected 40+)" | |
| echo "Paths found:" | |
| echo "$SPEC" | jq '.paths | keys' | |
| exit 1 | |
| fi | |
| echo "✓ OpenAPI spec is valid" | |
| echo " Version: $VERSION" | |
| echo " Endpoints: $PATHS" | |
| - name: Test Swagger UI is accessible | |
| run: | | |
| echo "Testing Swagger UI..." | |
| curl -f http://localhost:8080/exist/apps/api/docs.html || { | |
| echo "Error: Swagger UI not accessible" | |
| exit 1 | |
| } | |
| echo "✓ Swagger UI is accessible" | |
| - name: Check RESTXQ registration in logs | |
| if: always() | |
| run: | | |
| echo "Checking for RESTXQ registration messages..." | |
| docker logs bw-api-test 2>&1 | grep -i "post-install.*registered" || { | |
| echo "Warning: No RESTXQ registration messages found in logs" | |
| echo "Full logs:" | |
| docker logs bw-api-test 2>&1 | tail -50 | |
| } | |
| - name: Show container logs on failure | |
| if: failure() | |
| run: | | |
| echo "=== Container Logs ===" | |
| docker logs bw-api-test | |
| echo "=== Container Status ===" | |
| docker ps -a | grep bw-api-test | |
| - name: Stop container | |
| if: always() | |
| run: docker rm -f bw-api-test || true | |
| docker-data-test: | |
| name: Docker with Data Test | |
| runs-on: ubuntu-latest | |
| needs: docker-build-test | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image with data | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| load: true | |
| tags: bw-api:test-data | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Check image size with data | |
| run: | | |
| docker images bw-api:test-data | |
| SIZE=$(docker images bw-api:test-data --format "{{.Size}}") | |
| echo "Docker image size with data: $SIZE" | |
| - name: Start container with data | |
| run: | | |
| docker run -d --name bw-api-data-test \ | |
| -p 8080:8080 \ | |
| -e EXIST_PASSWORD=testpass123 \ | |
| bw-api:test-data | |
| echo "Container started, waiting for deployment with data..." | |
| sleep 120 # Data deployment takes longer | |
| - name: Test data is available | |
| run: | | |
| echo "Testing if documents are available..." | |
| RESPONSE=$(curl -s http://localhost:8080/exist/restxq/iiif/documents.json) | |
| # Extract just the documents array (skip CORS headers) | |
| DOCS=$(echo "$RESPONSE" | jq '.[3]') | |
| DOC_COUNT=$(echo "$DOCS" | jq 'length') | |
| if [ "$DOC_COUNT" -eq 0 ]; then | |
| echo "Error: No documents found in API" | |
| echo "Response: $RESPONSE" | |
| exit 1 | |
| fi | |
| echo "✓ Data is available" | |
| echo " Documents found: $DOC_COUNT" | |
| echo " Sample document:" | |
| echo "$DOCS" | jq '.[0]' | |
| - name: Stop container | |
| if: always() | |
| run: docker rm -f bw-api-data-test || true | |
| summary: | |
| name: Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [build-test, docker-build-test, docker-data-test] | |
| if: always() | |
| steps: | |
| - name: Check job results | |
| run: | | |
| echo "Build Test: ${{ needs.build-test.result }}" | |
| echo "Docker Build Test: ${{ needs.docker-build-test.result }}" | |
| echo "Docker Data Test: ${{ needs.docker-data-test.result }}" | |
| if [ "${{ needs.build-test.result }}" != "success" ] || \ | |
| [ "${{ needs.docker-build-test.result }}" != "success" ]; then | |
| echo "❌ Required tests failed" | |
| exit 1 | |
| fi | |
| echo "✅ All required tests passed" |