forked from saleor/saleor-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (212 loc) · 8.76 KB
/
test-env-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
name: TEST-ENV-DEPLOYMENT
# Build and deploy test instance for every pull request
on: [pull_request]
jobs:
deploy:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
runs-on: ubuntu-latest
outputs:
base_URL: ${{ steps.set-domain.outputs.domain }}
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@3.1.0
- name: Start deployment
uses: bobheadxi/deployments@v0.4.2
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }}
ref: ${{ github.head_ref }}
- name: Start storybook deployment
uses: bobheadxi/deployments@v0.4.2
id: storybook-deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: storybook ${{ env.GITHUB_HEAD_REF_SLUG_URL }}
ref: ${{ github.head_ref }}
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-qa-${{ env.cache-name }}-
${{ runner.os }}-qa-
${{ runner.os }}-
- name: Install deps
run: |
npm ci
- name: Get custom API_URI
id: api_uri
# Search for API_URI in PR description
env:
pull_request_body: ${{ github.event.pull_request.body }}
prefix: API_URI=
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/?
run: |
echo "::set-output name=custom_api_uri::$(echo $pull_request_body | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)"
- name: Get MARKETPLACE_URL
id: marketplace_url
# Search for MARKETPLACE_URL in PR description
env:
pull_request_body: ${{ github.event.pull_request.body }}
prefix: MARKETPLACE_URL=
pattern: (http|https)://[a-zA-Z0-9.-]+/?
run: |
echo "::set-output name=custom_marketplace_url::$(echo $pull_request_body | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)"
- name: Run build
env:
# Use custom API_URI or the default one
API_URI: ${{ steps.api_uri.outputs.custom_api_uri || 'https://qa.staging.saleor.cloud/graphql/' }}
MARKETPLACE_URL: ${{ steps.marketplace_url.outputs.custom_marketplace_url }}
APP_MOUNT_URI: /
STATIC_URL: /
IS_CLOUD_INSTANCE: true
run: |
npm run build
- name: Run build storybook
run: |
npm run build-storybook
- name: Set domain
id: set-domain
# Set test instance domain based on branch name slug
run: |
echo "::set-output name=domain::${{ env.GITHUB_HEAD_REF_SLUG_URL }}.dashboard.saleor.rocks"
- 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: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy to S3
run: |
aws s3 sync ./build/dashboard s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ steps.set-domain.outputs.domain }}
aws s3 sync ./build/storybook s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ steps.set-domain.outputs.domain }}/storybook
- name: Invalidate cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_TEST_CF_DIST_ID }} --paths "/${{ steps.set-domain.outputs.domain }}/*"
- name: Update deployment status
uses: bobheadxi/deployments@v0.4.2
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env_url: https://${{ steps.set-domain.outputs.domain }}/
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update storybook deployment status
uses: bobheadxi/deployments@v0.4.2
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env_url: https://${{ steps.set-domain.outputs.domain }}/storybook/index.html
deployment_id: ${{ steps.storybook-deployment.outputs.deployment_id }}
prepare-tests:
runs-on: ubuntu-latest
outputs:
tags: ${{steps.get_tags.outputs.result}}
containers: ${{ steps.get_containers.outputs.result}}
steps:
- name: Get tags
id: get_tags
uses: actions/github-script@v6
env:
pullRequestBody: ${{ github.event.pull_request.body }}
with:
result-encoding: string
script: |
const { pullRequestBody } = process.env
const tags = ["@critical"];
try{
const removedPullRequestBodyBeforeTests = pullRequestBody.split(`### Do you want to run more stable tests?`);
const removedPullRequestBodyAfterTests = removedPullRequestBodyBeforeTests[1].split(`CONTAINERS`);
let tagsInString = removedPullRequestBodyAfterTests[0];
tagsInString = tagsInString.split('\n');
tagsInString.forEach(line => {
if (line.includes('[x]')) tags.push(line.replace(/[0-9]+\. \[x\] /, "@stable+@"))
});
const tagsToReturn = tags.join(",").toString();
return tagsToReturn.replace(/\r/g, '')
}catch{
return '@critical'
}
- name: get-containers
id: get_containers
uses: actions/github-script@v6
env:
pullRequestBody: ${{ github.event.pull_request.body }}
with:
script: |
const { pullRequestBody } = process.env
const containers = [];
const numberOfContainersRegex = /CONTAINERS=(\d*)/
const numberOfContainers = pullRequestBody.match(numberOfContainersRegex);
for(let i=1; i<=numberOfContainers[1]; i++){
containers.push(i)
}
return {"containers": containers}
- name: echo-tags
run: |
echo ${{steps.get_tags.outputs.result}}
cypress-run-selected:
runs-on: ubuntu-latest
needs: [prepare-tests, deploy]
container: cypress/browsers:node14.16.0-chrome89-ff86
strategy:
fail-fast: false
max-parallel: 10
matrix: ${{ fromJson(needs.prepare-tests.outputs.containers) }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Get API_URI
id: api_uri
# Search for API_URI in PR description and use default if not defined
env:
pull_request_body: ${{ github.event.pull_request.body }}
prefix: API_URI=
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/?
fallback_uri: ${{ secrets.CYPRESS_API_URI }}
run: |
echo "::set-output name=custom_api_uri::$(echo $pull_request_body | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1 | { read custom_uri; if [ -z "$custom_uri" ]; then echo "$fallback_uri"; else echo "$custom_uri"; fi })"
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-qa-${{ env.cache-name }}-
${{ runner.os }}-qa-
${{ runner.os }}-
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm install
- name: Cypress run critical
uses: cypress-io/github-action@v4
env:
API_URI: ${{ steps.api_uri.outputs.custom_api_uri }}
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
CYPRESS_baseUrl: https://${{needs.deploy.outputs.base_URL}}
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
CYPRESS_SECOND_USER_NAME: ${{ secrets.CYPRESS_SECOND_USER_NAME }}
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
COMMIT_INFO_MESSAGE: Critical tests triggered on PR - ${{ github.ref_name }}
CYPRESS_grepTags: ${{ needs.prepare-tests.outputs.tags }}
with:
parallel: true
group: 'UI - Chrome'
record: true
tag: Critical, ${{github.event.action}}