Skip to content

Commit

Permalink
Merge pull request #8 from kimitrii/kimitri
Browse files Browse the repository at this point in the history
Refactor GitHub Actions to Run Tests Using cloudflare/wrangler-action@v3 and Remove wrangler.toml
  • Loading branch information
kimitrii authored Nov 25, 2024
2 parents 7728510 + d0fe671 commit 8bd12f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 59 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/deploy-cloudflare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
14 changes: 7 additions & 7 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- name: Run tests using Cloudflare CLI environment
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
preCommands: pnpm test
command: logout
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
.DS_Store

# cloudflare
wrangler.toml
45 changes: 25 additions & 20 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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']
}
}
}
}
}
})
10 changes: 0 additions & 10 deletions wrangler.toml

This file was deleted.

13 changes: 13 additions & 0 deletions wrangler.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Example Cloudflare Workers configuration
# This file is a template. Replace the placeholders with your actual configuration.

name = "<your-project-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 = "<your-database-name>" # Replace with the name of your D1 database
database_id = "<your-database-id>" # Replace with your actual D1 database ID
migrations_dir = "./src/migrations"

0 comments on commit 8bd12f9

Please sign in to comment.