Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deploy workflows #18

Merged
merged 4 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Vercel Preview Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
pull_request:
branches-ignore:
- main
jobs:
Deploy-Preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Install ZX
run: npm i -g zx
- name: Deploy Project Artifacts to Vercel
env:
NX_VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
NX_VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
NX_VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: zx ./scripts/deploy-preview.mjs
27 changes: 27 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Vercel Production Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
pull_request:
branches:
- main
jobs:
Deploy-Production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} --scope=chainlinklabs
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} --scope=chainlinklabs
- name: Install ZX
run: npm i -g zx
- name: Deploy Project Artifacts to Vercel
env:
NX_VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
NX_VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
NX_VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: zx ./scripts/deploy-prod.mjs
43 changes: 43 additions & 0 deletions scripts/deploy-preview.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env zx
const localRepo = await $`git rev-parse --show-toplevel`

const appName = localRepo
.toString()
.replace(/\/\S*\//, '')
.replace('\n', '')
const appUrl = appName
const lineBreak = '-------------------'

const commitSha = await $`git show --format="%H" --no-patch`
const authorNameOutput = await $`git show --format="%an" --no-patch`
const authorName = authorNameOutput
.toString()
.replace(' ', '')
.replace('\n', '')
.replace(/\(.*\)/g, '')
const commitSubject = await $`git show --format='%s' --no-patch`
const REF = await $`git rev-parse --abbrev-ref HEAD`
const REPOSITORY = appName
const ORGANISATION = 'smartcontractkit'

const gitBranchName = await $`git branch --show-current`

const alias =
appName + '-' +
gitBranchName.stdout.trim().replace(/\//g, '-').slice(0, 30) +
'-chainlinklabs.vercel.app'

const deployOutput =
await $`VERCEL_ORG_ID=$NX_VERCEL_ORG_ID VERCEL_PROJECT_ID=$NX_VERCEL_PROJECT_ID vercel --scope chainlinklabs --token=$NX_VERCEL_TOKEN -m githubDeployment=1 -m githubCommitAuthorName=${authorName} -m githubCommitAuthorLogin=${authorName} -m githubCommitMessage=${commitSubject} -m githubCommitOrg=${ORGANISATION} -m githubCommitRepo=${REPOSITORY} -m githubCommitRef=${REF} -m githubCommitSha=${commitSha} -m githubOrg=${ORGANISATION} -m githubRepo=${REPOSITORY} ./`

const appUrlRegex = new RegExp(`https://${appUrl}.*.vercel.app`, 'g')
const deployPreviewUrl = deployOutput.stdout.match(appUrlRegex)

await $`vercel alias ${deployPreviewUrl} ${alias} --token=$NX_VERCEL_TOKEN --scope=chainlinklabs`

console.log(`
${lineBreak}
usechainlinkfunctions commit preview URL: ${deployPreviewUrl}
usechainlinkfunctions branch preview URL: https://${alias}
${lineBreak}
`)
18 changes: 18 additions & 0 deletions scripts/deploy-prod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env zx
const localRepo = await $`git rev-parse --show-toplevel`
const commitSha = await $`git show --format="%H" --no-patch`
const authorNameOutput = await $`git show --format="%an" --no-patch`
const authorName = authorNameOutput
.toString()
.replace(' ', '')
.replace('\n', '')
.replace(/\(.*\)/g, '')
const commitSubject = await $`git show --format='%s' --no-patch`
const REF = await $`git rev-parse --abbrev-ref HEAD`
const REPOSITORY = localRepo
.toString()
.replace(/\/\S*\//, '')
.replace('\n', '')
const ORGANISATION = 'smartcontractkit'

await $`VERCEL_ORG_ID=$NX_VERCEL_ORG_ID VERCEL_PROJECT_ID=$NX_VERCEL_PROJECT_ID vercel --scope chainlinklabs --token=$NX_VERCEL_TOKEN --prod -m githubDeployment=1 -m githubCommitAuthorName=${authorName} -m githubCommitAuthorLogin=${authorName} -m githubCommitMessage=${commitSubject} -m githubCommitOrg=${ORGANISATION} -m githubCommitRepo=${REPOSITORY} -m githubCommitRef=${REF} -m githubCommitSha=${commitSha} -m githubOrg=${ORGANISATION} -m githubRepo=${REPOSITORY} ./`