From c12ceffd08954ae25cd6056d80eafcdde4a380fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Xalambr=C3=AD?= Date: Fri, 15 Nov 2024 20:23:30 -0500 Subject: [PATCH] Update GHA workflows, move migrations to db/migrations and update wrangler config --- .github/workflows/ci.yml | 62 +++++++++++-------- .github/workflows/deploy.yml | 44 ++++++++----- .../migrations}/0000_CreateTables.sql | 0 wrangler.toml | 22 +++---- 4 files changed, 73 insertions(+), 55 deletions(-) rename {migrations => db/migrations}/0000_CreateTables.sql (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21f3a8bc..49ef7753 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,44 +1,54 @@ name: CI -on: [push] +# We run CI on every push +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize] -jobs: - build: - name: Build - runs-on: ubuntu-latest - timeout-minutes: 1 - steps: - - uses: actions/checkout@v3 - - uses: oven-sh/setup-bun@v1 - - run: bun install - - run: bun run build +# Automatically cancel running workflows when there's a new one +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +permissions: + contents: read + packages: read + +jobs: typecheck: name: Typechecker runs-on: ubuntu-latest - timeout-minutes: 1 steps: - - uses: actions/checkout@v3 - - uses: oven-sh/setup-bun@v1 - - run: bun install + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: bun install --frozen-lockfile + - run: bun run build + # - run: bun run rr:typegen - run: bun run typecheck - test: + tests: name: Tests runs-on: ubuntu-latest - timeout-minutes: 1 steps: - - uses: actions/checkout@v3 - - uses: oven-sh/setup-bun@v1 - - run: bun install - - run: bun run test:coverage + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install --frozen-lockfile + - run: bun run test quality: name: Code Quality runs-on: ubuntu-latest - timeout-minutes: 1 steps: - - uses: actions/checkout@v3 - - uses: oven-sh/setup-bun@v1 - - run: bun install - - run: bun run check + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install --frozen-lockfile + - run: bun run quality diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d36885aa..0e6e1089 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,25 +1,35 @@ name: Deploy -on: [push, workflow_dispatch] +on: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }} + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +permissions: + contents: read + deployments: write + packages: read jobs: - website: - name: Website + deploy: + name: "Deploy to Cloudflare Workers" + timeout-minutes: 10 runs-on: ubuntu-latest - permissions: - contents: read - deployments: write steps: - - uses: actions/checkout@v3 - - - uses: oven-sh/setup-bun@v1 - - run: bun install + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: bun install --frozen-lockfile - run: bun run build - - - uses: cloudflare/pages-action@v1 + - uses: cloudflare/wrangler-action@v3 with: - apiToken: ${{ secrets.CF_API_TOKEN }} - accountId: ${{ secrets.CF_ACCOUNT_ID }} - projectName: sergiodxa - directory: public - gitHubToken: ${{ secrets.GITHUB_TOKEN }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + preCommands: | + bun run db:migrate ${{ secrets.CLOUDFLARE_DATABASE_NAME }} --remote diff --git a/migrations/0000_CreateTables.sql b/db/migrations/0000_CreateTables.sql similarity index 100% rename from migrations/0000_CreateTables.sql rename to db/migrations/0000_CreateTables.sql diff --git a/wrangler.toml b/wrangler.toml index f41cab3b..824ecb7e 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,6 +1,13 @@ name = "sergiodxa" -compatibility_date = "2023-06-22" -node_compat = true + +# Update the compatibility date to the date you want to lock to +compatibility_date = "2024-10-11" + +# This is needed for AsyncLocalStorage to work +compatibility_flags = ["nodejs_compat_v2"] + +# Set the development port to be 3000 +dev.port = 3000 kv_namespaces = [ { binding = "cache", id = "597a3ce0108c42798aeac0044a566e31", preview_id = "cache" }, @@ -16,13 +23,4 @@ r2_buckets = [ binding = "DB" database_name = "db" database_id = "f6bb2533-9284-4427-83e6-ea12c6630026" - -# [[services]] -# binding = "SVG_GENERATOR" -# service = "svg-generator" -# environment = "production" - -# [[services]] -# binding = "SVG_TO_PNG" -# service = "svg-to-png" -# environment = "production" +migrations_dir = "./db/migrations"