Skip to content

Commit

Permalink
ci: Add Cloudflare deployment configuration on the development branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray-D-Song committed Oct 22, 2024
1 parent a90cf64 commit 1dce175
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Deploy

on:
push:
branches:
- showcase

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 Service
run: pnpm build:service

- 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 == "web-archive") | .uuid')
if [ -z "$DB_ID" ]; then
CREATE_OUTPUT=$(wrangler d1 create web-archive)
DB_ID=$(echo "$CREATE_OUTPUT" | sed -n 's/.*database_id = "\([^"]*\)".*/\1/p')
else
echo "Found existing web-archive database"
fi
echo "Database ID: $DB_ID"
echo "DB_ID=$DB_ID" >> $GITHUB_ENV
- name: update wrangler.toml
run: |
cd dist/service
sed -i 's/database_id = ".*"/database_id = "'$DB_ID'"/' wrangler.toml
- name: Apply D1 Migrations
run: |
cd dist/service
wrangler d1 migrations apply web-archive --remote
rm -rf ./src/sql
- name: Check and Create R2 Bucket
run: |
BUCKET_LIST=$(wrangler r2 bucket list)
if echo "$BUCKET_LIST" | grep -q "web-archive"; then
echo "Bucket already exists"
else
echo "Creating new bucket"
wrangler r2 bucket create web-archive
fi
- name: Create Pages project if not exists
run: |
if ! wrangler pages project list | grep -q "web-archive"; then
wrangler pages project create web-archive --production-branch=main
fi
- name: Deploy
run: |
cd dist/service
wrangler pages deploy --project-name=web-archive --branch=${{ github.ref_name }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

0 comments on commit 1dce175

Please sign in to comment.