Skip to content

Commit

Permalink
add staging deploy (#130)
Browse files Browse the repository at this point in the history
* add staging deploy

* always deploy vercel preview

* fix ci

* try reusing

* add setup-env

* fix setup-env

* try this way

* try this way too

* think this is it

* skip postinstall

* rename SKIP_YARN_POST_INSTALL

* add vercel deploy comp action

* version broadcasts

* drop vercel.json

* no need to build before vercel build

* fix deploy, biome ignore stuff

* typo

* optimizzziiinnggg

* fix

* keep env YARN_ENABLE_HARDENED_MODE: 0

* fix deploy alias

* fix links

* fix url
  • Loading branch information
0xBigBoss authored Feb 25, 2024
1 parent 3327170 commit 1fc78df
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 48 deletions.
40 changes: 40 additions & 0 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Setup Environment"
description: "Set up Node.js, install Foundry, and set up Bun. Runs Yarn install."
inputs:
install-foundry:
description: "Whether to install Foundry."
required: false
default: "true"
install-bun:
description: "Whether to install Bun."
required: false
default: "true"
install-node:
description: "Whether to install Node.js."
required: false
default: "true"
yarn-install:
description: "Whether to run Yarn install."
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Use Node.js
if: ${{ inputs.install-node == 'true' }}
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: "yarn"
- name: Setup Bun
if: ${{ inputs.install-bun == 'true' }}
uses: oven-sh/setup-bun@v1
- name: Install Foundry
if: ${{ inputs.install-foundry == 'true' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Yarn Install
if: ${{ inputs.yarn-install == 'true' }}
shell: bash
run: yarn install --immutable
42 changes: 42 additions & 0 deletions .github/actions/vercel-deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Deploy Vercel"
description: "Deploy the project to Vercel. Pulls environment information, builds the project, and deploys it to Vercel. Sets the Vercel alias."
inputs:
vercel-token:
description: "The Vercel token to use for deployment."
required: true
public-hostname:
description: "The public hostname alias to use for the deployment."
required: false
default: ""
outputs:
deployment-url:
description: "The URL of the deployment."
value: ${{ steps.deploy.outputs.deployment_url }}
runs:
using: "composite"
steps:
- name: Mask Vercel Token
shell: bash
run: echo "::add-mask::${{ inputs.vercel-token }}"
- name: Switch to Vercel Send team
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} team switch 0xsend
- name: Pull Vercel Environment Information
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} pull --yes --environment=preview
- name: Build Project Artifacts
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} build
- name: Deploy Project Artifacts to Vercel
id: deploy
shell: bash
run: |
bunx vercel --token=${{ inputs.vercel-token }} deploy --prebuilt > deployment-url.txt
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
echo ::notice::Deployment URL: $(cat deployment-url.txt)
- name: Set Vercel Branch Alias
if: ${{ inputs.public-hostname != '' }}
shell: bash
run: |
bunx vercel --token=${{ inputs.vercel-token }} -S 0xsend alias set ${{ steps.deploy.outputs.deployment_url }} ${{ inputs.public-hostname }}
echo ::notice::Vercel Alias URL https://${{ inputs.public-hostname }}/
86 changes: 47 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ concurrency:
cancel-in-progress: true

jobs:
ci:
# set yarn cache
cache-deps:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
install-foundry: false
install-bun: false
env:
YARN_ENABLE_HARDENED_MODE: 0
SKIP_YARN_POST_INSTALL: 1

ci:
runs-on: ubuntu-latest
needs: [cache-deps]
env:
ANVIL_MAINNET_FORK_URL: ${{ secrets.CI_ANVIL_MAINNET_FORK_URL }}
ANVIL_BASE_FORK_URL: ${{ secrets.CI_ANVIL_BASE_FORK_URL }}
Expand All @@ -34,16 +49,12 @@ jobs:
run: |
brew bundle
brew cleanup
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'yarn'
- uses: oven-sh/setup-bun@v1
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Setup Environment
uses: ./.github/actions/setup-env
env:
YARN_ENABLE_HARDENED_MODE: 0
with:
version: nightly
yarn-install: false
- name: Tilt CI
shell: bash
run: tilt ci unit-tests:tests
Expand Down Expand Up @@ -81,11 +92,15 @@ jobs:
path: packages/playwright/playwright-report/
retention-days: 30

# @todo create supabase branch https://supabase.com/docs/reference/cli/supabase-branches-update
vercel-deploy-preview:
# skip if on dev since it will be deployed with another workflow
if: github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
needs: ci
needs: [cache-deps]

permissions:
pull-requests: write

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
Expand All @@ -95,25 +110,14 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'yarn'
- uses: oven-sh/setup-bun@v1
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
version: nightly
- name: Install Vercel CLI
run: yarn global add vercel
- name: Switch to Vercel Send team
run: vercel --token=${{ secrets.VERCEL_TOKEN }} team switch 0xsend
- name: Pull Vercel Environment Information
run: vercel --token=${{ secrets.VERCEL_TOKEN }} pull --yes --environment=preview
- name: Build Project Artifacts
run: vercel --token=${{ secrets.VERCEL_TOKEN }} build
yarn-install: false
env:
YARN_ENABLE_HARDENED_MODE: 0
- name: Extract branch name
id: extract_branch
shell: bash
run: |
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
Expand All @@ -124,15 +128,19 @@ jobs:
branch="${branch%-}" # Remove trailing hyphen, if any
branch="${branch#-}" # Remove leading hyphen, if any
echo "branch=${branch}" >> $GITHUB_OUTPUT
echo "public_url=https://sendapp-${BRANCH}-0xsend.vercel.app" >> $GITHUB_OUTPUT
id: extract_branch
- name: Deploy Project Artifacts to Vercel
echo "public_hostname=sendapp-${branch}-0xsend.vercel.app" >> $GITHUB_OUTPUT
- name: Vercel Deploy
id: deploy
run: |
vercel --token=${{ secrets.VERCEL_TOKEN }} deploy --prebuilt \
--env=NEXT_PUBLIC_URL=${{ steps.extract_branch.outputs.public_url }} \
> deployment-url.txt && \
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
echo ::notice::Deployment URL: $(cat deployment-url.txt)
- name: Set Vercel alias
run: vercel --token=${{ secrets.VERCEL_TOKEN }} -S 0xsend alias set ${{ steps.deploy.outputs.deployment_url }} ${{ steps.extract_branch.outputs.public_url }}
uses: ./.github/actions/vercel-deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
public-hostname: ${{ steps.extract_branch.outputs.public_hostname }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- uses: mshick/add-pr-comment@v2
with:
message-id: vercel-preview-url
message: |
Vercel Unique URL: [${{ steps.deploy.outputs.deployment-url }}](${{ steps.deploy.outputs.deployment-url }})
Vercel Preview URL: [${{ steps.extract_branch.outputs.public_hostname }}](https://${{ steps.extract_branch.outputs.public_hostname }}/)
84 changes: 84 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Deploy Staging

on:
push:
branches:
- dev
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}

jobs:
supabase-deploy:
runs-on: ubuntu-latest

env:
SUPABASE_ACCESS_TOKEN: '' # ${{ secrets.SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: '' # ${{ secrets.STAGING_DB_PASSWORD }}
SUPABASE_PROJECT_ID: '' # ${{ secrets.STAGING_PROJECT_ID }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: supabase/setup-cli@v1
with:
version: latest

- run: echo todo # supabase link --project-ref $SUPABASE_PROJECT_ID
- run: echo todo # supabase db push

vercel-deploy:
runs-on: ubuntu-latest

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'yarn'
- uses: oven-sh/setup-bun@v1
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install Vercel CLI
run: yarn global add vercel
- name: Switch to Vercel Send team
run: vercel --token=${{ secrets.VERCEL_TOKEN }} team switch 0xsend
- name: Pull Vercel Environment Information
run: vercel --token=${{ secrets.VERCEL_TOKEN }} pull --yes --environment=preview
- name: Build Project Artifacts
run: vercel --token=${{ secrets.VERCEL_TOKEN }} build
- name: Extract branch name
shell: bash
run: |
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
branch="${branch//\//-}" # Replace / with -
branch="${branch//_/-}" # Replace _ with -
branch="${branch,,}" # Convert to lowercase
branch="${branch//[^a-z0-9-]/}" # Remove any character that is not a-z, 0-9, or -
branch="${branch%-}" # Remove trailing hyphen, if any
branch="${branch#-}" # Remove leading hyphen, if any
echo "branch=${branch}" >> $GITHUB_OUTPUT
echo "public_url=https://sendapp-${BRANCH}-0xsend.vercel.app" >> $GITHUB_OUTPUT
id: extract_branch
- name: Deploy Project Artifacts to Vercel
id: deploy
run: |
vercel --token=${{ secrets.VERCEL_TOKEN }} deploy --prebuilt \
--env=NEXT_PUBLIC_URL=${{ steps.extract_branch.outputs.public_url }} \
> deployment-url.txt && \
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
echo ::notice::Deployment URL: $(cat deployment-url.txt)
- name: Set Vercel alias
run: vercel --token=${{ secrets.VERCEL_TOKEN }} -S 0xsend alias set ${{ steps.deploy.outputs.deployment_url }} ${{ steps.extract_branch.outputs.public_url }}
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,5 @@ tmp

.parcel-cache

# Foundry stuff
cache/
out/
broadcast

# ignore for now
Brewfile.lock.json
3 changes: 0 additions & 3 deletions apps/next/vercel.json

This file was deleted.

3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"dist/**",
"build/**",
".snaplet/**",
"packages/contracts/out/**",
"packages/contracts/cache/**",
"packages/contracts/broadcast/**",
"packages/contracts/lib/**",
"packages/ui/types/**",
"packages/playwright/test-results/**",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"web:prod": "yarn workspace next-app build",
"web:prod:serve": "yarn workspace next-app serve",
"fix": "manypkg fix",
"postinstall": "yarn check-deps && yarn build",
"postinstall": "test -n \"$SKIP_YARN_POST_INSTALL\" || (yarn check-deps && yarn build)",
"build": "yarn workspaces foreach --all --exclude next-app run build",
"biome:check": "biome check .",
"biome:check:fix": "biome check . --apply",
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Foundry stuff
cache/
out/
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
/broadcast/**/run-*.json
!/broadcast/**/run-latest.json
Loading

0 comments on commit 1fc78df

Please sign in to comment.