Upload Coverage Report #99
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upload Coverage Report | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 5 * * *' # daily at 00:05 | |
jobs: | |
update-coverage-report: | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
env: | |
OUTPUT_DIR: _site/coverage | |
WORKFLOW_SPEC: > | |
dotnet-windows.yml: coverage-report-windows-net8.0-Release,coverage-report-windows-net9.0-Release,coverage-report-windows-net481-Release | | |
dotnet-ubuntu.yml: coverage-report-ubuntu-net8.0-Release,coverage-report-ubuntu-net9.0-Release | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # avoid shallow clone so that nbgv can do its work. | |
- name: Check for commits | |
id: check | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "update_report=true" >> "$GITHUB_OUTPUT" | |
else | |
commit_count=$(git log --oneline --since '24 hours ago' | wc -l) | |
echo "$commit_count found in the last 24 hours" | |
if [[ $commit_count -gt 0 ]]; then | |
echo "update_report=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "update_report=false" >> "$GITHUB_OUTPUT" | |
fi | |
fi | |
- name: 'Download latest successful build artifact' | |
run: | | |
IFS='|' read -ra wsspec <<< "${{ env.WORKFLOW_SPEC }}" | |
for ispec in "${wsspec[@]}"; do | |
IFS=':' read -ra spec <<< "$ispec" | |
workflow_id=$(echo ${spec[0]} | xargs) | |
echo "Getting last successful run for workflow '$workflow_id'" | |
run_id=$(gh run list -w $workflow_id --json conclusion,headBranch,databaseId --jq 'first(.[] | select(.conclusion | contains("success"))) | .databaseId') | |
if [ -z "$run_id" ]; then | |
echo "::error::No successful run found for workflow '$workflow_id'" 1>&2 | |
exit 1 | |
fi | |
echo "Last successful run for workflow '$workflow_id' is '$run_id'" | |
IFS=',' read -ra artifacts <<< "${spec[@]:1}" | |
for i in "${artifacts[@]}"; do | |
artifact_id=$(echo $i | xargs) | |
artifact_subdir=$OUTPUT_DIR/$(echo $artifact_id | sed 's/coverage-report-//g' | tr '[:upper:]' '[:lower:]') | |
echo "Downloading artifact '$artifact_id' for workflow '$workflow_id'" | |
gh run download $run_id -n $artifact_id -D $artifact_subdir || exit 1 | |
done | |
done | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: ${{ steps.check.outputs.update_report }} | |
- name: Generate Badges | |
run: | | |
for summary in $OUTPUT_DIR/**/Summary.json | |
do | |
echo "Generate badge for $summary" | |
badge_content=$(echo $(basename $(dirname $summary)) | sed -e 's/-release//g' -e 's/-debug//g' -e 's/_/__/g' -e 's/-/--/g' -e 's/ /_/g') | |
branch_coverage=$(printf "%.0f" $(jq ".summary.branchcoverage" $summary)) | |
line_coverage=$(printf "%.0f" $(jq ".summary.linecoverage" $summary)) | |
if (( branch_coverage < line_coverage )); then | |
min_coverage=$branch_coverage | |
else | |
min_coverage=$line_coverage | |
fi | |
if [[ $min_coverage -le 50 ]]; then | |
badge_color=red | |
elif [[ $min_coverage -le 70 ]]; then | |
badge_color=magenta | |
elif [[ $min_coverage -le 90 ]]; then | |
badge_color=yellow | |
else | |
badge_color=green | |
fi | |
badge_url="https://img.shields.io/badge/coverage_${badge_content}-b_${branch_coverage}%25_l_${line_coverage}%25-${badge_color}?style=flat-square" | |
echo "Badge URL: $badge_url" | |
curl -o $(dirname $summary)/badge.svg "$badge_url" | |
done | |
if: ${{ steps.check.outputs.update_report }} | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
if: ${{ steps.check.outputs.update_report }} | |
- name: Upload Pages | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: _site/coverage | |
if: ${{ steps.check.outputs.update_report }} | |
- name: Deploy Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
if: ${{ steps.check.outputs.update_report }} |