-
Notifications
You must be signed in to change notification settings - Fork 339
89 lines (89 loc) · 3.76 KB
/
preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Preview
on:
workflow_dispatch:
inputs:
projects:
description: 'Publish Workspaces (to Vercel)'
required: true
chain_type:
description: 'Chain Type to publish (default to mainnet when more than 1 was configured)'
required: false
defaults:
run:
shell: bash
jobs:
validate-projects:
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.extract-projects.outputs.projects }}
steps:
- uses: actions/checkout@v3
- name: Extract projects
run: |
export ALL_PROJECTS=$(yarn workspaces list --json | jq -csr '[ .[].name | select(. | startswith("web") ) ]')
node <<EOF | tee -a $GITHUB_OUTPUT $GITHUB_STEP_SUMMARY
const allProjects = JSON.parse(process.env.ALL_PROJECTS);
const projects = process.env.PROJECTS === '*' ? null : process.env.PROJECTS.split(/,/).map(p => p.trim()).filter(p => p);
console.log('projects=' + JSON.stringify(allProjects.filter(a => !projects || projects.includes(a))));
EOF
id: extract-projects
env:
PROJECTS: ${{ github.event.inputs.projects }}
publish:
runs-on: ubuntu-latest
needs: validate-projects
if: ${{ needs.validate-projects.outputs.projects != '[]' }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
project: ${{ fromJSON(needs.validate-projects.outputs.projects) }}
name: Publish ${{ matrix.project }}
steps:
- uses: actions/checkout@v3
- name: Assign chain type
run: |
# assign chain_type
node <<EOF | tee -a $GITHUB_OUTPUT
const chainType = process.env.NEXT_PUBLIC_CHAIN_TYPE?.toLowerCase() || 'mainnet';
const chainJson = require('./apps/' + process.env.PROJECT_NAME + '/src/chain.json');
const { chains, ...settings } = chainJson;
let chain = chains.find((c) => c.chainType?.toLowerCase() === chainType);
if (!chain && chainType !== 'testnet') {
chain = chains.find((c) => c.chainType?.toLowerCase() === 'testnet');
}
if (!chain) [chain] = chains;
if (!chain?.chainType || process.env.NEXT_PUBLIC_CHAIN_TYPE && process.env.NEXT_PUBLIC_CHAIN_TYPE.toLowerCase() !== chain.chainType.toLowerCase())
throw new Error('Chain type ' + process.env.NEXT_PUBLIC_CHAIN_TYPE + ' not found in chain.json');
console.log('chain_type=' + chain.chainType.toLowerCase());
EOF
id: assign-chain-type
env:
PROJECT_NAME: ${{ matrix.project }}
NEXT_PUBLIC_CHAIN_TYPE: ${{ github.event.inputs.chain_type }}
- name: Install Vercel CLI
run: npm i -g vercel
- name: Generate vercel.json
run: |
node <<EOF > vercel.json
const projectName = process.env.PROJECT_NAME || 'web';
const chainType = process.env.NEXT_PUBLIC_CHAIN_TYPE?.toLowerCase() || 'mainnet';
const config = {
buildCommand: 'NEXT_PUBLIC_CHAIN_TYPE=' + chainType + ' node vercel-deploy.js',
outputDirectory: 'apps/web/.next',
installCommand: 'node vercel-deploy.js manual ' + projectName,
devCommand: 'cd apps/web && yarn next dev',
framework: 'nextjs',
ignoreCommand: 'exit 1',
};
console.log(JSON.stringify(config, null, 2));
EOF
env:
PROJECT_NAME: ${{ matrix.project }}
NEXT_PUBLIC_CHAIN_TYPE: ${{ steps.assign-chain-type.outputs.chain_type }}
- name: Deploy preview to Vercel
run: vercel -t ${{ secrets.VERCEL_TOKEN }} | tee -a $GITHUB_STEP_SUMMARY
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}