diff --git a/.github/workflows/test-cases.yml b/.github/workflows/test-cases.yml new file mode 100644 index 0000000..5d7c6c7 --- /dev/null +++ b/.github/workflows/test-cases.yml @@ -0,0 +1,101 @@ +name: Test NDC Test Cases (Relational DB) + +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch, tag or SHA to test' + required: true + default: 'main' + type: string + push: + branches: + - main + paths: + - 'relational/**' + - 'static/relational/**' + +jobs: + validate-test-cases: + runs-on: ubuntu-latest + + steps: + - name: Checkout ndc-test-cases + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} + + - name: Setup Docker + uses: docker/setup-buildx-action@v3 + + - name: Start PostgreSQL + working-directory: static/relational/postgres + run: | + docker compose up -d postgres + + # Wait for PostgreSQL to be healthy + until docker compose ps postgres | grep "healthy"; do + echo "Waiting for PostgreSQL..." + sleep 5 + done + + - name: Setup NDC Postgres + working-directory: static/relational/postgres + run: | + # Get latest NDC Postgres version + NDC_POSTGRES_VERSION=$(curl -s https://api.github.com/repos/hasura/ndc-postgres/releases/latest | jq -r .tag_name) + echo "Using NDC Postgres version: ${NDC_POSTGRES_VERSION}" + + # Download and setup NDC Postgres + BINARY_URL="https://github.com/hasura/ndc-postgres/releases/download/${NDC_POSTGRES_VERSION}/ndc-postgres-cli-x86_64-unknown-linux-gnu" + curl -L --fail -o ndc-postgres-cli "${BINARY_URL}" + chmod +x ndc-postgres-cli + + # Initialize and configure NDC using existing metadata + ./ndc-postgres-cli update + + # Start NDC service + docker compose up -d connector + + # Wait for NDC service to be healthy + until docker compose ps connector | grep "healthy"; do + echo "Waiting for NDC service..." + sleep 5 + + if docker compose ps connector | grep -q "(Exit"; then + echo "Error: NDC service failed to start" + docker compose logs connector + exit 1 + fi + done + + - name: Download and Setup NDC Test + working-directory: static/relational/postgres + run: | + curl -L --fail -o ndc-test https://github.com/hasura/ndc-spec/releases/download/v0.1.6/ndc-test-x86_64-unknown-linux-gnu + chmod +x ndc-test + + - name: Run Tests + working-directory: static/relational/postgres + run: | + ./ndc-test replay --endpoint http://localhost:8080 --snapshots-dir ../../relational + + - name: Collect Logs on Failure + if: failure() + working-directory: static/relational/postgres + run: | + mkdir -p logs + docker compose logs postgres > logs/postgres.log + docker compose logs connector > logs/connector.log + + - name: Upload Logs + if: always() + uses: actions/upload-artifact@v3 + with: + name: test-logs + path: static/relational/postgres/logs/ + retention-days: 7 + +permissions: + contents: read + pull-requests: read diff --git a/static/relational/postgres/setup.sh b/static/relational/postgres/setup.sh index a31b3b3..21b5064 100755 --- a/static/relational/postgres/setup.sh +++ b/static/relational/postgres/setup.sh @@ -5,7 +5,7 @@ set -e # Check if version argument is provided if [ -z "$1" ]; then - echo "Error: Version argument is required" + echo "Error: NDC postgres version argument is required" echo "Usage: $0 " echo "Example: $0 v1.2.0" exit 1 @@ -13,6 +13,7 @@ fi VERSION=$1 BINARY_URL="https://github.com/hasura/ndc-postgres/releases/download/${VERSION}/ndc-postgres-cli-x86_64-unknown-linux-gnu" +NDC_TEST_URL="https://github.com/hasura/ndc-spec/releases/download/v0.1.6/ndc-test-x86_64-unknown-linux-gnu" # Start PostgreSQL echo "Starting PostgreSQL..." @@ -26,7 +27,7 @@ until docker compose ps postgres | grep "healthy"; do done echo "PostgreSQL is ready!" -# Download the binary with progress and status checking +# Download the NDC Postgres CLI binary echo "Downloading NDC Postgres CLI version ${VERSION}..." HTTP_RESPONSE=$(curl -L --fail \ --write-out "%{http_code}" \ @@ -41,24 +42,41 @@ if [ $? -ne 0 ] || [ "$HTTP_RESPONSE" -ne 200 ]; then exit 1 fi -echo "✓ Download completed successfully (HTTP ${HTTP_RESPONSE})" +echo "✓ Download of NDC Postgres CLI completed successfully (HTTP ${HTTP_RESPONSE})" -# Verify the download -if [ ! -f ndc-postgres-cli ]; then - echo "Error: Binary file not found after download" +# Download the NDC Test binary +echo "Downloading NDC Test..." +NDC_TEST_RESPONSE=$(curl -L --fail \ + --write-out "%{http_code}" \ + --progress-bar \ + ${NDC_TEST_URL} \ + -o ndc-test-local) + +if [ $? -ne 0 ] || [ "$NDC_TEST_RESPONSE" -ne 200 ]; then + echo "Error: Failed to download NDC Test" + echo "URL: ${NDC_TEST_URL}" + echo "HTTP Status: ${NDC_TEST_RESPONSE}" exit 1 fi -# Make the binary executable -chmod +x ndc-postgres-cli +echo "✓ Download of NDC Test completed successfully (HTTP ${NDC_TEST_RESPONSE})" -# Verify the binary is executable -if ! ./ndc-postgres-cli --help >/dev/null 2>&1; then - echo "Error: Downloaded binary is not executable or is invalid" - exit 1 -fi +# Verify the downloads and make executables +for binary in ndc-postgres-cli ndc-test-local; do + if [ ! -f "$binary" ]; then + echo "Error: $binary file not found after download" + exit 1 + fi -echo "✓ Binary verified and ready" + chmod +x "$binary" + + if ! ./"$binary" --help >/dev/null 2>&1; then + echo "Error: Downloaded $binary is not executable or is invalid" + exit 1 + fi + + echo "✓ $binary verified and ready" +done # Remove existing ndc-metadata directory if it exists if [ -d "ndc-metadata" ]; then @@ -80,7 +98,7 @@ export CONNECTION_URI='postgresql://postgres:postgres@localhost:5433/postgres' ../ndc-postgres-cli update # Start the NDC service -echo "Starting NDC Postgres service..." +echo "Starting NDC service..." cd .. # Move back to the root directory docker compose up -d connector @@ -101,6 +119,10 @@ done echo "✓ NDC service is ready and healthy!" echo "Service is running at http://localhost:8080" +# Run NDC tests +echo "Running NDC tests..." +./ndc-test replay --endpoint http://0.0.0.0:8080 --snapshots-dir ~/hasura/v3/ndc-test-cases/relational + # Keep the script running and show logs echo "Following logs... (Press Ctrl+C to stop)" docker compose logs -f postgres connector