-
Notifications
You must be signed in to change notification settings - Fork 1
230 lines (196 loc) · 8.15 KB
/
CI.yml
File metadata and controls
230 lines (196 loc) · 8.15 KB
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: CI
on:
push:
branches: [ "master" ]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
permissions:
security-events: write
packages: read
actions: read
contents: write
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.14.0
uses: actions/setup-node@v4
with:
node-version: 20.14.0
- run: npm ci
working-directory: src
- run: npm run lint
working-directory: src
- run: npm run build
working-directory: src
- name: Run unit tests
run: npm run ci-test
working-directory: src
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: Unit Test Results
files: |
src/test-results/unit-tests/*.xml
- name: Code Coverage Summary Report (Unit Tests)
uses: irongut/CodeCoverageSummary@v1.3.0
if: always()
with:
filename: src/test-results/unit-tests/code-coverage/cobertura/cobertura-coverage.xml
badge: true
format: 'markdown'
output: 'both'
hide_complexity: true
- name: Add title to coverage report
run: |
"# Unit Tests Code Coverage" | Set-Content -Path unit-tests-code-coverage-results.md
Get-Content -Path code-coverage-results.md | Add-Content -Path unit-tests-code-coverage-results.md
shell: pwsh
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: always()
with:
recreate: true
header: Unit Tests Code Coverage
path: unit-tests-code-coverage-results.md
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
build-mode: none
config-file: ./.github/codeql/codeql-config.yml
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:javascript-typescript"
- name: Copy staticwebapp.config.json
run: cp src/staticwebapp.config.json src/dist/dive-intelligence/browser/staticwebapp.config.json
# deploy PR to preview site
- name: Find PR comment to update
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: This PR has been deployed to a [preview site](https://kind-beach-03c93dc0f-pr${{ github.event.pull_request.number }}.eastus2.3.azurestaticapps.net/) for testing.
- name: Create/update PR comment with in progress message
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
id: wip-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
:construction: :construction: The application is being deployed to a preview site. Please wait for the deployment to complete. :construction: :construction:
- name: Deploy to preview site
if: github.event_name == 'pull_request'
run: npm run deploy -- --env "pr${{ github.event.pull_request.number }}" --deployment-token ${{ secrets.SWA_DEPLOYMENT_TOKEN }}
working-directory: src
- name: Get current date
if: github.event_name == 'pull_request'
id: date
run: echo "date=$(date --utc +'%FT%TZ')" >> $GITHUB_OUTPUT
- name: Update PR comment with link to preview site
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.wip-comment.outputs.comment-id }}
edit-mode: replace
body: |
This PR has been deployed to a [preview site](https://kind-beach-03c93dc0f-pr${{ github.event.pull_request.number }}.eastus2.3.azurestaticapps.net/) for testing.
This site will automatically be deleted when the PR is merged.
Last deployed: ${{ steps.date.outputs.date }} (UTC)
- name: Install Playwright Browsers
run: npx playwright install --with-deps
working-directory: src
- name: Run UI automation tests on preview site
if: github.event_name == 'pull_request'
run: npm run playwright
working-directory: src
env:
PLAYWRIGHT_BASE_URL: 'https://kind-beach-03c93dc0f-pr${{ github.event.pull_request.number }}.eastus2.3.azurestaticapps.net'
- name: Run UI automation tests locally
if: github.event_name != 'pull_request'
run: npm run playwright
working-directory: src
- name: Publish UI Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: UI Test Results
files: |
src/test-results/playwright/*.xml
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: src/test-results/playwright/
# deploy to production
- name: Set Instrumentation Key
if: github.ref == 'refs/heads/master'
uses: jossef/action-set-json-field@v2.2
with:
file: src/dist/dive-intelligence/browser/assets/config.json
field: instrumentationKey
value: ${{ vars.INSTRUMENTATION_KEY }}
- name: Upload Source Maps
if: github.ref == 'refs/heads/master'
run: az storage blob upload-batch --connection-string "${{ secrets.SOURCE_MAPS_CONNECTION_STRING}}" --source src/dist/dive-intelligence/browser --destination sourcemaps --overwrite true
- name: Deploy to Azure Static Web Apps
if: github.ref == 'refs/heads/master'
run: npm run deploy -- --env production --deployment-token ${{ secrets.SWA_DEPLOYMENT_TOKEN }}
working-directory: src
delete-preview-site:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
pull-requests: write
id-token: write
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Find PR comment to update
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: This PR has been deployed to a [preview site](https://kind-beach-03c93dc0f-pr${{ github.event.pull_request.number }}.eastus2.3.azurestaticapps.net/) for testing.
- name: Update PR comment with being deleted message
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
id: deleting-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
:construction: :construction: The preview site for this PR is being deleted. :construction: :construction:
- name: Delete preview site
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: az staticwebapp environment delete --name DiveIntelligence --environment-name "pr${{ github.event.pull_request.number }}" --resource-group DiveIntelligence --yes
- name: Update PR comment to indicate site has been deleted
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.deleting-comment.outputs.comment-id }}
edit-mode: replace
body: |
:no_entry_sign: :no_entry_sign: The preview site for this PR has been deleted. :no_entry_sign: :no_entry_sign: