Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
srmukher authored Jan 31, 2024
2 parents 8dc2265 + 53946ac commit 724565c
Show file tree
Hide file tree
Showing 14 changed files with 1,260 additions and 49 deletions.
224 changes: 176 additions & 48 deletions .github/workflows/testCoverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test coverage'
name: "Test coverage"
on:
schedule:
- cron: "0 */8 * * *"
Expand All @@ -16,10 +16,10 @@ on:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
contents: write
pages: write
id-token: write

jobs:
run_tests:
strategy:
Expand All @@ -32,13 +32,13 @@ jobs:
windows_artifact_name: ${{ steps.windows.outputs.COVERAGE_FILENAME_WINDOWS }}
macos_artifact_name: ${{ steps.macos.outputs.COVERAGE_FILENAME_MACOS }}

steps:
steps:
- name: Checkout [master]
uses: actions/checkout@v4

- name: Checkout [react-charting]
uses: actions/checkout@v4
with:
with:
repository: ${{ github.event.inputs.repo || 'microsoft/fluentui' }}
ref: ${{ github.event.inputs.branch || 'master' }}
path: repo1
Expand All @@ -50,24 +50,24 @@ jobs:
run: ls ./repo1

- name: Install packages
run: yarn --cwd ./tools/UnitTestApp && yarn --cwd ./repo1 && yarn --cwd ./repo1/packages/react-charting
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
run: yarn --cwd ./repo1 buildto @fluentui/react-charting

- name: Run the tests in windows
if: matrix.os == 'windows-latest'
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'
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

Expand All @@ -83,14 +83,14 @@ jobs:

- name: Generate coverage file name in windows
id: windows
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-latest'
run: |
$NOW=& Get-Date -format yyyy-MM-dd
echo "COVERAGE_FILENAME=test_coverage_${{ matrix.os }}_$NOW" >> $env:GITHUB_ENV
$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
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
Expand All @@ -114,48 +114,74 @@ jobs:
- 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"
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"
cd ./repo1/packages/react-charting
$fileContents = Get-Content -Raw -Path "coverageReport.txt"
$tableRegex = "(?ms)----.*?^$"
$table = [regex]::Match($fileContents, $tableRegex)
echo "$table"
publish_to_site:
push_artifacts_to_repo:
needs: run_tests
runs-on: 'ubuntu-latest'
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: "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: 'macos-latest'
path: './coverage/macos-latest'
name: "windows-latest"
path: "./coverage/windows-latest"

- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: 'windows-latest'
path: './coverage/windows-latest'
name: "coverage_VBC"
path: "./coverage/coverage_VBC"

- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: 'coverage_VBC'
path: './coverage/coverage_VBC'
name: ${{env.COVERAGE_FILENAME_MACOS}}
path: './coverage/coverageFileMacOS'
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: ${{env.COVERAGE_FILENAME_UBUNTU}}
path: "./coverage/coverageFileUbuntu"
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
name: ${{env.COVERAGE_FILENAME_WINDOWS}}
path: './coverage/coverageFileWindows'
- name: Download all artifacts to publish together
uses: actions/download-artifact@v4
with:
pattern: test_coverage_*
path: "./coverage/coverageFiles"

- name: "Check coverage file"
run: cd ./coverage/coverageFiles && ls -a
- name: Rename folders
run: |
cd ./coverage
Expand All @@ -172,28 +198,130 @@ jobs:
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
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'
path: "./coverage"

- name: Directory disp
run: ls -a

- name: Checkout [main]
uses: actions/checkout@v4
with:
path: repo
ref: main

- name: Remove old artifacts
run: |
rm -rf ./repo/docs/coverageFiles
cd ./repo/docs
ls -a
shell: bash
- name: Rename all txt reports to md and remove unnecessary lines
run: |
cd ./coverage/coverageFiles
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}')
sed -i "1i\![Test Coverage Badge](https://img.shields.io/badge/Test_Coverage-$statementCoveragePercentTrimmed-mediumgreen)\n" "$f"
sed -i '2i\ ' "$f"
sed -i '3i\[Click here for a detailed report](https://fluentui-charting-test-coverage.netlify.app/)' "$f"
dir_path=$(dirname "$f")
file_name=$(basename "$f")
new_file_name="TestCoverageReport.md"
mv -- "$f" "$dir_path/$new_file_name"
done
ls -lR
- name: Move coverage to docs
run: ls -a && mv -f coverage/coverageFiles repo/docs && cd repo/docs && ls -a
- name: Rename folder names for reports
run: |
cd ./repo/docs/coverageFiles
ls -lR
for dir in *; do
if [[ $dir == *"ubuntu"* ]]; then
mv "$dir/TestCoverageReport.md" "Ubuntu Test Coverage Report.md"
rm -rf $dir
elif [[ $dir == *"macos"* ]]; then
mv "$dir/TestCoverageReport.md" "MacOS Test Coverage Report.md"
rm -rf $dir
elif [[ $dir == *"windows"* ]]; then
mv "$dir/TestCoverageReport.md" "Windows Test Coverage Report.md"
rm -rf $dir
fi
done
ls -lR
shell: bash
- uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: repo
branch: main
- name: Change branch to test-coverage-artifacts and move new artifacts to folder
run: |
cd repo
if [ `git branch | grep test-coverage-artifacts` ]
then
git checkout test-coverage-artifacts
git pull origin test-coverage-artifacts
else
git checkout -b test-coverage-artifacts
fi
rm -rf ./*
cd ..
mv -f ./coverage/* ./repo/
- uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: repo
branch: test-coverage-artifacts
push_options: "--force"


- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
deploy:
needs: push_artifacts_to_repo
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
with:
ref: main
- uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn
- name: List files in docs
run: cd docs && ls -a
- name: Install dependencies
run: cd apps/docsite && yarn install --frozen-lockfile
- name: Build website
run: cd apps/docsite && yarn build

- name: Url after deployment
run: echo "${{ steps.deployment.outputs.page_url }}"
# Popular action to deploy to GitHub Pages:
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Build output to publish to the `gh-pages` branch:
publish_dir: ./apps/docsite/build
# The following lines assign commit authorship to the official
# GH-Actions bot for deploys to `gh-pages` branch:
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
# The GH actions bot is used by default if you didn't specify the two fields.
# You can swap them out with your own user credentials.
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
3 changes: 2 additions & 1 deletion apps/docsite/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import HomepageFeatures from '@site/src/components/HomepageFeatures';
import Heading from '@theme/Heading';

import styles from './index.module.css';
import sidebars from '@site/sidebars';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
Expand All @@ -19,7 +20,7 @@ function HomepageHeader() {
<div className={styles.buttons}>
<Link
className="button button--secondary button--lg"
to="/docs/Fluent-React-Charting">
to={`/docs/${sidebars.tutorialSidebar[0]}`}>
Getting Started 🚈
</Link>
</div>
Expand Down
Loading

0 comments on commit 724565c

Please sign in to comment.