name: Integration Test on: workflow_run: workflows: [CI] types: [completed] branches: [main] workflow_dispatch: inputs: image_sha: description: 'Image SHA to test (defaults to latest on main)' required: false env: REGISTRY: forgejo.riotpiao.com IMAGE: forgejo.riotpiao.com/riotpiao-poimen/poimen-memory NAMESPACE: poimen jobs: integration-test: name: K8s Integration Test runs-on: rust if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' steps: - name: Checkout code uses: actions/checkout@v4 - name: Get image SHA id: image run: | if [ -n "${{ github.event.inputs.image_sha }}" ]; then SHA="${{ github.event.inputs.image_sha }}" else SHA="$(git rev-parse --short HEAD)" fi echo "sha=$SHA" >> $GITHUB_OUTPUT echo "Image SHA: $SHA" - name: Install kubectl run: | apt-get update apt-get install -y kubectl postgresql-client - name: Setup kubeconfig run: | mkdir -p ~/.kube echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > ~/.kube/config chmod 600 ~/.kube/config # Verify cluster access kubectl cluster-info kubectl get nodes - name: Verify image exists in registry run: | IMAGE="${{ env.IMAGE }}:${{ steps.image.outputs.sha }}" echo "Checking if image exists: $IMAGE" # Use registry API to verify image exists if docker pull "$IMAGE" 2>/dev/null; then echo "✓ Image found in registry" else echo "✗ Image not found" exit 1 fi env: DOCKER_CONFIG: /tmp/docker continue-on-error: true - name: Apply integration test Job run: | IMAGE_SHA="${{ steps.image.outputs.sha }}" echo "Creating integration test Job with image: $IMAGE_SHA" echo "" # Substitute image SHA in manifest cat k8s/test/integration-test-job.yaml | \ sed "s|IMAGE_SHA|$IMAGE_SHA|g" | \ kubectl apply -f - -n ${{ env.NAMESPACE }} echo "✓ Job submitted" echo "" # Wait for job to complete kubectl wait --for=condition=complete job/poimen-memory-integration-test \ -n ${{ env.NAMESPACE }} \ --timeout=600s || { echo "" echo "✗ Job did not complete in time" echo "" echo "Pod logs:" kubectl logs -l test=integration -n ${{ env.NAMESPACE }} --all-containers=true --tail=100 exit 1 } - name: Collect test results if: always() run: | echo "==========================================" echo "Integration Test Results" echo "==========================================" echo "" echo "Job status:" kubectl describe job poimen-memory-integration-test -n ${{ env.NAMESPACE }} | tail -20 echo "" echo "Pod logs:" kubectl logs -l test=integration -n ${{ env.NAMESPACE }} --all-containers=true || true echo "" # Get job status STATUS=$(kubectl get job poimen-memory-integration-test \ -n ${{ env.NAMESPACE }} \ -o jsonpath='{.status.succeeded}') if [ "$STATUS" = "1" ]; then echo "✓ Integration test PASSED" exit 0 else echo "✗ Integration test FAILED" exit 1 fi - name: Cleanup test Job if: always() run: | echo "Cleaning up test resources..." kubectl delete job poimen-memory-integration-test \ -n ${{ env.NAMESPACE }} \ --ignore-not-found=true echo "✓ Cleanup complete"