From 7478fbca833b4bbc13b5c085a178f6d7e8011bd7 Mon Sep 17 00:00:00 2001 From: Emily Morgan Date: Wed, 22 Nov 2023 10:03:11 +0100 Subject: [PATCH] Add E2E CLI test (#1247) --- .github/workflows/build-pr.yml | 9 +- package.json | 2 + pnpm-lock.yaml | 271 ++++++++++++++++++++++++++++++++- scripts/test-canary.ts | 147 ++++++++++++++++++ 4 files changed, 425 insertions(+), 4 deletions(-) create mode 100644 scripts/test-canary.ts diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index bfefddc6b..7a70b83c5 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -157,6 +157,13 @@ jobs: ``` npx @xata.io/cli@${{ steps.version.outputs.TAG }} ``` + - name: Canary build E2E test + if: ${{ steps.secrets.outputs.exist == 'true' && github.event_name == 'pull_request' }} + run: pnpm run test:canary + env: + XATA_API_KEY: ${{ secrets.INTEGRATION_TEST_API_KEY }} + XATA_WORKSPACE: ${{ secrets.INTEGRATION_TEST_WORKSPACE }} + CANARY_VERSION: ${{ steps.version.outputs.TAG }} test: runs-on: ubuntu-latest @@ -204,7 +211,5 @@ jobs: run: | pnpm test env: - XATA_DATABASE_URL: ${{ secrets.INTEGRATION_TEST_DATABASE_URL }} XATA_API_KEY: ${{ secrets.INTEGRATION_TEST_API_KEY }} - XATA_BRANCH: ${{ secrets.INTEGRATION_TEST_BRANCH }} XATA_WORKSPACE: ${{ secrets.INTEGRATION_TEST_WORKSPACE }} diff --git a/package.json b/package.json index 8aa1b0607..ba6d460eb 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "test": "vitest", + "test:canary": "tsx ./scripts/test-canary.ts", "lint": "eslint .", "lint:fix": "eslint . --fix", "prepare": "husky install", @@ -65,6 +66,7 @@ "rollup-plugin-strip-code": "^0.2.7", "size-limit": "^11.0.0", "ts-node": "^10.9.1", + "tsx": "^4.0.0", "turbo": "^1.10.16", "typescript": "^5.2.2", "vite": "^5.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c21e4c62..082c9a171 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -121,6 +121,9 @@ importers: ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@20.9.2)(typescript@5.2.2) + tsx: + specifier: ^4.0.0 + version: 4.0.0 turbo: specifier: ^1.10.16 version: 1.10.16 @@ -2218,6 +2221,16 @@ packages: '@edge-runtime/primitives': 4.0.5 dev: false + /@esbuild/android-arm64@0.18.20: + resolution: + { integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ== } + engines: { node: '>=12' } + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm64@0.19.2: resolution: { integrity: sha512-lsB65vAbe90I/Qe10OjkmrdxSX4UJDjosDgb8sZUKcg3oefEuW2OT2Vozz8ef7wrJbMcmhvCC+hciF8jY/uAkw== } @@ -2237,6 +2250,16 @@ packages: requiresBuild: true optional: true + /@esbuild/android-arm@0.18.20: + resolution: + { integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw== } + engines: { node: '>=12' } + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm@0.19.2: resolution: { integrity: sha512-tM8yLeYVe7pRyAu9VMi/Q7aunpLwD139EY1S99xbQkT4/q2qa6eA4ige/WJQYdJ8GBL1K33pPFhPfPdJ/WzT8Q== } @@ -2256,6 +2279,16 @@ packages: requiresBuild: true optional: true + /@esbuild/android-x64@0.18.20: + resolution: + { integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg== } + engines: { node: '>=12' } + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-x64@0.19.2: resolution: { integrity: sha512-qK/TpmHt2M/Hg82WXHRc/W/2SGo/l1thtDHZWqFq7oi24AjZ4O/CpPSu6ZuYKFkEgmZlFoa7CooAyYmuvnaG8w== } @@ -2275,6 +2308,16 @@ packages: requiresBuild: true optional: true + /@esbuild/darwin-arm64@0.18.20: + resolution: + { integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA== } + engines: { node: '>=12' } + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-arm64@0.19.2: resolution: { integrity: sha512-Ora8JokrvrzEPEpZO18ZYXkH4asCdc1DLdcVy8TGf5eWtPO1Ie4WroEJzwI52ZGtpODy3+m0a2yEX9l+KUn0tA== } @@ -2294,6 +2337,16 @@ packages: requiresBuild: true optional: true + /@esbuild/darwin-x64@0.18.20: + resolution: + { integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ== } + engines: { node: '>=12' } + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-x64@0.19.2: resolution: { integrity: sha512-tP+B5UuIbbFMj2hQaUr6EALlHOIOmlLM2FK7jeFBobPy2ERdohI4Ka6ZFjZ1ZYsrHE/hZimGuU90jusRE0pwDw== } @@ -2313,6 +2366,16 @@ packages: requiresBuild: true optional: true + /@esbuild/freebsd-arm64@0.18.20: + resolution: + { integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw== } + engines: { node: '>=12' } + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-arm64@0.19.2: resolution: { integrity: sha512-YbPY2kc0acfzL1VPVK6EnAlig4f+l8xmq36OZkU0jzBVHcOTyQDhnKQaLzZudNJQyymd9OqQezeaBgkTGdTGeQ== } @@ -2332,6 +2395,16 @@ packages: requiresBuild: true optional: true + /@esbuild/freebsd-x64@0.18.20: + resolution: + { integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ== } + engines: { node: '>=12' } + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-x64@0.19.2: resolution: { integrity: sha512-nSO5uZT2clM6hosjWHAsS15hLrwCvIWx+b2e3lZ3MwbYSaXwvfO528OF+dLjas1g3bZonciivI8qKR/Hm7IWGw== } @@ -2351,6 +2424,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-arm64@0.18.20: + resolution: + { integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA== } + engines: { node: '>=12' } + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm64@0.19.2: resolution: { integrity: sha512-ig2P7GeG//zWlU0AggA3pV1h5gdix0MA3wgB+NsnBXViwiGgY77fuN9Wr5uoCrs2YzaYfogXgsWZbm+HGr09xg== } @@ -2370,6 +2453,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-arm@0.18.20: + resolution: + { integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg== } + engines: { node: '>=12' } + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm@0.19.2: resolution: { integrity: sha512-Odalh8hICg7SOD7XCj0YLpYCEc+6mkoq63UnExDCiRA2wXEmGlK5JVrW50vZR9Qz4qkvqnHcpH+OFEggO3PgTg== } @@ -2389,6 +2482,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-ia32@0.18.20: + resolution: + { integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA== } + engines: { node: '>=12' } + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ia32@0.19.2: resolution: { integrity: sha512-mLfp0ziRPOLSTek0Gd9T5B8AtzKAkoZE70fneiiyPlSnUKKI4lp+mGEnQXcQEHLJAcIYDPSyBvsUbKUG2ri/XQ== } @@ -2408,6 +2511,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-loong64@0.18.20: + resolution: + { integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg== } + engines: { node: '>=12' } + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-loong64@0.19.2: resolution: { integrity: sha512-hn28+JNDTxxCpnYjdDYVMNTR3SKavyLlCHHkufHV91fkewpIyQchS1d8wSbmXhs1fiYDpNww8KTFlJ1dHsxeSw== } @@ -2427,6 +2540,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-mips64el@0.18.20: + resolution: + { integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ== } + engines: { node: '>=12' } + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-mips64el@0.19.2: resolution: { integrity: sha512-KbXaC0Sejt7vD2fEgPoIKb6nxkfYW9OmFUK9XQE4//PvGIxNIfPk1NmlHmMg6f25x57rpmEFrn1OotASYIAaTg== } @@ -2446,6 +2569,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-ppc64@0.18.20: + resolution: + { integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA== } + engines: { node: '>=12' } + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ppc64@0.19.2: resolution: { integrity: sha512-dJ0kE8KTqbiHtA3Fc/zn7lCd7pqVr4JcT0JqOnbj4LLzYnp+7h8Qi4yjfq42ZlHfhOCM42rBh0EwHYLL6LEzcw== } @@ -2465,6 +2598,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-riscv64@0.18.20: + resolution: + { integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A== } + engines: { node: '>=12' } + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-riscv64@0.19.2: resolution: { integrity: sha512-7Z/jKNFufZ/bbu4INqqCN6DDlrmOTmdw6D0gH+6Y7auok2r02Ur661qPuXidPOJ+FSgbEeQnnAGgsVynfLuOEw== } @@ -2484,6 +2627,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-s390x@0.18.20: + resolution: + { integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ== } + engines: { node: '>=12' } + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-s390x@0.19.2: resolution: { integrity: sha512-U+RinR6aXXABFCcAY4gSlv4CL1oOVvSSCdseQmGO66H+XyuQGZIUdhG56SZaDJQcLmrSfRmx5XZOWyCJPRqS7g== } @@ -2503,6 +2656,16 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-x64@0.18.20: + resolution: + { integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w== } + engines: { node: '>=12' } + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-x64@0.19.2: resolution: { integrity: sha512-oxzHTEv6VPm3XXNaHPyUTTte+3wGv7qVQtqaZCrgstI16gCuhNOtBXLEBkBREP57YTd68P0VgDgG73jSD8bwXQ== } @@ -2522,6 +2685,16 @@ packages: requiresBuild: true optional: true + /@esbuild/netbsd-x64@0.18.20: + resolution: + { integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A== } + engines: { node: '>=12' } + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/netbsd-x64@0.19.2: resolution: { integrity: sha512-WNa5zZk1XpTTwMDompZmvQLHszDDDN7lYjEHCUmAGB83Bgs20EMs7ICD+oKeT6xt4phV4NDdSi/8OfjPbSbZfQ== } @@ -2541,6 +2714,16 @@ packages: requiresBuild: true optional: true + /@esbuild/openbsd-x64@0.18.20: + resolution: + { integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg== } + engines: { node: '>=12' } + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/openbsd-x64@0.19.2: resolution: { integrity: sha512-S6kI1aT3S++Dedb7vxIuUOb3oAxqxk2Rh5rOXOTYnzN8JzW1VzBd+IqPiSpgitu45042SYD3HCoEyhLKQcDFDw== } @@ -2560,6 +2743,16 @@ packages: requiresBuild: true optional: true + /@esbuild/sunos-x64@0.18.20: + resolution: + { integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ== } + engines: { node: '>=12' } + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /@esbuild/sunos-x64@0.19.2: resolution: { integrity: sha512-VXSSMsmb+Z8LbsQGcBMiM+fYObDNRm8p7tkUDMPG/g4fhFX5DEFmjxIEa3N8Zr96SjsJ1woAhF0DUnS3MF3ARw== } @@ -2579,6 +2772,16 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-arm64@0.18.20: + resolution: + { integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg== } + engines: { node: '>=12' } + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-arm64@0.19.2: resolution: { integrity: sha512-5NayUlSAyb5PQYFAU9x3bHdsqB88RC3aM9lKDAz4X1mo/EchMIT1Q+pSeBXNgkfNmRecLXA0O8xP+x8V+g/LKg== } @@ -2598,6 +2801,16 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-ia32@0.18.20: + resolution: + { integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g== } + engines: { node: '>=12' } + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-ia32@0.19.2: resolution: { integrity: sha512-47gL/ek1v36iN0wL9L4Q2MFdujR0poLZMJwhO2/N3gA89jgHp4MR8DKCmwYtGNksbfJb9JoTtbkoe6sDhg2QTA== } @@ -2617,6 +2830,16 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-x64@0.18.20: + resolution: + { integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ== } + engines: { node: '>=12' } + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-x64@0.19.2: resolution: { integrity: sha512-tcuhV7ncXBqbt/Ybf0IyrMcwVOAPDckMK9rXNHtF17UTK18OKLpg08glminN06pt2WCoALhXdLfSPbVvK/6fxw== } @@ -8477,6 +8700,37 @@ packages: { integrity: sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg== } dev: true + /esbuild@0.18.20: + resolution: + { integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA== } + engines: { node: '>=12' } + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/android-arm': 0.18.20 + '@esbuild/android-arm64': 0.18.20 + '@esbuild/android-x64': 0.18.20 + '@esbuild/darwin-arm64': 0.18.20 + '@esbuild/darwin-x64': 0.18.20 + '@esbuild/freebsd-arm64': 0.18.20 + '@esbuild/freebsd-x64': 0.18.20 + '@esbuild/linux-arm': 0.18.20 + '@esbuild/linux-arm64': 0.18.20 + '@esbuild/linux-ia32': 0.18.20 + '@esbuild/linux-loong64': 0.18.20 + '@esbuild/linux-mips64el': 0.18.20 + '@esbuild/linux-ppc64': 0.18.20 + '@esbuild/linux-riscv64': 0.18.20 + '@esbuild/linux-s390x': 0.18.20 + '@esbuild/linux-x64': 0.18.20 + '@esbuild/netbsd-x64': 0.18.20 + '@esbuild/openbsd-x64': 0.18.20 + '@esbuild/sunos-x64': 0.18.20 + '@esbuild/win32-arm64': 0.18.20 + '@esbuild/win32-ia32': 0.18.20 + '@esbuild/win32-x64': 0.18.20 + dev: true + /esbuild@0.19.2: resolution: { integrity: sha512-G6hPax8UbFakEj3hWO0Vs52LQ8k3lnBhxZWomUJDxfz3rZTLqF5k/FCzuNdLx2RbpBiQQF9H9onlDDH1lZsnjg== } @@ -10151,6 +10405,7 @@ packages: resolution: { integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== } engines: { node: '>=0.10.0' } + requiresBuild: true dependencies: safer-buffer: 2.1.2 dev: true @@ -12282,6 +12537,7 @@ packages: /nan@2.18.0: resolution: { integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w== } + requiresBuild: true dev: false optional: true @@ -15120,13 +15376,11 @@ packages: dependencies: buffer-from: 1.1.2 source-map: 0.6.1 - dev: false /source-map@0.6.1: resolution: { integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== } engines: { node: '>=0.10.0' } - dev: false /sourcemap-codec@1.4.8: resolution: @@ -15785,6 +16039,19 @@ packages: typescript: 5.2.2 dev: false + /tsx@4.0.0: + resolution: + { integrity: sha512-jd3C5kw9tR68gtvqHUYo/2IwxaA46/CyKvcVQ4DsKRAPb19/vWgl7zF9mYNjFRY6KcGKiwne41RU91ll31IggQ== } + engines: { node: '>=18.0.0' } + hasBin: true + dependencies: + esbuild: 0.18.20 + get-tsconfig: 4.7.2 + source-map-support: 0.5.21 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /tty-table@4.2.1: resolution: { integrity: sha512-xz0uKo+KakCQ+Dxj1D/tKn2FSyreSYWzdkL/BYhgN6oMW808g8QRMuh1atAV9fjTPbWBjfbkKQpI/5rEcnAc7g== } diff --git a/scripts/test-canary.ts b/scripts/test-canary.ts new file mode 100644 index 000000000..e8529cac9 --- /dev/null +++ b/scripts/test-canary.ts @@ -0,0 +1,147 @@ +import { exec as execRaw } from 'child_process'; +import { randomUUID } from 'crypto'; +import path from 'path'; +import * as util from 'util'; +const exec = util.promisify(execRaw); + +async function main() { + if (!process.env.CANARY_VERSION) throw new Error('CANARY_VERSION is not set'); + if (!process.env.XATA_WORKSPACE) throw new Error('XATA_WORKSPACE is not set'); + + console.log(`Running canary test for ${process.env.CANARY_VERSION}`); + + const cli = `@xata.io/cli@${process.env.CANARY_VERSION}`; + + const databaseName = `canary_${randomUUID()}`; + const region = process.env.XATA_REGION || 'us-east-1'; + const dir = path.join(__dirname, 'throwaway'); + const file = path.join(dir, 'test.ts'); + const schemaFile = path.join(dir, 'schema.json'); + + const schemaContent = `{ + "tables": [ + { + "name": "teams", + "columns": [ + { + "name": "name", + "type": "string" + } + ] + } + ] + }`; + + const fullyQualifiedEndpoint = `https://${process.env.XATA_WORKSPACE}.${region}.xata.sh/db/${databaseName}`; + + const makeDir = async () => { + await exec(`rm -rf ${dir}`); + const result = await exec(`mkdir ${dir}`); + if (result.stderr) { + throw new Error(`Failed to make dir: ${result.stderr}`); + } + console.log('Made dir', result.stdout); + }; + + const download = async (retry = 0) => { + try { + const result = await exec(`cd ${dir} && npm cache clean --force && npm install -g ${cli}`); + console.log('Downloaded npm package', result.stdout); + return result; + } catch (e) { + if (retry < 8) { + const nextTry = retry + 1; + console.log(`Could not download npm package, retrying... ${e}. Attempt: ${nextTry}`); + await new Promise((resolve) => setTimeout(resolve, 1000 * 10 * nextTry)); + await download(nextTry); + } + throw e; + } + }; + + const create = async () => { + const result = await exec( + `cd ${dir} && npx ${cli} dbs create ${databaseName} --workspace ${process.env.XATA_WORKSPACE} --region ${region}` + ); + if (result.stderr.includes('Error:')) { + throw new Error(`Failed to create database: ${result.stderr}`); + } + console.log('Created database', result.stdout); + }; + + const init = async () => { + const result = await exec(`cd ${dir} && npx ${cli} init --db ${fullyQualifiedEndpoint} --codegen ${file} --force`); + // Warnings go to stderr + if (result.stderr.includes('Error:')) { + throw new Error(`Failed to init: ${result.stderr}`); + } + console.log('Initialized database', result.stdout); + }; + + const schemaPull = async () => { + const result = await exec(`npx ${cli} pull main --no-input --db ${fullyQualifiedEndpoint} -f`); + if (result.stderr) { + throw new Error(`Failed to pull schema: ${result.stderr}`); + } + console.log('Pulled schema', result.stdout); + }; + + const schemaPush = async () => { + const result = await exec(`npx ${cli} push main --db ${fullyQualifiedEndpoint} -y`); + if (result.stderr) { + throw new Error(`Failed to push schema: ${result.stderr}`); + } + console.log('Pushed schema', result.stdout); + }; + + const schemaUpload = async () => { + await exec(`echo '${schemaContent}' > ${schemaFile}`); + const result = await exec(`npx ${cli} schema upload ${schemaFile} --db ${fullyQualifiedEndpoint} -b main -y`); + if (result.stderr) { + throw new Error(`Failed to upload schema: ${result.stderr}`); + } + console.log('Uploaded schema', result.stdout); + }; + + const createBranch = async () => { + const result = await exec(`npx ${cli} branch create tester --db ${fullyQualifiedEndpoint}`); + if (result.stderr) { + throw new Error(`Failed to create branch: ${result.stderr}`); + } + console.log('Created branch', result.stdout); + }; + + const deleteBranch = async () => { + const result = await exec(`npx ${cli} branch delete tester --db ${fullyQualifiedEndpoint} -f`); + if (result.stderr) { + throw new Error(`Failed to delete branch: ${result.stderr}`); + } + console.log('Deleted branch', result.stdout); + }; + + const deleteDatabase = async () => { + const result = await exec( + `cd ${dir} && npx ${cli} dbs delete ${databaseName} --no-input -f --workspace ${process.env.XATA_WORKSPACE}` + ); + if (result.stderr) { + throw new Error(`Failed to delete database: ${result.stderr}`); + } + console.log('Deleted database', result.stdout); + }; + + try { + await makeDir(); + await download(); + await create(); + await init(); + await schemaPull(); + await schemaPush(); + await schemaUpload(); + await createBranch(); + await deleteBranch(); + } finally { + await deleteDatabase(); + } +} + +main();