Repository: NWACus/web
Pull request #119: .github: add workflows to run deployments
Author: login: stevekuznetsov
Created: 2025-04-16T01:49:08Z | Merged: 2025-04-16T14:11:58Z



Diff:
diff --git a/.github/workflows/cleanup.yaml b/.github/workflows/cleanup.yaml
new file mode 100644
index 000000000..09f4fc9b2
--- /dev/null
+++ b/.github/workflows/cleanup.yaml
@@ -0,0 +1,22 @@
+name: cleanup
+on:
+  delete:
+    branches-ignore:
+      - 'main'
+      - 'release'
+jobs:
+  cleanup:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Install Turso CLI
+        run: curl -sSfL https://get.tur.so/install.sh | bash
+        env:
+          TURSO_INSTALL_SKIP_SIGNUP: 'true'
+      - name: Delete preview database
+        run: |
+          ref="${{ github.head_ref }}"
+          name="payloadcms-preview-${ref//[^a-z0-9\-]/x}"
+          /home/runner/.turso/turso db destroy --yes "${name}"
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+# TODO: clean up Vercel deployment?
diff --git a/.github/workflows/development.yaml b/.github/workflows/development.yaml
new file mode 100644
index 000000000..ad56f3ab3
--- /dev/null
+++ b/.github/workflows/development.yaml
@@ -0,0 +1,81 @@
+name: development
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
+    branches:
+      - 'main'
+jobs:
+  Deploy-Production:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Install Turso CLI
+        run: curl -sSfL https://get.tur.so/install.sh | bash
+        env:
+          TURSO_INSTALL_SKIP_SIGNUP: 'true'
+      - name: Delete existing preview database
+        run: |
+          /home/runner/.turso/turso org switch nwac
+          if /home/runner/.turso/turso db show payloadcms-dev; then
+            /home/runner/.turso/turso db destroy payloadcms-dev --yes
+          fi
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: Create a new database for the preview
+        id: database
+        run: /home/runner/.turso/turso db create payloadcms-dev --wait
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: Record database connection URI and token
+        id: connection
+        run: |
+          echo "uri=$(/home/runner/.turso/turso db show payloadcms-dev --url)" >> "${GITHUB_OUTPUT}"
+          echo "token=$(/home/runner/.turso/turso db tokens create payloadcms-dev )" >> "${GITHUB_OUTPUT}"
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: 🏗 Setup repo
+        uses: actions/checkout@v4
+      - name: 🏗 Setup pnpm
+        uses: pnpm/action-setup@v4
+      - name: 🏗 Setup Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
+          cache: pnpm
+      - name: 📦 Install dependencies
+        run: pnpm ii
+        shell: bash
+      - name: Install Vercel CLI
+        run: npm install --global vercel@latest
+      - name: Pull Vercel Environment Information
+        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update database URI in Vercel
+        run: vercel env add DATABASE_URI preview main --sensitive --force <<<"${{ steps.connection.outputs.uri }}"
+      - name: Update database token in Vercel
+        run: vercel env add DATABASE_AUTH_TOKEN preview "${{ github.head_ref }}" --sensitive --force <<<"${{ steps.connection.outputs.token }}" --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update bootstrap password in Vercel
+        run: vercel env add PAYLOAD_SEED_PASSWORD preview main --sensitive --force <<<"${{ secrets.PAYLOAD_SEED_PASSWORD }}"
+      - name: Seed the database
+        run: ./seed-build.sh
+        env:
+          SKIP_BUILD: 'true'
+          DATABASE_URI: '${{ steps.connection.outputs.uri }}'
+          DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
+          PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
+          PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
+          GOOGLE_MAPS_API_KEY: '${{ secrets.GOOGLE_MAPS_API_KEY }}'
+          VERCEL_BLOB_READ_WRITE_TOKEN: '${{ secrets.VERCEL_BLOB_READ_WRITE_TOKEN }}'
+      - name: Build Project Artifacts
+        run: vercel build --yes --target=preview --token=${{ secrets.VERCEL_TOKEN }}
+        env:
+          DATABASE_URI: '${{ steps.connection.outputs.uri }}'
+          DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
+          PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
+          PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
+          GOOGLE_MAPS_API_KEY: '${{ secrets.GOOGLE_MAPS_API_KEY }}'
+          VERCEL_BLOB_READ_WRITE_TOKEN: '${{ secrets.VERCEL_BLOB_READ_WRITE_TOKEN }}'
+      - name: Deploy Project Artifacts to Vercel
+        id: deployment
+        run: |
+          vercel deploy --yes --prebuilt --target=preview --token=${{ secrets.VERCEL_TOKEN }}
diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml
new file mode 100644
index 000000000..3ddc38c32
--- /dev/null
+++ b/.github/workflows/preview.yaml
@@ -0,0 +1,82 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  pull_request:
+    types:
+      - opened
+      - synchronize
+jobs:
+  deploy:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Install Turso CLI
+        run: curl -sSfL https://get.tur.so/install.sh | bash
+        env:
+          TURSO_INSTALL_SKIP_SIGNUP: 'true'
+      - name: Create a new database for the preview
+        id: database
+        run: |
+          ref="${{ github.head_ref }}"
+          name="payloadcms-preview-${ref//[^a-z0-9\-]/x}"
+          /home/runner/.turso/turso org switch nwac
+          if /home/runner/.turso/turso db show "${name}"; then
+            /home/runner/.turso/turso db destroy "${name}" --yes
+          fi
+          /home/runner/.turso/turso db create "${name}" --wait
+          echo "name=${name}" >> "${GITHUB_OUTPUT}"
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: Record database connection URI and token
+        id: connection
+        run: |
+          echo "uri=$(/home/runner/.turso/turso db show "${{ steps.database.outputs.name }}" --url)" >> "${GITHUB_OUTPUT}"
+          echo "token=$(/home/runner/.turso/turso db tokens create "${{ steps.database.outputs.name }}")" >> "${GITHUB_OUTPUT}"
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: 🏗 Setup repo
+        uses: actions/checkout@v4
+      - name: 🏗 Setup pnpm
+        uses: pnpm/action-setup@v4
+      - name: 🏗 Setup Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
+          cache: pnpm
+      - name: 📦 Install dependencies
+        run: pnpm ii
+        shell: bash
+      - name: Install Vercel CLI
+        run: npm install --global vercel@latest
+      - name: Pull Vercel Environment Information
+        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update database URI in Vercel
+        run: vercel env add DATABASE_URI preview "${{ github.head_ref }}" --sensitive --force <<<"${{ steps.connection.outputs.uri }}" --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update database token in Vercel
+        run: vercel env add DATABASE_AUTH_TOKEN preview "${{ github.head_ref }}" --sensitive --force <<<"${{ steps.connection.outputs.token }}" --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update bootstrap password in Vercel
+        run: vercel env add PAYLOAD_SEED_PASSWORD preview "${{ github.head_ref }}" --sensitive --force <<<"${{ secrets.PAYLOAD_SEED_PASSWORD }}" --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Seed the database
+        run: ./seed-build.sh
+        env:
+          SKIP_BUILD: 'true'
+          DATABASE_URI: '${{ steps.connection.outputs.uri }}'
+          DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
+          PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
+          PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
+          GOOGLE_MAPS_API_KEY: '${{ secrets.GOOGLE_MAPS_API_KEY }}'
+          VERCEL_BLOB_READ_WRITE_TOKEN: '${{ secrets.VERCEL_BLOB_READ_WRITE_TOKEN }}'
+      - name: Build Project Artifacts
+        run: vercel build --yes --target=preview --token=${{ secrets.VERCEL_TOKEN }}
+        env:
+          DATABASE_URI: '${{ steps.connection.outputs.uri }}'
+          DATABASE_AUTH_TOKEN: '${{ steps.connection.outputs.token }}'
+          PAYLOAD_SEED_PASSWORD: '${{ secrets.PAYLOAD_SEED_PASSWORD }}'
+          PAYLOAD_SECRET: '${{ secrets.PAYLOAD_SECRET }}'
+          GOOGLE_MAPS_API_KEY: '${{ secrets.GOOGLE_MAPS_API_KEY }}'
+          VERCEL_BLOB_READ_WRITE_TOKEN: '${{ secrets.VERCEL_BLOB_READ_WRITE_TOKEN }}'
+      - name: Deploy Project Artifacts to Vercel
+        id: deployment
+        run: |
+          vercel deploy --yes --prebuilt --target=preview --token=${{ secrets.VERCEL_TOKEN }}
diff --git a/seed-build.sh b/seed-build.sh
index 947881197..f00252c5b 100755
--- a/seed-build.sh
+++ b/seed-build.sh
@@ -36,5 +36,10 @@ set +o errexit
 cleanup
 set -o errexit
 
