-
Notifications
You must be signed in to change notification settings - Fork 10
260 lines (224 loc) · 9.96 KB
/
testCoverage.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: "Test coverage"
on:
schedule:
- cron: "0 */8 * * *"
workflow_dispatch:
inputs:
repo:
description: "Repo to run the tests on"
required: true
default: "microsoft/fluentui"
branch:
description: "Branch to run the tests on"
required: true
default: "master"
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
jobs:
run_tests:
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
outputs:
test_coverage: ${{ steps.run_tests.outputs }}
ubuntu_artifact_name: ${{ steps.ubuntu.outputs.COVERAGE_FILENAME_UBUNTU }}
windows_artifact_name: ${{ steps.windows.outputs.COVERAGE_FILENAME_WINDOWS }}
macos_artifact_name: ${{ steps.macos.outputs.COVERAGE_FILENAME_MACOS }}
steps:
- name: Checkout [master]
uses: actions/checkout@v4
- name: Checkout [react-charting]
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repo || 'microsoft/fluentui' }}
ref: ${{ github.event.inputs.branch || 'master' }}
path: repo1
- name: Show current directory
run: echo "$PWD" && ls
- name: Show repo1 directory
run: ls ./repo1
- name: Install packages
run: yarn --cwd ./tools/UnitTestApp && yarn --cwd ./repo1 && yarn --cwd ./repo1/packages/react-charting
- name: Change function visibility from private to public
id: setup
uses: ./tools/UnitTestApp/ChangeFunctionVisibility
with:
osType: ${{ matrix.os }}
- name: Build
run: yarn --cwd ./repo1 buildto @fluentui/react-charting
- name: Run the tests in windows
if: matrix.os == 'windows-latest'
run: cd ./repo1/packages/react-charting && powershell -Command "(Get-Content -Path ./config/tests.js) -replace 'PROD', 'TEST' | Set-Content -Path ./config/tests.js" && yarn jest --coverage --coverageDirectory ./coverage/${{matrix.os}} --verbose --coverageReporters=html --coverageReporters=text > coverageReport.txt
continue-on-error: true
- name: Run a single test in windows
if: matrix.os == 'windows-latest'
run: cd ./repo1/packages/react-charting && powershell -Command "(Get-Content -Path ./config/tests.js) -replace 'PROD', 'TEST' | Set-Content -Path ./config/tests.js" && yarn jest ./src/components/VerticalBarChart --coverage --coverageDirectory ./coverage/${{matrix.os}}_VerticalBarChart --verbose --coverageReporters=html
continue-on-error: true
- name: Run the tests in macos
if: matrix.os == 'macos-latest'
run: cd ./repo1/packages/react-charting && sed -i '' 's/PROD/TEST/g' ./config/tests.js && yarn jest --coverage --coverageDirectory ./coverage/${{matrix.os}} --verbose --coverageReporters=html --coverageReporters=text > coverageReport.txt
continue-on-error: true
- name: Run the tests in ubuntu
if: matrix.os == 'ubuntu-latest'
run: cd ./repo1/packages/react-charting && sed -i 's/PROD/TEST/g' ./config/tests.js && yarn jest --coverage --coverageDirectory ./coverage/${{matrix.os}} --verbose --coverageReporters=html --coverageReporters=text > coverageReport.txt
continue-on-error: true
- name: Generate coverage file name in windows
id: windows
if: matrix.os == 'windows-latest'
run: |
$NOW=& Get-Date -format yyyy-MM-dd
echo "COVERAGE_FILENAME=test_coverage_${{ matrix.os }}_$NOW" >> $env:GITHUB_ENV
- name: Generate coverage file name
run: |
echo "COVERAGE_FILENAME=test_coverage_${{ matrix.os }}_$(date +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_ENV
- name: Save coverage folder
uses: actions/upload-artifact@v4
with:
name: ${{matrix.os}}
path: ./repo1/packages/react-charting/coverage/${{matrix.os}}
- name: Save coverage file
uses: actions/upload-artifact@v4
with:
name: ${{env.COVERAGE_FILENAME}}_report
path: ./repo1/packages/react-charting/coverageReport.txt
- name: Save coverage folder for a single test
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: coverage_VBC
path: ./repo1/packages/react-charting/coverage/${{matrix.os}}_VerticalBarChart
- name: Extract the coverage summary table
if: matrix.os != 'windows-latest'
run: |
cd ./repo1/packages/react-charting
file_contents=$(cat coverageReport.txt)
table=$(echo "$file_contents" | awk '/----/,/^$/' | sed '1d;$d')
echo "$table"
- name: Extract the coverage summary table in windows
if: matrix.os == 'windows-latest'
run: |
cd ./repo1/packages/react-charting
$fileContents = Get-Content -Raw -Path "coverageReport.txt"
$tableRegex = "(?ms)----.*?^$"
$table = [regex]::Match($fileContents, $tableRegex)
echo "$table"
push_artifacts_to_repo:
needs: run_tests
runs-on: "ubuntu-latest"
permissions:
contents: write
steps:
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: "ubuntu-latest"
path: "./coverage/ubuntu-latest"
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: "macos-latest"
path: "./coverage/macos-latest"
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: "windows-latest"
path: "./coverage/windows-latest"
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: "coverage_VBC"
path: "./coverage/coverage_VBC"
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
pattern: test_coverage_*
path: "./coverage/coverageFiles"
- name: Generate html to show the latest coverages for all os types
run: |
cd ./coverage
echo "<!DOCTYPE html><html><head><title>Contributor Readiness</title></head><body><h1>View contributor guides and full test coverage reports</h1><ul><li><a href="https://uifabric.visualstudio.com/iss/_wiki/wikis/iss.wiki/280/Charting-Concepts">Contributor guides</a></li><li><a href="./windows-latest/index.html">Coverage for Windows</a></li><li><a href="./ubuntu-latest/index.html">Coverage for Ubuntu</a></li><li><a href="./macos-latest/index.html">Coverage for MacOS</a></li><li><a href="./coverage_VBC/index.html">Coverage for Vertical bar chart - Windows</a></li></ul></body></html>" >> index.html
shell: bash
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "./coverage"
- name: Directory disp
run: ls -a
- name: Checkout [test-coverage-artifacts]
uses: actions/checkout@v4
with:
path: repo
ref: test-coverage-artifacts
- name: Rename all txt reports to md and remove unnecessary lines
run: |
cd ./coverage
for f in $(find ./ -name '*.txt'); do
sed -i '/PASS/d' "$f"
sed -i '/FAIL/d' "$f"
sed -i '/yarn/d' "$f"
sed -i '/jest/d' "$f"
sed -i '1d' "$f"
statementCoveragePercent=$(echo $(awk '/All files/ {print}' $f) | awk -F'|' '{print $2}')
statementCoveragePercentTrimmed=$(echo "$statementCoveragePercent" | awk '{$1=$1; print}')
dir_path=$(dirname "$f")
file_name=$(basename "$f")
statementCovJson=$(jq -n \
--arg k1 "$statementCoveragePercentTrimmed" \
'{"statementCoverage": $k1}'
)
echo "$statementCovJson" > testCoverage.json
if [[ $f == *macos* ]]; then
echo "$statementCovJson" > macosCoverage.json
elif [[ $f == *windows* ]]; then
echo "$statementCovJson" > windowsCoverage.json
elif [[ $f == *ubuntu* ]]; then
echo "$statementCovJson" > ubuntuCoverage.json
fi
done
shell: bash
- name: Move coverage JSONs to root
run: |
mv -f ./repo/.github ./
mv -f ./repo/bundle-size ./
cd repo
rm -rf ./*
cd ..
mv -f ./.github ./repo/
mv -f ./bundle-size ./repo/
mv -f ./coverage/* ./repo/
cd repo
ls
continue-on-error: true
- uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: repo
branch: test-coverage-artifacts
build_and_deploy_job:
needs: push_artifacts_to_repo
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v3
with:
submodules: true
lfs: false
ref: test-coverage-artifacts
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PROUD_ISLAND_067885010 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "" # Built app content directory - optional
###### End of Repository/Build Configurations ######