-
-
Notifications
You must be signed in to change notification settings - Fork 650
223 lines (196 loc) · 8.18 KB
/
mycryptobuilds.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: MyCryptoBuilds
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_MYCRYPTOBUILDS }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_MYCRYPTOBUILDS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_MYCRYPTOBUILDS }}
AWS_REGION: 'us-east-2'
on:
pull_request:
branches:
- '*'
push:
branches:
- master
repository_dispatch:
types: [ok-to-test-command]
jobs:
myc-build:
environment: STAGING
runs-on: ubuntu-latest
steps:
# Fetch the PR number to use it with AWS
- name: Set PR_NUMBER
run: |
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# Define url as env var to be used by TestCafe.
- name: Set E2E_BASE_URL
if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
run: |
E2E_BASE_URL=$( echo https://mycryptobuilds.com/pr/${PR_NUMBER}/# )
echo $E2E_BASE_URL
echo "E2E_BASE_URL=$E2E_BASE_URL" >> $GITHUB_ENV
# Define url as env var to be used by TestCafe.
- name: Set E2E_BASE_URL
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
E2E_BASE_URL=$( echo https://mycryptobuilds.com/master/# )
echo $E2E_BASE_URL
echo "E2E_BASE_URL=$E2E_BASE_URL" >> $GITHUB_ENV
# Define url as env var to be used by TestCafe.
- name: Set E2E_BASE_URL
if: github.event_name == 'repository_dispatch'
run: |
E2E_BASE_URL=$( echo https://mycryptobuilds.com/pr/${{ github.event.client_payload.pull_request.number }}/# )
echo $E2E_BASE_URL
echo "E2E_BASE_URL=$E2E_BASE_URL" >> $GITHUB_ENV
- uses: actions/checkout@v2
if: github.event_name != 'repository_dispatch'
- uses: actions/checkout@v2
if: github.event_name == 'repository_dispatch'
with:
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- name: Retrieve node version from .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat package.json | grep '\"node\":' | sed 's/^ *//;s/ *$//;s/\"node\":\ \"//;s/\",//')"
id: nvm
- name: Setup node ${{ steps.nvm.outputs.NVMRC }}
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Cache node modules
id: cache
uses: actions/cache@v2
with:
path: node_modules
## Check cache based on yarn.lock hashfile
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
- name: Cache Hardhat network
uses: actions/cache@v2
with:
path: .cache/hardhat
key: ${{ runner.OS }}-build-${{ hashFiles('**/hardhat.config.ts') }}
- name: Install Dependencies
## If no cache is found, install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Set outputs
id: vars
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: yarn build:staging
run: yarn build:staging
if: github.event_name == 'pull_request'
env:
COMMIT_HASH: ${{ github.event.pull_request.head.sha }}
- name: yarn build:staging
run: yarn build:staging
if: github.event_name == 'repository_dispatch'
env:
COMMIT_HASH: ${{ github.event.client_payload.pull_request.head.sha }}
- name: yarn build:staging
run: yarn build:staging
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
COMMIT_HASH: ${{ steps.vars.outputs.sha }}
- name: S3 Sync - Downloadable Branch - push
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'push'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: ${GITHUB_REF##*/}
SOURCE_DIR: 'dist/web'
- name: S3 Sync - Downloadable Branch - repository_dispatch
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: ${{ github.event.client_payload.pull_request.head.ref }}
SOURCE_DIR: 'dist/web'
- name: S3 Sync - Downloadable Branch - pull_request
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: ${{ github.head_ref }}
SOURCE_DIR: 'dist/web'
####
- name: S3 Sync - SHA Push
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'push'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --exclude '.git/*'
env:
DEST_DIR: ${GITHUB_SHA}
SOURCE_DIR: 'dist/web'
- name: S3 Sync - SHA Pull Request
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --exclude '.git/*'
env:
DEST_DIR: ${{ github.event.pull_request.head.sha }}
SOURCE_DIR: 'dist/web'
- name: S3 Sync - SHA Repository Dispatch
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --exclude '.git/*'
env:
DEST_DIR: ${{ github.event.client_payload.pull_request.head.sha }}
SOURCE_DIR: 'dist/web'
####
- name: S3 Sync - Downloadable - PR Number
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'pr/${PR_NUMBER}'
SOURCE_DIR: 'dist/web'
- name: S3 Sync - Downloadable - PR Number - Repository Dispatch
uses: jakejarvis/s3-sync-action@v0.5.1
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'pr/${{ github.event.client_payload.pull_request.number }}'
SOURCE_DIR: 'dist/web'
- name: Mycrypto-bot trigger
if: github.event_name == 'pull_request'
run: aws sns publish --topic-arn ${{ secrets.SNS_TOPIC_MYCRYPTO_BOT }} --region us-east-2 --message $(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
# Launch E2E tests. When in pull request it runs against the PR's mycryptobuilds url.
- name: E2E - run
run: yarn test:e2e:ci
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
- name: Update PR status
uses: actions/github-script@v1
id: update-check-run
if: github.event_name == 'repository_dispatch'
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;