chore: cloudflare.yaml - environment aware setup #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Cloudflare | |
on: | |
push: | |
branches: | |
- production | |
- preview | |
- main | |
pull_request: | |
paths: | |
- 'libs/utils/**' | |
workflow_dispatch: | |
jobs: | |
www: | |
runs-on: ubuntu-latest | |
environment: | |
name: |- | |
${{ | |
github.ref_name == 'production' && 'sveltevietnam (Production)' | |
|| github.ref_name == 'preview' && 'sveltevietnam (Preview)' | |
|| 'sveltevietnam (Dev)' | |
}} | |
url: |- | |
${{ | |
github.ref_name == 'production' && 'https://sveltevietnam.dev' | |
|| github.ref_name == 'preview' && 'https://preview.sveltevietnam.dev' | |
|| steps.cloudflare-pages-deploy.outputs.url | |
}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- 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 | |
- name: Get pnpm cache | |
uses: actions/cache@v3 | |
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 --frozen-lockfile --ignore-scripts | |
continue-on-error: false | |
- name: Build | |
run: pnpm run build --filter=@sites/www | |
env: | |
# cloudflare turnstile | |
PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY: ${{ vars.PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY }} | |
CLOUDFLARE_TURNSTILE_SECRET_KEY: ${{ secrets.CLOUDFLARE_TURNSTILE_SECRET_KEY }} | |
# cookies | |
COOKIE_USER_ID: ${{ vars.COOKIE_USER_ID }} | |
PUBLIC_COOKIE_SCHEME: ${{ vars.PUBLIC_COOKIE_SCHEME }} | |
COOKIE_LANGUAGE: ${{ vars.COOKIE_LANGUAGE }} | |
# public env | |
PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID: ${{ vars.PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID }} | |
PUBLIC_DISCORD_WS_URL: ${{ vars.PUBLIC_DISCORD_WS_URL }} | |
PUBLIC_MODE: ${{ vars.PUBLIC_MODE }} | |
- name: Deploy to Cloudflare | |
id: cloudflare-pages-deploy | |
uses: cloudflare/pages-action@v1 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
projectName: sveltevietnam | |
directory: sites/www/.svelte-kit/cloudflare | |
# gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref_name }} | |
wranglerVersion: "3" | |
- name: Create commit comment | |
if: ${{ github.event_name == 'push' }} | |
uses: peter-evans/commit-comment@v2 | |
with: | |
body: | | |
## ⚡ Successfully Cloudflare Pages deployed! | |
| Name | Link | | |
| :--- | :--- | | |
| Latest commit | ${{ github.event.pull_request.head.sha || github.sha }} | | |
| Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | | |
| Deploy Preview Url | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | | |
| Environment | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | | |
- name: Create PR comment | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: mshick/add-pr-comment@v2 | |
with: | |
message: | | |
## ⚡ Successfully Cloudflare Pages deployed! | |
| Name | Link | | |
| :--- | :--- | | |
| Latest commit | ${{ github.event.pull_request.head.sha || github.sha }} | | |
| Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | | |
| Deploy Preview Url | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | | |
| Environment | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | |