|
| 1 | +--- |
| 2 | +name: Test Apollo Supergraph |
| 3 | + |
1 | 4 | on: |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - main |
2 | 8 | push: |
3 | | - paths: |
4 | | - - Dockerfile |
5 | | - - router.yaml |
6 | | - - .github/workflows/test.yaml |
7 | | - - .github/workflows/supergraph.graphql |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
8 | 12 | jobs: |
9 | | - test: |
10 | | - name: Smoke test Router |
| 13 | + test-subgraphs: |
| 14 | + name: Test Subgraphs |
11 | 15 | runs-on: ubuntu-latest |
12 | 16 | steps: |
13 | 17 | - name: Checkout |
14 | 18 | |
15 | | - - name: Build Docker image |
16 | | - run: docker build -t router . |
17 | | - - name: Run Router |
18 | | - run: docker run -d --name router -p 4000:4000 -v ./.github/workflows/supergraph.graphql:/dist/supergraph.graphql router -s supergraph.graphql |
19 | | - - name: Wait for Router to start |
20 | | - run: sleep 5 |
21 | | - - name: Test Router |
22 | | - run: | |
23 | | - curl http://localhost:4000 -d '{"query": "query{__typename}"}' -H "Content-Type: application/json" |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '18' |
| 24 | + cache: 'npm' |
| 25 | + cache-dependency-path: subgraphs/package-lock.json |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + cd subgraphs |
| 30 | + npm ci |
| 31 | +
|
| 32 | + - name: Test subgraphs validation |
| 33 | + run: | |
| 34 | + cd subgraphs |
| 35 | + if npm run | grep -q "validate"; then |
| 36 | + npm run validate |
| 37 | + else |
| 38 | + echo "No validate script found, skipping" |
| 39 | + fi |
| 40 | +
|
| 41 | + test-supergraph-composition: |
| 42 | + name: Test Supergraph Composition |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + |
| 47 | + |
| 48 | + - name: Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: '18' |
| 52 | + |
| 53 | + - name: Install Rover CLI |
| 54 | + run: | |
| 55 | + curl -sSL https://rover.apollo.dev/nix/latest | sh |
| 56 | + echo "$HOME/.rover/bin" >> $GITHUB_PATH |
| 57 | +
|
| 58 | + - name: Test supergraph composition |
| 59 | + run: | |
| 60 | + cd router |
| 61 | + ./compose.sh |
| 62 | +
|
| 63 | + # Verify the supergraph file was created |
| 64 | + if [ ! -f "supergraph.graphql" ]; then |
| 65 | + echo "❌ Supergraph composition failed - file not created" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + # Verify the supergraph contains expected content |
| 70 | + if ! grep -q "join__Graph" supergraph.graphql; then |
| 71 | + echo "❌ Supergraph composition failed - missing join__Graph" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "✅ Supergraph composition successful" |
| 76 | +
|
| 77 | + test-docker-builds: |
| 78 | + name: Test Docker Builds |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Checkout |
| 82 | + |
| 83 | + |
| 84 | + - name: Set up Docker Buildx |
| 85 | + uses: docker/setup-buildx-action@v3 |
| 86 | + |
| 87 | + - name: Build subgraphs Docker image |
| 88 | + run: | |
| 89 | + cd subgraphs |
| 90 | + docker build -t subgraphs:test . |
| 91 | +
|
| 92 | + # Verify the image was created |
| 93 | + if ! docker images | grep -q "subgraphs.*test"; then |
| 94 | + echo "❌ Docker build failed for subgraphs" |
| 95 | + exit 1 |
| 96 | + fi |
| 97 | +
|
| 98 | + echo "✅ Subgraphs Docker build successful" |
| 99 | +
|
| 100 | + test-scripts: |
| 101 | + name: Test Helper Scripts |
| 102 | + runs-on: ubuntu-latest |
| 103 | + steps: |
| 104 | + - name: Checkout |
| 105 | + |
| 106 | + |
| 107 | + - name: Test script syntax |
| 108 | + run: | |
| 109 | + # Test that all scripts have valid syntax |
| 110 | + for script in *.sh; do |
| 111 | + if [ -f "$script" ]; then |
| 112 | + echo "Testing syntax for $script" |
| 113 | + bash -n "$script" || exit 1 |
| 114 | + fi |
| 115 | + done |
| 116 | +
|
| 117 | + # Test scripts in scripts directory |
| 118 | + if [ -d "scripts" ]; then |
| 119 | + for script in scripts/*.sh; do |
| 120 | + if [ -f "$script" ]; then |
| 121 | + echo "Testing syntax for $script" |
| 122 | + bash -n "$script" || exit 1 |
| 123 | + fi |
| 124 | + done |
| 125 | + fi |
| 126 | +
|
| 127 | + echo "✅ All scripts have valid syntax" |
| 128 | +
|
| 129 | + - name: Test script help options |
| 130 | + run: | |
| 131 | + # Test that scripts with help options work |
| 132 | + ./run-k8s.sh --help || exit 1 |
| 133 | + ./cleanup-k8s.sh --help || exit 1 |
| 134 | + ./kill-minikube.sh --help || exit 1 |
| 135 | + ./setup-minikube.sh --help || exit 1 |
| 136 | + ./setup-env.sh --help || exit 1 |
| 137 | +
|
| 138 | + echo "✅ All script help options working" |
| 139 | +
|
| 140 | + test-k8s-yaml: |
| 141 | + name: Test Kubernetes YAML Format |
| 142 | + runs-on: ubuntu-latest |
| 143 | + steps: |
| 144 | + - name: Checkout |
| 145 | + |
| 146 | + |
| 147 | + - name: Install yamllint |
| 148 | + run: | |
| 149 | + pip install yamllint |
| 150 | +
|
| 151 | + - name: Validate YAML files |
| 152 | + run: | |
| 153 | + # Test all YAML files in k8s directory |
| 154 | + if [ -d "k8s" ]; then |
| 155 | + for yaml_file in k8s/*.yaml; do |
| 156 | + if [ -f "$yaml_file" ]; then |
| 157 | + echo "Validating YAML format: $yaml_file" |
| 158 | + yamllint "$yaml_file" || exit 1 |
| 159 | + fi |
| 160 | + done |
| 161 | + fi |
| 162 | +
|
| 163 | + # Test GitHub Actions workflows |
| 164 | + for workflow in .github/workflows/*.yaml; do |
| 165 | + if [ -f "$workflow" ]; then |
| 166 | + echo "Validating workflow: $workflow" |
| 167 | + yamllint "$workflow" || exit 1 |
| 168 | + fi |
| 169 | + done |
| 170 | +
|
| 171 | + echo "✅ All YAML files have valid format" |
| 172 | +
|
| 173 | + - name: Test Kubernetes manifest structure |
| 174 | + run: | |
| 175 | + # Basic structure validation without kubectl |
| 176 | + echo "Testing Kubernetes manifest structure..." |
| 177 | +
|
| 178 | + # Check if required files exist |
| 179 | + required_files=("k8s/namespace.yaml" \ |
| 180 | + "k8s/subgraphs-deployment-clusterip.yaml" \ |
| 181 | + "k8s/router-deployment-clusterip.yaml" \ |
| 182 | + "k8s/ingress.yaml") |
| 183 | +
|
| 184 | + for file in "${required_files[@]}"; do |
| 185 | + if [ ! -f "$file" ]; then |
| 186 | + echo "❌ Required Kubernetes manifest missing: $file" |
| 187 | + exit 1 |
| 188 | + fi |
| 189 | + echo "✅ Found: $file" |
| 190 | + done |
| 191 | +
|
| 192 | + # Check for basic Kubernetes resource types |
| 193 | + for file in k8s/*.yaml; do |
| 194 | + if [ -f "$file" ]; then |
| 195 | + echo "Checking $file for Kubernetes resource types..." |
| 196 | + if ! grep -q "kind:" "$file"; then |
| 197 | + echo "❌ No 'kind:' field found in $file" |
| 198 | + exit 1 |
| 199 | + fi |
| 200 | + if ! grep -q "apiVersion:" "$file"; then |
| 201 | + echo "❌ No 'apiVersion:' field found in $file" |
| 202 | + exit 1 |
| 203 | + fi |
| 204 | + fi |
| 205 | + done |
| 206 | +
|
| 207 | + echo "✅ All Kubernetes manifests have basic structure" |
0 commit comments