Skip to content

deploy_to_cf_workers #2

deploy_to_cf_workers

deploy_to_cf_workers #2

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
repository_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Install wrangler
run: npm install -g wrangler
- name: Verify Cloudflare API Token
run: |
echo "Verifying Cloudflare API Token..."
wrangler whoami
- name: Check and Create D1 Database
run: |
set -x
DB_LIST=$(wrangler d1 list --json)
DB_ID=$(echo $DB_LIST | jq -r '.[] | select(.name == "github-persona") | .uuid')
if [ -z "$DB_ID" ]; then
CREATE_OUTPUT=$(wrangler d1 create github-persona)
DB_ID=$(echo "$CREATE_OUTPUT" | sed -n 's/.*database_id = "\([^"]*\)".*/\1/p')
else
echo "Found existing github-persona database"
fi
echo "Database ID: $DB_ID"
echo "DB_ID=$DB_ID" >> $GITHUB_ENV
- name: update wrangler.toml database_id
run: |
sed -i 's/database_id = ".*"/database_id = "'$DB_ID'"/' wrangler.toml
- name: update wrangler.toml github_client_id
run: |
sed -i 's/GITHUB_CLIENT_ID = ".*"/GITHUB_CLIENT_ID = "'$GITHUB_CLIENT_ID'"/' wrangler.toml
- name: update wrangler.toml github_client_secret
run: |
sed -i 's/GITHUB_CLIENT_SECRET = ".*"/GITHUB_CLIENT_SECRET = "'$GITHUB_CLIENT_SECRET'"/' wrangler.toml
- name: Apply D1 Migrations
run: |
wrangler d1 migrations apply github-persona --remote
- name: Create Pages project if not exists
run: |
if ! wrangler pages project list | grep -q "github-persona"; then
wrangler pages project create github-persona --production-branch=main
fi
- name: Deploy
run: wrangler pages deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }}