Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Created January 7, 2024 07:18
Show Gist options
  • Save anhtuank7c/c45e50b59c90c651c8402efca5293e9b to your computer and use it in GitHub Desktop.
Save anhtuank7c/c45e50b59c90c651c8402efca5293e9b to your computer and use it in GitHub Desktop.
Github workflow for deploying Sveltekit app to Cloudflare Pages
# Deploy to Cloudflare Workers/Pages with Wrangler
# https://github.com/marketplace/actions/deploy-to-cloudflare-workers-with-wrangler
name: Deploy Pages
on:
push:
branches:
- main
pull_request:
jobs:
deploy:
# runs-on: ubuntu-latest
runs-on: self-hosted
timeout-minutes: 10
name: Deploy site to Cloudflare Pages
steps:
# checkout code
- name: Checkout
uses: actions/checkout@v3
# Install pnpm and cache dependencies
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
# Install and cache Playwright
# - name: Get installed Playwright version
# id: playwright-version
# run: echo "PLAYWRIGHT_VERSION=1.28.1" >> $GITHUB_ENV
# - name: Cache playwright binaries
# uses: actions/cache@v3
# id: playwright-cache
# with:
# # Change path below to match runs-on option from above
# # %USERPROFILE%\AppData\Local\ms-playwright Windows
# # ~/.cache/ms-playwright Linux
# # ~/Library/Caches/ms-playwright MacOS
# path: |
# ~/Library/Caches/ms-playwright
# key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
# - name: Install Playwright
# run: pnpm exec playwright install
# if: steps.playwright-cache.outputs.cache-hit != 'true'
# integration test & unit test
- name: Unit Test
run: pnpm run test:unit
# build site
- name: Build
run: pnpm run build
# deploy to cloudflare pages
- name: Deploy Pages to Production branch
uses: cloudflare/wrangler-action@v3
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy .svelte-kit/cloudflare --project-name=blog
- name: Deploy Pages to Preview branch
uses: cloudflare/wrangler-action@v3
if: ${{ contains(fromJson('"refs/heads/staging"]'), github.ref) && github.event_name == 'push' }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy .svelte-kit/cloudflare --project-name=blog --branch=preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment