Skip to content

Commit

Permalink
deploy on dev (#131)
Browse files Browse the repository at this point in the history
* deploy on dev

* add staging deploy

* fix it

* checkout deploy-staging

* fix deploy preview

* fix ci.yml

* fix ci

* fix deploy

* deploy it

* fix public hostname deploy
  • Loading branch information
0xBigBoss authored Feb 26, 2024
1 parent 1fc78df commit ba79e31
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 115 deletions.
58 changes: 58 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy
description: "Deploy the project to Vercel and Supabase."
inputs:
vercel-token:
description: "The Vercel token to use for deployment."
required: true
vercel-org-id:
description: "The Vercel organization ID to use for deployment."
required: true
vercel-project-id:
description: "The Vercel project ID to use for deployment."
required: true
production:
description: "Whether to deploy to the production environment."
required: false
default: "false"
supabase-project-id:
description: "The Supabase project ID to use for deployment."
required: true
supabase-access-token:
description: "The Supabase access token to use for deployment."
required: true
supabase-db-password:
description: "The Supabase database password to use for deployment."
required: true
runs:
using: "composite"
steps:
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
yarn-install: false
env:
YARN_ENABLE_HARDENED_MODE: "0"
- name: Supabase Deploy
id: deploy
uses: ./.github/actions/supabase-deploy
with:
supabase-project-id: ${{ inputs.supabase-project-id }}
supabase-access-token: ${{ inputs.supabase-access-token }}
supabase-db-password: ${{ inputs.supabase-db-password }}
- name: Extract Branch
id: extract-branch
uses: ./.github/actions/extract-branch
- name: Public Hostname
shell: bash
id: public-hostname
run: echo "public-hostname=sendapp-${{steps.extract-branch.outputs.branch}}-0xsend.vercel.app" >> $GITHUB_OUTPUT
- name: Vercel Deploy
uses: ./.github/actions/vercel-deploy
with:
vercel-token: ${{ inputs.vercel-token }}
vercel-org-id: ${{ inputs.vercel-org-id }}
vercel-project-id: ${{ inputs.vercel-project-id }}
public-hostname: ${{ steps.public-hostname.outputs.public-hostname }}
production: ${{ inputs.production }}
env:
YARN_ENABLE_HARDENED_MODE: "0"
21 changes: 21 additions & 0 deletions .github/actions/extract-branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Extract Branch Name"
description: "Extract the branch name from the GitHub event payload and set it as an output cleaned for use in Vercel."
outputs:
branch:
description: "The cleaned branch name."
value: ${{ steps.extract.outputs.branch }}
runs:
using: "composite"
steps:
- name: Extract Branch Name
id: extract
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
37 changes: 37 additions & 0 deletions .github/actions/supabase-deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Supabase Deploy Migrations
description: "Deploy the project to Supabase. Run migrations against the database."
inputs:
supabase-project-id:
description: "The Supabase project ID to use for deployment."
required: true
supabase-access-token:
description: "The Supabase access token to use for deployment."
required: true
supabase-db-password:
description: "The Supabase database password to use for deployment."
required: true
runs:
using: "composite"
steps:
- name: Mask Supabase Access Token
shell: bash
run: echo "::add-mask::${{ inputs.supabase-access-token }}"
- name: Mask Supabase Database Password
shell: bash
run: echo "::add-mask::${{ inputs.supabase-db-password }}"
- name: Mask Supabase Project ID
shell: bash
run: echo "::add-mask::${{ inputs.supabase-project-id }}"
- uses: supabase/setup-cli@v1
with:
version: latest
- shell: bash
run: supabase link --project-ref ${{ inputs.supabase-project-id }}
env:
SUPABASE_ACCESS_TOKEN: ${{ inputs.supabase-access-token }}
SUPABASE_DB_PASSWORD: ${{ inputs.supabase-db-password }}
- shell: bash
run: supabase db push
env:
SUPABASE_ACCESS_TOKEN: ${{ inputs.supabase-access-token }}
SUPABASE_DB_PASSWORD: ${{ inputs.supabase-db-password }}
31 changes: 30 additions & 1 deletion .github/actions/vercel-deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ inputs:
vercel-token:
description: "The Vercel token to use for deployment."
required: true
vercel-org-id:
description: "The Vercel organization ID to use for deployment."
required: true
vercel-project-id:
description: "The Vercel project ID to use for deployment."
required: true
public-hostname:
description: "The public hostname alias to use for the deployment."
required: false
default: ""
production:
description: "Whether to deploy to the production environment."
required: false
default: "false"
outputs:
deployment-url:
description: "The URL of the deployment."
Expand All @@ -21,22 +31,41 @@ runs:
- name: Switch to Vercel Send team
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} team switch 0xsend
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
- name: Pull Vercel Environment Information
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} pull --yes --environment=preview
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
- name: Build Project Artifacts
shell: bash
run: bunx vercel --token=${{ inputs.vercel-token }} build
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
- name: Deploy Project Artifacts to Vercel
id: deploy
shell: bash
run: |
bunx vercel --token=${{ inputs.vercel-token }} deploy --prebuilt > deployment-url.txt
if [[ ${{ inputs.production }} == "true" ]]; then
bunx vercel --token=${{ inputs.vercel-token }} deploy --prebuilt --prod > deployment-url.txt
else
bunx vercel --token=${{ inputs.vercel-token }} deploy --prebuilt > deployment-url.txt
fi
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
echo ::notice::Deployment URL: $(cat deployment-url.txt)
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
- 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 }}/
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
44 changes: 25 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
SKIP_YARN_POST_INSTALL: 1

ci:
# skip if on dev and main (but not PRS to dev or main)
if: ${{ !(contains(github.ref, 'dev') || contains(github.ref, 'main')) }}
runs-on: ubuntu-latest
needs: [cache-deps]
env:
Expand Down Expand Up @@ -92,10 +94,9 @@ 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'
# **always** skip if on dev and main since it will be deployed with another workflow
if: ${{ !(contains(github.ref, 'dev') || contains(github.ref, 'main') || contains(github.head_ref, 'dev') || contains(github.head_ref, 'main')) }}
runs-on: ubuntu-latest
needs: [cache-deps]

Expand All @@ -117,30 +118,35 @@ jobs:
env:
YARN_ENABLE_HARDENED_MODE: 0
- name: Extract branch name
id: extract_branch
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_hostname=sendapp-${branch}-0xsend.vercel.app" >> $GITHUB_OUTPUT
id: extract-branch
uses: ./.github/actions/extract-branch
- name: Set Public Hostname
id: public-hostname
run: echo "public-hostname=sendapp-${{steps.extract-branch.outputs.branch}}-0xsend.vercel.app" >> $GITHUB_OUTPUT
- name: Vercel Deploy
id: deploy
id: vercel-deploy
uses: ./.github/actions/vercel-deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
public-hostname: ${{ steps.extract_branch.outputs.public_hostname }}
public-hostname: ${{ steps.public-hostname.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 }}/)
Vercel Unique URL: [${{ steps.vercel-deploy.outputs.deployment-url }}](${{ steps.vercel-deploy.outputs.deployment-url }})
Vercel Preview URL: [${{ steps.public-hostname.outputs.public-hostname }}](https://${{ steps.public-hostname.outputs.public-hostname }}/)
deploy-staging:
if: github.ref == 'refs/heads/dev'
needs: [cache-deps]
uses: ./.github/workflows/deploy-staging.yml
secrets:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
STAGING_SUPABASE_PROJECT_ID: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
STAGING_SUPABASE_DB_PASSWORD: ${{ secrets.STAGING_SUPABASE_DB_PASSWORD }}
45 changes: 45 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Staging

on:
workflow_dispatch:
workflow_call:
secrets:
VERCEL_TOKEN:
description: 'Vercel token'
required: true
VERCEL_PROJECT_ID:
description: 'Vercel project id'
required: true
VERCEL_ORG_ID:
description: 'Vercel org id'
required: true
SUPABASE_ACCESS_TOKEN:
description: 'Supabase access token'
required: true
STAGING_SUPABASE_PROJECT_ID:
description: 'Staging Supabase project id'
required: true
STAGING_SUPABASE_DB_PASSWORD:
description: 'Staging Supabase db password'
required: true

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

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Deploy
uses: ./.github/actions/deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
production: false
supabase-project-id: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
supabase-access-token: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
supabase-db-password: ${{ secrets.STAGING_SUPABASE_DB_PASSWORD }}
84 changes: 0 additions & 84 deletions .github/workflows/staging.yml

This file was deleted.

3 changes: 2 additions & 1 deletion supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
project_id = "send"

[api]
enabled = true
port = 54321
schemas = ["public", "storage"]
schemas = ["public", "storage", "graphql_public"]
extra_search_path = ["public", "extensions"]
max_rows = 100

Expand Down
Loading

0 comments on commit ba79e31

Please sign in to comment.