-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (147 loc) · 4.8 KB
/
build-test-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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Build, test, and deploy
on: [push]
jobs:
installDependencies:
name: Install dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v2
with:
node-version: '14'
check-latest: true
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
- uses: actions/cache@v2
id: cache-build
with:
path: ./*
key: ${{ github.sha }}
formatCheck:
name: Check formatting
runs-on: ubuntu-latest
needs: installDependencies
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- run: yarn format:check
lintCheck:
name: Check lint
runs-on: ubuntu-latest
needs: installDependencies
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- run: yarn lint
typeCheck:
name: Check type
runs-on: ubuntu-latest
needs: installDependencies
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- run: yarn type:check
testUnit:
name: Test unit
runs-on: ubuntu-latest
needs: installDependencies
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- run: yarn test
deployApplication:
name: Deploy to Layer0
runs-on: ubuntu-latest
needs: [formatCheck, lintCheck, typeCheck, testUnit]
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- name: Check if layer0 TOKEN exists
if: env.layer0_deploy_token == ''
run: |
echo You must define the "layer0_deploy_token" secret in GitHub project settings
exit 1
env:
layer0_deploy_token: ${{ secrets.layer0_deploy_token }}
- name: Set BRANCH_NAME and ENVIRONMENT_NAME variables
shell: bash
run: |
bash ./.github/set-vars.sh
- name: Start deployment
uses: bobheadxi/deployments@v0.5.2
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ env.ENVIRONMENT_NAME }}
- name: Deploy to Layer0
id: deploy
run: |
yarn layer0:deploy --branch=$BRANCH_NAME --token=$layer0_deploy_token --environment=$ENVIRONMENT_NAME
env:
layer0_deploy_token: ${{ secrets.layer0_deploy_token }}
- name: Get deployment URLs
id: deploy_manifest
run: |
content=$(cat .layer0/deployment-manifest.json | tr -d '\n')
echo "::set-output name=json::$content"
- name: Check if deployment report file exists
if: steps.deploy_manifest.outputs.json == ''
run: |
echo File .layer0/deployment-manifest.json is empty or not exists
exit 1
- name: Update deployment status
uses: bobheadxi/deployments@v0.5.2
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ env.DEPLOYMENT_EDGE }}
env:
DEPLOYMENT_EDGE: ${{fromJson(steps.deploy_manifest.outputs.json).environment.url}}
- name: Find pull-request ID
uses: jwalton/gh-find-current-pr@v1.0.3
id: finder
- name: Sticky Pull Request Comment
uses: marocchino/sticky-pull-request-comment@v2.1.0
with:
number: ${{ steps.finder.outputs.pr }}
recreate: true
message: |
:white_check_mark: Permalink: <${{ env.DEPLOYMENT_PERMALINK }}>
:heavy_check_mark: Edge: <${{env.DEPLOYMENT_EDGE}}>
env:
DEPLOYMENT_NUMBER: ${{fromJson(steps.deploy_manifest.outputs.json).number}}
DEPLOYMENT_PERMALINK: ${{fromJson(steps.deploy_manifest.outputs.json).url}}
DEPLOYMENT_EDGE: ${{fromJson(steps.deploy_manifest.outputs.json).environment.url}}
DEPLOYMENT_ENVIRONMENT: ${{fromJson(steps.deploy_manifest.outputs.json).environment.name}}