Skip to content

CD(Feature Branch) - push #223

CD(Feature Branch) - push

CD(Feature Branch) - push #223

name: CD(Feature Branch)
run-name: CD(Feature Branch) - ${{ github.event_name }}
on:
push:
workflow_dispatch:
env:
PROJECT_NAME: ${{ vars.PROD_CLOUDFLARE_PROJECT_NAME }}
PRODUCTION_BRANCH: main
jobs:
build_and_deploy:
if: |
(github.event_name == 'push' && ((github.head_ref || github.ref_name) != 'main' )) ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
- name: Symlink
run: |
mkdir -p /home/runner/work/${{ github.event.repository.name }}/
ln -s ${{ github.workspace }} /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
check-latest: true
- name: cache
uses: actions/cache@v4
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
~/.npm
/home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/.next/cache
node_modules
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
- run: npm install
- name: build (branch preview)
if: ${{ ((github.head_ref || github.ref_name) != env.PRODUCTION_BRANCH) }}
id: build-preview
run: npx @cloudflare/next-on-pages@1
env:
NEXT_PUBLIC_API_ENDPOINT: ${{vars.DEV_API_ENDPOINT}}
NEXT_PUBLIC_FIREBASE_API_KEY: ${{vars.DEV_FIREBASE_API_KEY}}
NEXT_PUBLIC_FIREBASE_APP_ID: ${{vars.DEV_FIREBASE_APP_ID}}
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{vars.DEV_FIREBASE_AUTH_DOMAIN}}
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{vars.DEV_FIREBASE_MESSAGING_SENDER_ID}}
NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{vars.DEV_FIREBASE_PROJECT_ID}}
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{vars.DEV_FIREBASE_STORAGE_BUCKET}}
NEXT_PUBLIC_SENTRY_DSN: ${{vars.SENTRY_DSN}}
NEXT_PUBLIC_SENTRY_PROJECT: ${{vars.SENTRY_PROJECT}}
- name: build (production)
if: ${{ ((github.head_ref || github.ref_name) == env.PRODUCTION_BRANCH) && github.event.pull_request.merged == true }}
id: build-production
run: npx @cloudflare/next-on-pages@1
env:
NEXT_PUBLIC_API_ENDPOINT: ${{secrets.PROD_API_ENDPOINT}}
NEXT_PUBLIC_FIREBASE_API_KEY: ${{secrets.PROD_FIREBASE_API_KEY}}
NEXT_PUBLIC_FIREBASE_APP_ID: ${{secrets.PROD_FIREBASE_APP_ID}}
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{secrets.PROD_FIREBASE_AUTH_DOMAIN}}
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{secrets.PROD_FIREBASE_MESSAGING_SENDER_ID}}
NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{secrets.PROD_FIREBASE_PROJECT_ID}}
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{secrets.PROD_FIREBASE_STORAGE_BUCKET}}
NEXT_PUBLIC_SENTRY_DSN: ${{vars.SENTRY_DSN}}
NEXT_PUBLIC_SENTRY_PROJECT: ${{vars.SENTRY_PROJECT}}
NEXT_PUBLIC_GTMID: ${{vars.GTMID}}
- name: deploy
id: deploy
uses: whatacotton/pages-action@v1
if: steps.build-preview.outcome == 'success' || steps.build-production.outcome == 'success'
with:
apiToken: ${{secrets.CLOUDFLARE_API_TOKEN}}
accountId: ${{vars.CLOUDFLARE_ACCOUNT_ID}}
projectName: ${{ env.PROJECT_NAME }}
directory: ".vercel/output/static"
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
productionBranch: ${{ env.PRODUCTION_BRANCH }}
branch: ${{ github.head_ref || github.ref_name }}
wranglerVersion: "3"
- name: Sentry
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
- name: Notify
uses: sarisia/actions-status-discord@v1
if: always() && !cancelled()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
status: ${{ job.status }}
content: "status: ${{ job.status }} \n🔗 Preview URL: ${{ steps.deploy.outputs.url }} \n📌 Branch Preview URL: ${{ steps.deploy.outputs.alias }}"
title: "${{ github.workflow }}"
description: "Build and deploy status of sos24-client."
color: 0x6600CC
url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
username: GitHub Actions
avatar_url: https://r2.sohosai.com/logo.png