Skip to content

Commit

Permalink
build: add scripts for building backend and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianjeng committed Jan 11, 2024
1 parent 38193a8 commit 151f44c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy pages

on: [push, pull_request]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
- run: yarn install
- name: Build
run: |
cd packages/serverless-backend
npx @cloudflare/next-on-pages@1
- name: Deploy
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
cd packages/serverless-backend
npx wrangler pages deploy .vercel/output/static --branch=$BRANCH_NAME --project-name=unirep-explorer-backend
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"frontend": "yarn workspace frontend",
"lint": "prettier .",
"lint:check": "prettier . --check",
"lint:fix": "prettier . --write"
"lint:fix": "prettier . --write",
"prepare": "scripts/cf_build.sh"
},
"devDependencies": {
"lerna": "^5.5.4"
Expand Down
16 changes: 16 additions & 0 deletions scripts/cf_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Load environment variables from .env file
source .env

if [ "$CF_PAGES_BRANCH" = "production" ]; then
echo "export const version = 'v2.0.0'" > packages/frontend/src/config.js
echo "export const network = 'sepolia'" >> packages/frontend/src/config.js
echo "export const SERVER = 'https://unirep-explorer-backend.pages.dev'" >> packages/frontend/src/config.js
elif [ "$CF_PAGES_BRANCH" = "staging" ]; then
branch=$(git branch --show-current)
branch="${branch%"${branch##*[![:space:]]}"}" # Trim trailing whitespace
echo "export const version = 'v2.0.0'" > packages/frontend/src/config.js
echo "export const network = 'sepolia'" >> packages/frontend/src/config.js
echo "export const SERVER = 'https://${branch}.unirep-explorer-backend.pages.dev'" >> packages/frontend/src/config.js
fi
16 changes: 0 additions & 16 deletions scripts/linkUnirep.sh

This file was deleted.

0 comments on commit 151f44c

Please sign in to comment.