-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make separate step for publish
- Loading branch information
1 parent
b769f8b
commit a5d6ddc
Showing
10 changed files
with
238 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
dist | ||
*.js | ||
scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Deploy | ||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy-it: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup NodeJS | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
cache: 'yarn' | ||
|
||
- name: Git | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Restore cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} | ||
|
||
- name: Install packages | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Deploy packages | ||
run: yarn run deploy | ||
env: | ||
REF: ${{ github.ref }} | ||
BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
GH_TOKEN: ${{ github.token }} | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
VERCEL_PROJECT_WALLETS: ${{ secrets.VERCEL_PROJECT_WALLETS }} | ||
VERCEL_PROJECT_Q: ${{ secrets.VERCEL_PROJECT_Q }} | ||
VERCEL_PROJECT_WALLET_ADAPTER: ${{ secrets.VERCEL_PROJECT_WALLET_ADAPTER }} | ||
VERCEL_PROJECT_WIDGET_CONFIG: ${{ secrets.VERCEL_PROJECT_WIDGET_CONFIG }} | ||
VERCEL_PROJECT_WIDGET_APP: ${{ secrets.VERCEL_PROJECT_WIDGET_APP }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
import process from 'node:process'; | ||
import { workspacePackages } from '../common/utils.mjs'; | ||
import { buildPackages, logAsSection } from '../publish/utils.mjs'; | ||
import { deployProjectsToVercel } from './utils.mjs'; | ||
|
||
// TODO: Working directory should be empty. | ||
async function run() { | ||
// Detect last relase and what packages has changed since then. | ||
const packages = await workspacePackages(); | ||
const privatePackages = packages.filter((pkg) => { | ||
return pkg.private; | ||
}); | ||
|
||
await buildPackages(privatePackages).catch((e) => { | ||
console.log( | ||
'[-] BUILD FAILED. Ignore it to workflow run the rest of tasks.' | ||
); | ||
console.log(e); | ||
}); | ||
logAsSection('[x] Build for VERCEL'); | ||
await deployProjectsToVercel(privatePackages).catch((e) => { | ||
console.log( | ||
'[-] DEPLOY FAILED. Ignore it to workflow run the rest of tasks.' | ||
); | ||
console.log(e); | ||
}); | ||
logAsSection('[x] Deploy to VERCEL'); | ||
} | ||
|
||
run().catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { execa } from 'execa'; | ||
import { detectChannel } from '../publish/utils.mjs'; | ||
import { VERCEL_ORG_ID, VERCEL_PACKAGES, VERCEL_TOKEN } from './config.mjs'; | ||
|
||
export function getVercelProjectId(packageName) { | ||
return VERCEL_PACKAGES[packageName]; | ||
} | ||
|
||
export async function deployProjectsToVercel(pkgs) { | ||
await Promise.all(pkgs.map((pkg) => deploySingleProjectToVercel(pkg))); | ||
} | ||
export async function deploySingleProjectToVercel(pkg) { | ||
const deployTo = detectChannel() === 'prod' ? 'production' : 'preview'; | ||
|
||
const env = { | ||
VERCEL_ORG_ID: VERCEL_ORG_ID, | ||
VERCEL_PROJECT_ID: getVercelProjectId(pkg.name), | ||
}; | ||
|
||
console.log(`start deplyoing ${pkg.name}...`); | ||
|
||
await execa( | ||
'yarn', | ||
[ | ||
'vercel', | ||
'pull', | ||
'--cwd', | ||
pkg.location, | ||
'--environment', | ||
deployTo, | ||
'--token', | ||
VERCEL_TOKEN, | ||
'--yes', | ||
], | ||
{ env }, | ||
); | ||
await execa('yarn', ['vercel', 'build', '--cwd', pkg.location, '--token', VERCEL_TOKEN], { env }); | ||
await execa('yarn', ['vercel', pkg.location, '--prebuilt', '--token', VERCEL_TOKEN], { env }); | ||
|
||
console.log(`${pkg.name} deployed.`); | ||
} | ||
|
||
export function groupPackagesForDeploy(packages) { | ||
const output = { | ||
npm: [], | ||
vercel: [], | ||
}; | ||
|
||
packages.forEach((pkg) => { | ||
if (!!getVercelProjectId(pkg.name)) { | ||
output.vercel.push(pkg); | ||
} else if (!pkg.private) { | ||
// If getVercelProjectId returns undefined, it's possible to be added as npm package | ||
// So here we are making sure it's not a private package and can be published using npm | ||
output.npm.push(pkg); | ||
} | ||
}); | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.