Skip to content

Test coverage

Test coverage #27

Workflow file for this run

name: 'Test coverage'
on:
schedule:
- cron: "0 0 * * *"
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: read
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 }}
ref: ${{ github.event.inputs.branch }}
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
- 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
- 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
- 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
- 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"
publish_to_site:
needs: run_tests
runs-on: 'ubuntu-latest'
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: Rename folders
run: |
cd ./coverage
for dir in *; do
if [[ $name == *"ubuntu"* ]] && [[ $name != *"_report"* ]]; then
mv "$dir" "ubuntu"
elif [[ $name == *"macos"* ]] && [[ $name != *"_report"* ]]; then
mv "$dir" "macos"
elif [[ $name == *"VBC"* ]] && [[ $name != *"_report"* ]]; then
mv "$dir" "VBC"
elif [[ $name == *"windows"* ]] && [[ $name != *"_report"* ]]; then
mv "$dir" "windows"
fi
done
shell: bash
- name: Show the coverage folder
run: |
cd ./coverage
ls
- 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: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Url after deployment
run: echo "${{ steps.deployment.outputs.page_url }}"