-
Notifications
You must be signed in to change notification settings - Fork 14
84 lines (70 loc) · 2.6 KB
/
cd-deploy.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
name: CD Deploy
on:
workflow_dispatch:
push:
branches:
- "main"
- "staging"
- "dev"
jobs:
release:
environment: ${{ github.ref == 'refs/heads/main' && 'production' || (github.ref == 'refs/heads/staging' && 'staging' || 'development') }}
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DEPLOYMENT_STAGE: ${{ github.ref == 'refs/heads/main' && 'production' || (github.ref == 'refs/heads/staging' && 'staging' || 'development') }}
CI: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
- name: Install @metacraft/cli
run: npm i --location=global @metacraft/cli@latest
- name: Setup Yarn
run: corepack enable && yarn set version stable
- name: Install dependencies
run: yarn
- name: Execute eslint
run: yarn lint
- name: Execute type check with tsc
run: yarn type-check
- name: Create .env.test file for testing
run: |
touch .env.test
echo "${{ secrets.WALLET_TEST_ENV_FILE }}" >> apps/wallet/.env.test
- name: Run test cases
run: yarn test
- name: Set branch name
id: branch
run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}"
- name: Inspect stacks from commit message
id: inspect_stacks_from_commit_message
run: |
commit=$(git log --format="%B" -n 1)
stack_regex="\[(document|landing|wallet)\]"
remove_brackets_regex="(\w+)"
stacks_str=$(echo $commit | grep -oE $stack_regex | grep -oE $remove_brackets_regex | tr "\n" " ")
echo "stacks_str=\"$stacks_str\"" >> $GITHUB_OUTPUT
- name: Create .env file
run: |
touch .env.$DEPLOYMENT_STAGE
echo "${{ secrets.WALLET_ENV_FILE }}" >> apps/wallet/.env.$DEPLOYMENT_STAGE
- name: Deploy
run: |
stacks_str=${{ steps.inspect_stacks_from_commit_message.outputs.stacks_str }}
read -r -a stacks <<< $stacks_str
if [ ${#stacks[@]} -eq 0 ]; then
echo "Deploying all stacks to $DEPLOYMENT_STAGE"
yarn deploy --stage $DEPLOYMENT_STAGE
else
for stack in "${stacks[@]}"; do
echo "Deploying $stack to $DEPLOYMENT_STAGE"
yarn deploy $stack --stage $DEPLOYMENT_STAGE
done
fi