+if [[ -n "${SKIP_BUILD:-}" ]]; then
+  echo "[INFO] Skipping build..."
+  exit 0
+fi
+
 echo "[INFO] Running a production build using the seeded database..."
 pnpm build
diff --git a/src/Header/Component.tsx b/src/Header/Component.tsx
index 326c6961e..3913375cb 100644
--- a/src/Header/Component.tsx
+++ b/src/Header/Component.tsx
@@ -22,7 +22,7 @@ export async function Header({ center }: { center?: string }) {
     return <></>
   }
 
-  const nav = await payload.find({
+  const _nav = await payload.find({
     collection: 'navigations',
     depth: 1000,
     draft,


Reviews:
user: login: busbyk
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T02:10:40Z
user: login: stevekuznetsov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T02:15:47Z
user: login: stevekuznetsov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T02:16:14Z
user: login: busbyk
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T02:21:35Z
user: login: stevekuznetsov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T02:22:06Z
user: login: busbyk
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T02:22:30Z
user: login: stevekuznetsov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T02:32:02Z

Review comments:
path: .github/workflows/development.yaml
user: login: busbyk
body: Wouldn't this be the production deploy? Should we name this `production.yaml`?
created_at: 2025-04-16T02:07:36Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,21 @@
+name: cleanup
+on:
+  delete:
+    branches-ignore:
+      - 'main'
+      - 'preview'
+      - 'release'
+jobs:
+  Deploy-Production:
path: .github/workflows/cleanup.yaml
user: login: busbyk
body: Should we name this `cleanup`?
created_at: 2025-04-16T02:08:53Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,59 @@
+name: development
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
+    branches:
+      - 'main'
+jobs:
+  Deploy-Production:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Install Turso CLI
+        run: curl -sSfL https://get.tur.so/install.sh | bash
+      - name: Delete existing preview database
+        run: turso db destroy --yes payloadcms-dev
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: Create a new database for the preview
+        id: database
+        run: turso db create payloadcms-dev --wait
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: Record database connection URI
+        id: connection
+        run: echo "uri=$(turso db show payloadcms-dev --url)" >> "${GITHUB_OUTPUT}"
+        env:
+          TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }}
+      - name: 🏗 Setup repo
+        uses: actions/checkout@v4
+      - name: 🏗 Setup pnpm
+        uses: pnpm/action-setup@v4
+      - name: 🏗 Setup Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
+          cache: pnpm
+      - name: 📦 Install dependencies
+        run: pnpm ii
+        shell: bash
+      - name: Install Vercel CLI
+        run: npm install --global vercel@latest
+      - name: Pull Vercel Environment Information
+        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Update database URI in Vercel
+        run: vercel env add DATABASE_URI preview main --sensitive <<<"${{ steps.connection.outputs.uri }}"
+      - name: Update bootstrap password in Vercel
+        run: vercel env add PAYLOAD_SEED_PASSWORD preview main --sensitive <<<"${{ secrets.PAYLOAD_SEED_PASSWORD }}"
+      - name: Build Project Artifacts
+        run: vercel build --yes --target=preview --token=${{ secrets.VERCEL_TOKEN }}
+      - name: Deploy Project Artifacts to Vercel
path: .github/workflows/development.yaml
user: login: busbyk
body: Nicee
created_at: 2025-04-16T02:09:17Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
+    branches:
+      - '*'
+      - '**'
+      - '*/*'
+    branches-ignore:
+      - 'main'
+      - 'preview'
+      - 'release'
path: .github/workflows/preview.yaml
user: login: busbyk
body: Do we still care to ignore these?
created_at: 2025-04-16T02:09:37Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
path: .github/workflows/preview.yaml
user: login: busbyk
body: Do we want to run this on pushes or only on pull requests?
created_at: 2025-04-16T02:10:35Z
author_association: COLLABORATOR
path: .github/workflows/development.yaml
user: login: stevekuznetsov
body: `main` branch is our non-prod persistent deployment
created_at: 2025-04-16T02:15:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
path: .github/workflows/preview.yaml
user: login: stevekuznetsov
body: If you have a PR open and update the commits in it, I think it would be good to update the preview
created_at: 2025-04-16T02:16:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
path: .github/workflows/preview.yaml
user: login: busbyk
body: I've used this before to get that behavior:
```
on:
  pull_request:
    types: [opened, synchronize]
```

I'm just thinking that we don't want to be creating Turso dbs when pushing to feature branches that are in progress 🤷 
created_at: 2025-04-16T02:21:35Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
path: .github/workflows/preview.yaml
user: login: stevekuznetsov
body: (& it was not obvious if the `pull_request` [type](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request) supported update actions)
created_at: 2025-04-16T02:22:06Z
author_association: CONTRIBUTOR
path: .github/workflows/development.yaml
user: login: busbyk
body: Ahh the intent is to have `release` as production still? 
created_at: 2025-04-16T02:22:30Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,65 @@
+name: preview
+env:
+  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
+  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+on:
+  push:
path: .github/workflows/preview.yaml
user: login: stevekuznetsov
body: Ah, `synchronize` - will update this in the morning, thanks.
created_at: 2025-04-16T02:32:01Z
author_association: CONTRIBUTOR

PR comments:
user: login: stevekuznetsov
created_at: 2025-04-16T12:26:07Z
body: @busbyk hope it's ok - going to iterate this morning while nobody's around & pull this in
author_association: CONTRIBUTOR
user: login: stevekuznetsov
created_at: 2025-04-16T12:36:54Z
body: Well, looks like making it run on pull request events makes it run on _this_ pull request, which is nice!
author_association: CONTRIBUTOR
user: login: stevekuznetsov
created_at: 2025-04-16T12:46:37Z
body: ```
> cross-env NODE_OPTIONS=--no-deprecation next build
   ▲ Next.js 15.2.4
   Creating an optimized production build ...
 ✓ Compiled successfully
   Linting and checking validity of types ...
./src/Header/Component.tsx
25:9  Warning: 'nav' is assigned a value but never used. Allowed unused vars must match /^_/u.  @typescript-eslint/no-unused-vars
info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/app/api-reference/config/eslint#disabling-rules
```

Wild, we run `eslint` in CI already - why didn't this get caught?
author_association: CONTRIBUTOR
user: login: stevekuznetsov
created_at: 2025-04-16T13:48:28Z
body: Deployment worked, but:

1. /admin gets a 500
2. links on the home page are for localhost
3. we're still under `avy-*-nwac.vercel.app`, likely want something like `unique-id.preview.avy-fx.org`
author_association: CONTRIBUTOR
user: login: stevekuznetsov
created_at: 2025-04-16T14:08:02Z
body: I'm going to merge this in to see what the actual deployment looks like on avy-fx.org
author_association: CONTRIBUTOR