-
Notifications
You must be signed in to change notification settings - Fork 29
287 lines (270 loc) · 10 KB
/
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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
name: Deployments
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy'
type: environment
required: true
jobs:
prepare-deployment:
environment: ${{ inputs.environment }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Prepare Parameters
id: prepare_parameters
run: |
BASE=$(node -p "require('./packages/starknet-snap/package.json').version")
HASH=$(git rev-parse --short HEAD)
DATE=$(date +%Y%m%d)
ENV=${{ inputs.environment }}
{
echo "AWS_CLOUDFRONT_DISTRIBUTIONS_ID=${{ vars.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}"
echo "AWS_S3_GET_STARKNET_URL=${{ vars.AWS_S3_GET_STARKNET_URL }}"
echo "AWS_S3_URL=${{ vars.AWS_S3_URL }}"
echo "GET_STARKNET_PUBLIC_PATH=${{ vars.GET_STARKNET_PUBLIC_PATH }}"
} >> "$GITHUB_OUTPUT"
if [[ $ENV == "dev" ]]; then
{
echo "VERSION=${BASE}-dev-${HASH}-${DATE}"
echo "TAG=dev"
echo "ENV=dev"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "staging" ]]; then
{
echo "VERSION=${BASE}-staging"
echo "TAG=staging"
echo "ENV=staging"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "production" ]]; then
{
echo "VERSION=${BASE}"
echo "TAG=latest"
echo "ENV=prod"
} >> "$GITHUB_OUTPUT"
else
echo "Invalid environment"
exit 1
fi
outputs:
VERSION: ${{ steps.prepare_parameters.outputs.VERSION }}
TAG: ${{ steps.prepare_parameters.outputs.TAG }}
ENV: ${{ steps.prepare_parameters.outputs.ENV }}
AWS_S3_GET_STARKNET_URL: ${{ steps.prepare_parameters.outputs.AWS_S3_GET_STARKNET_URL }}
AWS_CLOUDFRONT_DISTRIBUTIONS_ID: ${{ steps.prepare_parameters.outputs.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}
AWS_S3_URL: ${{ steps.prepare_parameters.outputs.AWS_S3_URL }}
GET_STARKNET_PUBLIC_PATH: ${{ steps.prepare_parameters.outputs.GET_STARKNET_PUBLIC_PATH }}
install-build:
needs:
- prepare-deployment
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install
run: |
yarn --no-immutable
yarn allow-scripts
- name: Build Snap
run: |
echo "Building Snap with version $VERSION"
npm --prefix ./packages/starknet-snap version --new-version "$VERSION" --no-git-tag-version --allow-same-version
yarn workspace @consensys/starknet-snap build
BUILD_VERSION=$(node -p "require('./packages/starknet-snap/package.json').version")
if [[ "$VERSION" != "$BUILD_VERSION" ]]; then
echo "Version mismatch"
exit 1
fi
echo "Building UI with version $VERSION"
REACT_APP_SNAP_VERSION="$VERSION" yarn workspace wallet-ui build
echo "Building Get Starknet with GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH"
GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH yarn workspace @consensys/get-starknet build
env:
SNAP_ENV: ${{ needs.prepare-deployment.outputs.ENV }}
VERSION: ${{ needs.prepare-deployment.outputs.VERSION }}
VOYAGER_API_KEY: ${{ secrets.VOYAGER_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
GET_STARKNET_PUBLIC_PATH: ${{ needs.prepare-deployment.outputs.GET_STARKNET_PUBLIC_PATH }}
- name: Cache Build
uses: actions/cache@v3
id: restore-build
with:
path: |
./packages/get-starknet/dist/webpack
./packages/wallet-ui/build
./packages/starknet-snap/package.json
./packages/starknet-snap/dist
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
publish-npm-dry-run:
runs-on: ubuntu-latest
needs:
- prepare-deployment
- install-build
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Restore Cached Build
uses: actions/cache@v3
id: restore-build
with:
# add /packages/snap/snap.manifest.json to include an updated shasum from build due to version update in auto PR
path: |
./packages/get-starknet/dist/webpack
./packages/wallet-ui/build
./packages/starknet-snap/package.json
./packages/starknet-snap/dist
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Dry Run Publish
run: |
npm pack ./packages/starknet-snap --tag "$TAG" --access public
env:
TAG: ${{ needs.prepare-deployment.outputs.TAG }}
publish-npm:
runs-on: ubuntu-latest
needs:
- publish-npm-dry-run
- prepare-deployment
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Restore Cached Build
uses: actions/cache@v3
id: restore-build
with:
# add /packages/snap/snap.manifest.json to include an updated shasum from build due to version update in auto PR
path: |
./packages/get-starknet/dist/webpack
./packages/wallet-ui/build
./packages/starknet-snap/package.json
./packages/starknet-snap/dist
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Run Publish
run: |
npm publish ./packages/starknet-snap --tag "$TAG" --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ needs.prepare-deployment.outputs.TAG }}
deploy-wallet-ui:
runs-on: ubuntu-latest
needs:
- prepare-deployment
- publish-npm
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Restore Cached Build
uses: actions/cache@v3
id: restore-build
with:
path: |
./packages/get-starknet/dist/webpack
./packages/wallet-ui/build
./packages/starknet-snap/package.json
./packages/starknet-snap/dist
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Deploy to AWS
run: |
echo "Deployed Dapp to : $AWS_S3_URL"
aws s3 sync ./packages/wallet-ui/build "$AWS_S3_URL"
env:
AWS_S3_URL: ${{ needs.prepare-deployment.outputs.AWS_S3_URL }}
deploy-get-starknet:
runs-on: ubuntu-latest
needs:
- prepare-deployment
- install-build
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Restore Cached Build
uses: actions/cache@v3
id: restore-build
with:
path: |
./packages/get-starknet/dist/webpack
./packages/wallet-ui/build
./packages/starknet-snap/package.json
./packages/starknet-snap/dist
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Deploy to AWS
run: |
echo "Deployed get Starknet to : $AWS_S3_GET_STARKNET_URL"
aws s3 sync ./packages/get-starknet/dist/webpack "$AWS_S3_GET_STARKNET_URL"
env:
AWS_S3_GET_STARKNET_URL: ${{ needs.prepare-deployment.outputs.AWS_S3_GET_STARKNET_URL }}
invalid-aws-cdn-cache:
runs-on: ubuntu-latest
needs:
- deploy-wallet-ui
- deploy-get-starknet
- prepare-deployment
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- name: Invalid AWS CDN Cache
run: |
echo "Distribution ID : $AWS_CLOUDFRONT_DISTRIBUTIONS_ID"
echo "$AWS_CLOUDFRONT_DISTRIBUTIONS_ID" | tr ',' '\n' | while read -r DISTRIBUTIONS_ID
do
echo "Processing Distribution ID : $DISTRIBUTIONS_ID"
INVALIDED_ID="$(aws cloudfront create-invalidation --distribution-id "$DISTRIBUTIONS_ID" --paths "/starknet/*" | grep Id | awk -F'"' '{ print $4}')"
echo "Waiting for invalidation $INVALIDED_ID"
aws cloudfront wait invalidation-completed --id "$INVALIDED_ID" --distribution-id "$DISTRIBUTIONS_ID"
echo "Invalidation $INVALIDED_ID completed"
done
env:
AWS_CLOUDFRONT_DISTRIBUTIONS_ID: ${{ needs.prepare-deployment.outputs.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}