-
Notifications
You must be signed in to change notification settings - Fork 1.1k
203 lines (179 loc) · 8.03 KB
/
pr-automation.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
name: PR automation
on:
pull_request:
types: [opened, reopened, synchronize, labeled]
workflow_dispatch:
inputs:
shards:
type: number
description: "Number of shards to use for parallel testing"
required: false
default: 2 # This is the default only for manually (re-)triggered runs. Default for runs triggered by pull requests is configured via `jobs.initialize-cloud.generate-shard-matrix.env.CONCURRENCY`.
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
initialize-cloud:
runs-on: ubuntu-22.04
outputs:
POOL_NAME: ${{ steps.cloud_variables.outputs.POOL_NAME }}
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BASE_URL: ${{ steps.cloud_variables.outputs.BASE_URL }}
BASE_URL_DOMAIN: ${{ steps.cloud_variables.outputs.BASE_URL_DOMAIN }}
API_URL: ${{ steps.cloud_variables.outputs.API_URL }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}
BACKUP_VER: ${{ steps.cloud_variables.outputs.BACKUP_VER }}
BACKUP_NAME: ${{ steps.cloud_variables.outputs.BACKUP_NAME }}
SHARD_MATRIX: ${{ steps.generate-shard-matrix.outputs.SHARD_MATRIX }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: ./.github/actions
- name: Generate variables
id: cloud_variables
uses: ./.github/actions/prepare-tests-variables
with:
CLI_TOKEN: ${{ secrets.STAGING_TOKEN }}
MODE: pull-request
- name: Prepare instances
uses: ./.github/actions/prepare-instance
with:
STRATEGY: reload
CLI_TOKEN: ${{ secrets.STAGING_TOKEN }}
BASE_URL: ${{ steps.cloud_variables.outputs.BASE_URL }}
API_URL: ${{ steps.cloud_variables.outputs.API_URL }}
POOL_NAME: ${{ steps.cloud_variables.outputs.POOL_NAME }}
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}
SALEOR_CLOUD_SERVICE: ${{ steps.cloud_variables.outputs.SALEOR_CLOUD_SERVICE }}
- name: Generate shard matrix
id: generate-shard-matrix
env:
CONCURRENCY: ${{ inputs.shards || 2 }}
run: |
MAX_CONCURRENCY=4
if [ "$CONCURRENCY" -gt "$MAX_CONCURRENCY" ]; then
echo "[WARN] The requested number of shards ($CONCURRENCY) exceeds maximum allowed value ($MAX_CONCURRENCY). Using $MAX_CONCURRENCY shards instead." >&2
CONCURRENCY=$MAX_CONCURRENCY
fi
shard_matrix=() # Initialize an empty array to store the shard values.
for i in $(seq 1 "$CONCURRENCY"); do # Loop through the numbers from 1 to $CONCURRENCY.
shard_matrix+=("\"$i/$CONCURRENCY\"") # For each number i, append a string in the format "${i}/${CONCURRENCY}" to the shard_matrix array.
done
shard_matrix=( $(IFS=,; echo "[${shard_matrix[*]}]") ) # Join the elements of the shard_matrix array with commas and wrap the result in square brackets to create a valid JSON array string.
echo "SHARD_MATRIX=${shard_matrix[0]}" >> "$GITHUB_OUTPUT"
deploy-dashboard:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
outputs:
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
runs-on: ubuntu-22.04
needs: initialize-cloud
permissions:
deployments: write
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Start deployment
uses: bobheadxi/deployments@88ce5600046c82542f8246ac287d0a53c461bca3
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ needs.initialize-cloud.outputs.POOL_NAME }}
ref: ${{ github.head_ref }}
- name: Cache node modules
uses: actions/cache@v3
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: Build dashboard
env:
## backward compatibility for older versions
API_URI: ${{ needs.initialize-cloud.outputs.API_URL }}
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
APPS_MARKETPLACE_API_URL: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APP_MOUNT_URI: /
STATIC_URL: /
IS_CLOUD_INSTANCE: true
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
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
env:
AWS_TEST_DEPLOYMENT_BUCKET: ${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}
BASE_URL_DOMAIN: ${{ needs.initialize-cloud.outputs.BASE_URL_DOMAIN }}
run: aws s3 sync ./build/dashboard "s3://${AWS_TEST_DEPLOYMENT_BUCKET}/${BASE_URL_DOMAIN}"
- name: Invalidate cache
env:
AWS_TEST_CF_DIST_ID: ${{ secrets.AWS_TEST_CF_DIST_ID }}
BASE_URL_DOMAIN: ${{ needs.initialize-cloud.outputs.BASE_URL_DOMAIN }}
run: aws cloudfront create-invalidation --distribution-id "$AWS_TEST_CF_DIST_ID" --paths "/${BASE_URL_DOMAIN}/*"
- name: Update deployment status
uses: bobheadxi/deployments@88ce5600046c82542f8246ac287d0a53c461bca3
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env_url: ${{ needs.initialize-cloud.outputs.BASE_URL }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ needs.initialize-cloud.outputs.POOL_NAME }}
- name: Prepare accounts
id: accounts
uses: ./.github/actions/prepare-accounts
with:
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
run-tests:
if: ${{ contains(github.event.pull_request.labels.*.name, 'run pw-e2e') }}
runs-on: ubuntu-22.04
needs: [initialize-cloud, deploy-dashboard]
strategy:
fail-fast: false
matrix:
shard: ${{ fromJson(needs.initialize-cloud.outputs.SHARD_MATRIX) }}
steps:
- uses: actions/checkout@v4
- name: Run playwright tests
uses: ./.github/actions/run-pw-tests
with:
SHARD: ${{ matrix.shard }}
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}
ACCOUNTS: ${{ needs.deploy-dashboard.outputs.ACCOUNTS }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
merge-reports:
if: "!cancelled() && contains(github.event.pull_request.labels.*.name, 'run pw-e2e')"
needs: run-tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Merge playwright reports
uses: ./.github/actions/merge-pw-reports