From 39a3b7dec7389bb24a17117952798b2565c7e118 Mon Sep 17 00:00:00 2001 From: Kimitri Date: Mon, 25 Nov 2024 05:19:47 -0300 Subject: [PATCH 1/4] chore: add wrangler.toml to .gitignore --- .gitignore | 5 ++++- wrangler.toml | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 wrangler.toml diff --git a/.gitignore b/.gitignore index 1221f52..93a46f1 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ pnpm-debug.log* lerna-debug.log* # misc -.DS_Store \ No newline at end of file +.DS_Store + +# cloudflare +wrangler.toml \ No newline at end of file diff --git a/wrangler.toml b/wrangler.toml deleted file mode 100644 index fc8d8a7..0000000 --- a/wrangler.toml +++ /dev/null @@ -1,10 +0,0 @@ -name = "legion-backend" -main = "src/index.ts" -compatibility_date = "2024-11-20" -compatibility_flags = [ "nodejs_compat" ] - -[[d1_databases]] -binding = "DB" -database_name = "legion-db" -database_id = "2e03019b-39d6-4a9a-90de-90f8bd6282e2" -migrations_dir = "./src/migrations" \ No newline at end of file From 2e25671b11f0bc580609a45d436968291a9d3c10 Mon Sep 17 00:00:00 2001 From: Kimitri Date: Mon, 25 Nov 2024 05:22:31 -0300 Subject: [PATCH 2/4] chore: remove wrangler.toml from Vitest configuration --- vitest.config.ts | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index 670163a..3307164 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,23 +1,28 @@ -import { defineWorkersConfig, readD1Migrations } from "@cloudflare/vitest-pool-workers/config"; +import { + defineWorkersConfig, + readD1Migrations +} from '@cloudflare/vitest-pool-workers/config' export default defineWorkersConfig(async () => { - const migrations = await readD1Migrations("./src/migrations") - return { - test: { - globals: true, - poolOptions: { - workers: { - isolatedStorage: true, - miniflare: { - bindings: { - TEST_MIGRATIONS: migrations - } - }, - wrangler: { - configPath: "./wrangler.toml" - } - } - } - } - } + const migrations = await readD1Migrations('./src/migrations') + return { + test: { + globals: true, + poolOptions: { + workers: { + isolatedStorage: true, + miniflare: { + d1Databases: { + DB: 'db-tests' + }, + bindings: { + TEST_MIGRATIONS: migrations + }, + compatibilityDate: '2024-11-20', + compatibilityFlags: ['nodejs_compat'] + } + } + } + } + } }) From 72f259c69d6f4649f382d6ab010bdff1366344cd Mon Sep 17 00:00:00 2001 From: Kimitri Date: Mon, 25 Nov 2024 05:25:04 -0300 Subject: [PATCH 3/4] ci: update workflows to run tests using wrangler-action --- .github/workflows/deploy-cloudflare.yml | 25 ++++--------------------- .github/workflows/pr-tests.yml | 14 +++++++------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/.github/workflows/deploy-cloudflare.yml b/.github/workflows/deploy-cloudflare.yml index 6bd5042..56f63a2 100644 --- a/.github/workflows/deploy-cloudflare.yml +++ b/.github/workflows/deploy-cloudflare.yml @@ -5,28 +5,9 @@ on: branches: - main jobs: - test: - name: Run tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: git fetch --prune --unshallow --tags - - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - version: 9 - - - name: Install dependencies - run: pnpm install - - - name: Run all tests - run: pnpm run test - deploy: name: Deploy to Cloudflare Workers runs-on: ubuntu-latest - needs: ["test"] steps: - uses: actions/checkout@v4 @@ -35,9 +16,11 @@ jobs: with: version: 9 - - name: Run Migrations and Deploy + - name: Run Tests, Migrations and Deploy using Cloudflare CLI environment uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - preCommands: pnpm migration:prod + preCommands: | + pnpm test + pnpm migration:prod \ No newline at end of file diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 002b9c8..3d7afac 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -6,19 +6,19 @@ on: - main jobs: test: - name: Run tests + name: Run Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: git fetch --prune --unshallow --tags - name: Install pnpm uses: pnpm/action-setup@v4 with: version: 9 - - name: Install dependencies - run: pnpm install - - - name: Run all tests - run: pnpm run test \ No newline at end of file + - name: Run tests using Cloudflare CLI environment + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + preCommands: pnpm test + command: logout From d0fe6714443193c4af9a757c651b7b85607b800d Mon Sep 17 00:00:00 2001 From: Kimitri Date: Mon, 25 Nov 2024 05:37:32 -0300 Subject: [PATCH 4/4] docs: add example wrangler.toml file with placeholders --- wrangler.toml.example | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 wrangler.toml.example diff --git a/wrangler.toml.example b/wrangler.toml.example new file mode 100644 index 0000000..3a5528a --- /dev/null +++ b/wrangler.toml.example @@ -0,0 +1,13 @@ +# Example Cloudflare Workers configuration +# This file is a template. Replace the placeholders with your actual configuration. + +name = "" # Replace with your project name +main = "src/index.ts" +compatibility_date = "2024-11-20" +compatibility_flags = [ "nodejs_compat" ] + +[[d1_databases]] +binding = "DB" +database_name = "" # Replace with the name of your D1 database +database_id = "" # Replace with your actual D1 database ID +migrations_dir = "./src/migrations"