-
Notifications
You must be signed in to change notification settings - Fork 37
189 lines (188 loc) · 8.15 KB
/
build-test-e2e.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
name: 'Build/Run End-to-End Tests'
on: push
env:
BUILD_ARTIFACT_NAME: swc-war
BUILD_DIR: target
BUILD_NAME: portal-develop-SNAPSHOT.war
NODE_VERSION: 18.16.0
PW_ALL_BLOBS_DIR: all-blob-reports
jobs:
lint-e2e:
# Run in Sage repo on develop or release- branches
# and on all branches in user-owned forks
if: ${{ github.ref_name == 'develop' || startsWith(github.ref_name, 'release-') || github.actor == github.repository_owner }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint E2E tests
run: yarn e2e:lint
build:
# Run in Sage repo on develop or release- branches
# and on all branches in user-owned forks
if: ${{ github.ref_name == 'develop' || startsWith(github.ref_name, 'release-') || github.actor == github.repository_owner }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build SWC
uses: ./.github/workflows/build
with:
mvn_goal: package
- name: Upload build to GitHub Actions Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.BUILD_ARTIFACT_NAME }}
path: '${{ env.BUILD_DIR }}/${{ env.BUILD_NAME }}'
retention-days: 1
playwright-tests:
needs: [build]
runs-on: 'macos-12'
timeout-minutes: 60
# Ensure that at most one playwright-tests job will run at a time in Sage-Bionetworks repo,
# but allow multiple playwright-test jobs to run concurrently in forked repos
# Per https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
# "When a concurrent job or workflow is queued, if another job or workflow
# using the same concurrency group in the repository is in progress,
# the queued job or workflow will be pending. Any previously pending job or
# workflow in the concurrency group will be cancelled."
# Related discussion here: https://github.com/orgs/community/discussions/5435
concurrency:
group: ${{ github.repository_owner == 'Sage-Bionetworks' && format('${0}-${1}', github.workflow, '-playwright-tests') || format('${0}-${1}', github.run_id, matrix.shard ) }}
strategy:
max-parallel: ${{ github.repository_owner == 'Sage-Bionetworks' && 1 || 3 }}
fail-fast: false
matrix:
shard: [1/3, 2/3, 3/3]
env:
CONTAINER_NAME: 'swc-tomcat'
CI: true
DESTINATION_BUCKET: e2e-reports-bucket-bucket-1p1qz6p48t4uy
REPORT_ID: ${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}
# Allow OIDC Integration (so we can assume the AWS role to deploy)
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Check colima and lima version
if: runner.os == 'macos'
run: |
# Get colima and lima versions
limactl --version
colima version
- name: Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install docker
colima start
- name: Download build from GitHub Actions Artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.BUILD_ARTIFACT_NAME }}
path: ${{ env.BUILD_DIR }}
- name: Run SWC on Tomcat
run: |
docker run \
--name "${{ env.CONTAINER_NAME }}" \
-d --rm \
-p 8888:8080 \
-v "/$(pwd)/${{ env.BUILD_DIR }}/${{ env.BUILD_NAME }}:/usr/local/tomcat/webapps/ROOT.war" \
-v "/$(pwd)/e2e_workflow/settings.xml":/root/.m2/settings.xml \
tomcat:9.0
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile --network-timeout 1000000
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Check for common errors
run: |
if [ ! -e "/$(pwd)/${{ env.BUILD_DIR }}/${{ env.BUILD_NAME }}" ]; then
echo "::error:: downloaded WAR not found at expected location"
exit 1
fi
if [[ $(docker ps --filter "name=${{ env.CONTAINER_NAME }}" --format '{{.Names}}') != "${{ env.CONTAINER_NAME }}" ]]; then
echo "::error:: SWC docker container is not running"
exit 1
fi
if ! docker port "${{ env.CONTAINER_NAME }}" | grep -q "8080/tcp -> 0.0.0.0:8888"; then
echo "::error:: SWC container configuration does not specify expected port mapping"
exit 1
fi
if [[ "$(docker exec "${{ env.CONTAINER_NAME }}" bash -c "curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080")" != "200" ]]; then
echo "::error:: SWC container port not accessible from container"
exit 1
fi
if [[ "$(docker exec "${{ env.CONTAINER_NAME }}" bash -c "curl -sS -o /dev/null -w '%{http_code}\n' http://172.17.0.1:8888")" != "200" ]]; then
echo "::error:: SWC host port not accessible from container"
exit 1
fi
if ! netstat -an | grep -q "8888"; then
echo "::error:: host is not listening to SWC host port"
exit 1
fi
if [[ "$(curl -w '%{http_code}' --output /dev/null --silent --fail --show-error http://127.0.0.1:8888 2>&1)" != "200" ]]; then
echo "::error:: SWC host port not accessible from host"
exit 1
fi
- name: Run Playwright tests
env:
ADMIN_PAT: ${{ secrets.ADMIN_PAT }}
TRACE_TOGGLE: ${{ github.repository_owner == 'Sage-Bionetworks' && 'on' || 'off'}}
run: yarn playwright test --shard ${{ matrix.shard }} --trace=${{ env.TRACE_TOGGLE }}
- name: Assume AWS Role
if: ${{ github.repository_owner == 'Sage-Bionetworks' && always() }}
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::449435941126:role/sagebase-github-oidc-synapsedev-e2e-infra
role-session-name: GitHubActions-${{ github.repository_owner }}-${{ github.event.repository.name }}-${{ github.run_id }}
role-duration-seconds: 1200
- name: Upload blob report to S3
if: ${{ github.repository_owner == 'Sage-Bionetworks' && always() }}
run: |
aws s3 sync ./blob-report --region us-east-1 s3://${{ env.DESTINATION_BUCKET }}/${{ env.REPORT_ID }}/
- name: Upload blob report to GitHub Actions Artifacts
uses: actions/upload-artifact@v3
if: ${{ github.repository_owner != 'Sage-Bionetworks' && always() }}
with:
name: ${{ env.PW_ALL_BLOBS_DIR }}
path: blob-report
retention-days: 1
- name: Stop Tomcat
if: always()
run: docker stop "${{ env.CONTAINER_NAME }}"
- name: Stop Colima
if: runner.os == 'macos'
run: colima stop
merge-reports:
# Merge reports after playwright-tests, even if some shards have failed
# But skip this job if the previous job was cancelled or skipped
if: ${{ github.repository_owner != 'Sage-Bionetworks' && !cancelled() && needs.playwright-tests.result != 'skipped' }}
needs: [playwright-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.PW_ALL_BLOBS_DIR }}
path: ${{ env.PW_ALL_BLOBS_DIR }}
- name: Merge into HTML Report
run: yarn playwright merge-reports --reporter html ./"${{ env.PW_ALL_BLOBS_DIR }}"
- name: Upload HTML report
uses: actions/upload-artifact@v3
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14