|
| 1 | +stages: |
| 2 | + - test |
| 3 | + |
| 4 | +cli:smoke:test: |
| 5 | + stage: test |
| 6 | + image: alpine:3.20 |
| 7 | + variables: |
| 8 | + GIT_STRATEGY: fetch |
| 9 | + before_script: |
| 10 | + - apk add --no-cache bash curl git docker-cli docker-compose |
| 11 | + script: |
| 12 | + - bash -n ./postgres_ai |
| 13 | + - | |
| 14 | + set -euo pipefail |
| 15 | + out=$(./postgres_ai help | tr -d "\r") |
| 16 | + echo "$out" | grep -q "Postgres AI CLI" |
| 17 | + echo "$out" | grep -q "COMMANDS:" |
| 18 | + rules: |
| 19 | + - if: '$CI_COMMIT_BRANCH' |
| 20 | + |
| 21 | +cli:e2e:dind: |
| 22 | + stage: test |
| 23 | + image: alpine:3.20 |
| 24 | + services: |
| 25 | + - name: docker:24-dind |
| 26 | + command: ["--tls=false"] |
| 27 | + variables: |
| 28 | + DOCKER_HOST: tcp://docker:2375 |
| 29 | + DOCKER_TLS_CERTDIR: "" |
| 30 | + GIT_STRATEGY: fetch |
| 31 | + before_script: |
| 32 | + - apk add --no-cache bash curl git coreutils docker-cli docker-compose openssl |
| 33 | + - docker version |
| 34 | + script: |
| 35 | + - set -euo pipefail |
| 36 | + - bash -n ./postgres_ai |
| 37 | + - ./postgres_ai check || true |
| 38 | + - ./postgres_ai quickstart --demo -y |
| 39 | + - timeout 60 ./postgres_ai status |
| 40 | + - timeout 10 ./postgres_ai logs grafana || true |
| 41 | + - ./postgres_ai config |
| 42 | + - ./postgres_ai update-config |
| 43 | + - ./postgres_ai list-instances || true |
| 44 | + - ./postgres_ai add-key "test_key_123" |
| 45 | + - ./postgres_ai show-key |
| 46 | + - ./postgres_ai remove-key |
| 47 | + - ./postgres_ai generate-grafana-password || true |
| 48 | + - ./postgres_ai show-grafana-credentials || true |
| 49 | + - ./postgres_ai add-instance "postgresql://postgres:postgres@target-db:5432/target_database" "ci-demo" |
| 50 | + - ./postgres_ai test-instance "ci-demo" || true |
| 51 | + - printf "y\n" | ./postgres_ai reset sink-postgres |
| 52 | + - ./postgres_ai restart |
| 53 | + - ./postgres_ai stop |
| 54 | + - ./postgres_ai start |
| 55 | + - printf "y\n" | ./postgres_ai reset |
| 56 | + - ./postgres_ai clean |
| 57 | + after_script: |
| 58 | + - docker ps -a || true |
| 59 | + - docker system prune -af || true |
| 60 | + rules: |
| 61 | + - if: '$CI_COMMIT_BRANCH' |
| 62 | +cli:node:smoke: |
| 63 | + stage: test |
| 64 | + image: node:20-alpine |
| 65 | + variables: |
| 66 | + GIT_STRATEGY: fetch |
| 67 | + before_script: |
| 68 | + - corepack enable || true |
| 69 | + script: |
| 70 | + - node -v && npm -v |
| 71 | + - npm --prefix cli install --no-audit --no-fund |
| 72 | + - node ./cli/dist/bin/postgres-ai.js --help |
| 73 | + - node ./cli/dist/bin/postgres-ai.js mon status --help |
| 74 | + - node ./cli/dist/bin/postgres-ai.js mon targets list --help |
| 75 | + - npm install -g ./cli |
| 76 | + - echo "prefix=$(npm config get prefix)" && echo "PATH=$PATH" |
| 77 | + - command -v postgres-ai && postgres-ai --help |
| 78 | + - command -v pgai && pgai --help |
| 79 | + - rm -f .pgwatch-config |
| 80 | + - node ./cli/dist/bin/postgres-ai.js add-key "test_key_1234567890" |
| 81 | + - node ./cli/dist/bin/postgres-ai.js show-key | grep -E "\*{2,}|[0-9]{4}$" |
| 82 | + - test -f ~/.config/postgresai/config.json |
| 83 | + - grep -q 'test_key' ~/.config/postgresai/config.json |
| 84 | + - node ./cli/dist/bin/postgres-ai.js remove-key |
| 85 | + - if grep -q 'apiKey' ~/.config/postgresai/config.json; then echo 'key not removed' && exit 1; fi |
| 86 | + - node ./cli/dist/bin/postgres-ai.js mon targets list | head -n 1 || true |
| 87 | + - node ./cli/dist/bin/postgres-ai.js mon targets add 'postgresql://user:pass@host:5432/db' ci-test || true |
| 88 | + - node ./cli/dist/bin/postgres-ai.js mon targets remove ci-test || true |
| 89 | + rules: |
| 90 | + - if: '$CI_COMMIT_BRANCH' |
| 91 | + |
| 92 | +cli:node:e2e:dind: |
| 93 | + stage: test |
| 94 | + image: node:20-alpine |
| 95 | + services: |
| 96 | + - name: docker:24-dind |
| 97 | + command: ["--tls=false"] |
| 98 | + variables: |
| 99 | + DOCKER_HOST: tcp://docker:2375 |
| 100 | + DOCKER_TLS_CERTDIR: "" |
| 101 | + GIT_STRATEGY: fetch |
| 102 | + before_script: |
| 103 | + - corepack enable || true |
| 104 | + - apk add --no-cache bash docker-cli docker-compose openssl postgresql-client |
| 105 | + - node -v && npm -v && docker version |
| 106 | + - npm --prefix cli install --no-audit --no-fund |
| 107 | + script: |
| 108 | + - ./tests/e2e.cli.sh |
| 109 | + after_script: |
| 110 | + - docker ps -a || true |
| 111 | + rules: |
| 112 | + - if: '$CI_COMMIT_BRANCH' |
| 113 | + |
| 114 | +cli:node:full:dind: |
| 115 | + stage: test |
| 116 | + image: node:20-alpine |
| 117 | + services: |
| 118 | + - name: docker:24-dind |
| 119 | + command: ["--tls=false"] |
| 120 | + variables: |
| 121 | + DOCKER_HOST: tcp://docker:2375 |
| 122 | + DOCKER_TLS_CERTDIR: "" |
| 123 | + GIT_STRATEGY: fetch |
| 124 | + before_script: |
| 125 | + - corepack enable || true |
| 126 | + - apk add --no-cache bash git docker-cli docker-compose openssl postgresql-client |
| 127 | + - node -v && npm -v && docker version |
| 128 | + - npm --prefix cli install --no-audit --no-fund |
| 129 | + script: |
| 130 | + - echo "=== Testing quickstart (demo mode) ===" |
| 131 | + - node ./cli/dist/bin/postgres-ai.js mon quickstart --demo |
| 132 | + - sleep 10 |
| 133 | + - node ./cli/dist/bin/postgres-ai.js mon status |
| 134 | + - echo "" |
| 135 | + - echo "=== Testing shell command ===" |
| 136 | + - echo "SELECT 1;" | node ./cli/dist/bin/postgres-ai.js mon shell target-db || true |
| 137 | + - echo "" |
| 138 | + - echo "=== Testing complete workflow ===" |
| 139 | + - node ./cli/dist/bin/postgres-ai.js mon targets add "postgresql://monitor:monitor_pass@target-db:5432/target_database" demo-test |
| 140 | + - node ./cli/dist/bin/postgres-ai.js mon targets list |
| 141 | + - node ./cli/dist/bin/postgres-ai.js mon targets test demo-test || true |
| 142 | + - node ./cli/dist/bin/postgres-ai.js mon health --wait 120 |
| 143 | + - node ./cli/dist/bin/postgres-ai.js mon show-grafana-credentials |
| 144 | + - echo "" |
| 145 | + - echo "=== Cleanup ===" |
| 146 | + - node ./cli/dist/bin/postgres-ai.js mon stop |
| 147 | + - node ./cli/dist/bin/postgres-ai.js mon clean || true |
| 148 | + after_script: |
| 149 | + - docker ps -a || true |
| 150 | + rules: |
| 151 | + - if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^feature\//' |
| 152 | + allow_failure: false |
| 153 | + |
| 154 | +cli:node:integration: |
| 155 | + stage: test |
| 156 | + image: node:20-alpine |
| 157 | + variables: |
| 158 | + GIT_STRATEGY: fetch |
| 159 | + before_script: |
| 160 | + - corepack enable || true |
| 161 | + - node -v && npm -v |
| 162 | + - npm --prefix cli install --no-audit --no-fund |
| 163 | + script: |
| 164 | + - | |
| 165 | + set -euo pipefail |
| 166 | + : "${PGAI_API_KEY:?PGAI_API_KEY is required for integration tests}" |
| 167 | + BASE_URL="${PGAI_BASE_URL:-https://v2.postgres.ai/api/general/}" |
| 168 | + echo "Using BASE_URL=$BASE_URL" |
| 169 | + # Placeholder: run CLI help until API-backed commands are implemented |
| 170 | + node ./cli/dist/bin/postgres-ai.js --help |
| 171 | + rules: |
| 172 | + - if: '$PGAI_API_KEY' |
| 173 | + |
| 174 | + |
0 commit comments