-
Notifications
You must be signed in to change notification settings - Fork 0
250 lines (215 loc) · 8.19 KB
/
release.yaml
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
name: Release
on:
workflow_dispatch:
push:
branches: ['main']
jobs:
test:
name: Test and build node
runs-on: ubuntu-latest
outputs:
environments: ${{ steps.environments.outputs.ENVIRONMENTS }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- name: Install node packages
run: npm ci --no-audit
- name: Run tests
run: npm test
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
- id: environments
name: Get environments list
run: echo "ENVIRONMENTS=$(./get-environments.js)" >> $GITHUB_OUTPUT
- id: zone_name
name: Get Cloudflare zone name
run: echo "CLOUDFLARE_ZONE_NAME=$(./get-cloudflare-zone-name.js)" >> $GITHUB_OUTPUT
deploy-assets:
name: Deploy assets to Cloudflare pages
runs-on: ubuntu-latest
needs: test
outputs:
capture-public-urls: ${{ steps.capture-public-urls.outputs }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- name: Install node packages
run: npm ci --no-audit
- name: Build public
run: ./build-public.js
- name: Remove .gitkeep files
run: rm -rf public/*/.gitkeep && rm -rf public/.gitkeep && rm -rf public-urls/.gitkeep
- name: Deploy assets to cloudflare
run: |
npx wrangler pages deploy public/ --project-name=${{ vars.CLOUDFLARE_ASSETS_PROJECT}} --commit-dirty=true
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
- name: Purge Cloudflare Pages Cache
uses: jakejarvis/cloudflare-purge-action@master
env:
CLOUDFLARE_TOKEN: ${{ secrets.CF_API_TOKEN }}
CLOUDFLARE_ZONE: ${{ vars.CLOUDFLARE_ZONE }}
- name: Save public urls as artifacts
uses: actions/upload-artifact@v3
with:
name: public-urls
path: public-urls
deploy-cloudflare-worker:
name: Deploy to AWS and Cloudflare workers
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
env: ${{fromJson(needs.test.outputs.environments)}}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- name: Install node packages
run: npm ci --omit=dev --no-audit
- name: serverless deploy
run: npx serverless deploy --stage ${{ matrix.env }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
- name: Put AWS credentials as Cloudflare Workers vars in wrangler.toml
run: |
echo -e "\n[env.${{ matrix.env }}.vars]" >> wrangler.toml
grep -v ServerlessDeploymentBucketName vars-${{ matrix.env }}.toml >> wrangler.toml
rm vars-${{ matrix.env }}.toml
- name: Get AWS Secret for put into wrangler
id: aws_secret
run: |
PRODUCER=$(aws ssm get-parameter --name /realtime-changes-${{ matrix.env }}-producer-user/secret --output text --query Parameter.Value)
echo "::add-mask::$PRODUCER"
echo "PRODUCER=$PRODUCER" >> $GITHUB_OUTPUT
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
- name: Deploy cloudflare workers
run: |
echo ${{ steps.aws_secret.outputs.PRODUCER }} | npx wrangler secret put AwsSecretAccessKey --env ${{ matrix.env }}
npx wrangler deploy --env ${{ matrix.env }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
put-secrets-into-infisical:
name: Put secrets into Infisical
needs:
- test
- deploy-cloudflare-worker
- deploy-assets
runs-on: ubuntu-latest
strategy:
matrix:
env: ${{fromJson(needs.test.outputs.environments)}}
steps:
- name: Download public urls from artifacts
uses: actions/download-artifact@v3
with:
name: public-urls
path: public-urls
- name: Put secrets into Infisical
run: |
curl --fail -s -o "$GET_VARS_SH" \
"https://${{ github.token }}@raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/$GET_VARS_SH"
chmod +x "$GET_VARS_SH"
VARS=$("./$GET_VARS_SH" ${{ matrix.env }})
while IFS= read -r LINE; do
IFS="=" read -r NAME VALUE <<< "$LINE"
VALUE=$(echo "$VALUE" | sed "s/^'//; s/'$//")
echo "Put secret: $NAME - $VALUE..."
ENDPOINT="https://app.infisical.com/api/v3/secrets/raw/$NAME"
CURRENT_VALUE=$( \
curl --location --silent \
"$ENDPOINT?workspaceId=${{ vars.INFISICAL_WORKSPACE_ID}}&environment=${{ matrix.env }}&secretPath=${{ vars.INFISICAL_PATH }}" \
--header 'Authorization: Bearer ${{ secrets.INFISICAL_TOKEN }}' | jq -r .secret.secretValue \
)
if [ $? -ne 0 ]; then
echo "Failed to check does variable exists"
exit 3
fi
if [ "$CURRENT_VALUE" == "$VALUE" ]; then
echo "Secret $NAME already exists with value $VALUE"
continue
elif [ "$CURRENT_VALUE" == "null" ]; then
echo "Secret $NAME not exists, create"
METHOD=POST
else
echo "Secret $NAME exists, update"
METHOD=PATCH
fi
curl --fail --location \
--silent --output /dev/null \
--write-out "%{http_code}\n" \
--request $METHOD \
--url "$ENDPOINT" \
--header 'Authorization: Bearer ${{ secrets.INFISICAL_TOKEN }}' \
--header 'Content-Type: application/json' \
--data-binary @- <<EOF
{
"workspaceId": "${{ vars.INFISICAL_WORKSPACE_ID}}",
"environment": "${{ matrix.env }}",
"type": "shared",
"secretPath": "${{ vars.INFISICAL_PATH }}",
"secretValue": "$VALUE"
}
EOF
done <<< "$VARS"
env:
GET_VARS_SH: get-environments-vars.sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
dispatch-pigeon:
runs-on: ubuntu-22.04
needs:
- put-secrets-into-infisical
steps:
- name: Pigeon App Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.TOKEN_TO_RUN_GITHUB_ACTION }}
repository: kneu-messenger-pigeon/pigeon-app
event-type: environments-updated
client-payload: '{"initiator": "${{ github.event.repository.name }}"}'
dispatch-browser-integration-tests:
runs-on: ubuntu-22.04
needs:
- put-secrets-into-infisical
steps:
- name: Pigeon App Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.TOKEN_TO_RUN_GITHUB_ACTION }}
repository: kneu-messenger-pigeon/realtime-capture-browser-integration-tests
event-type: realtime-capture-deployed
client-payload: '{"initiator": "${{ github.event.repository.name }}"}'