Skip to content

Commit

Permalink
Produce GitHub Pages from workflows (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
cklutz authored Oct 11, 2024
1 parent 6bef65f commit e587a86
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 13 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/dotnet-reusable-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:

env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
LC_PIVOT: ${{ inputs.tfm }}-${{ inputs.configuration }}

steps:
- name: Checkout
Expand All @@ -60,8 +59,10 @@ jobs:
shopt -s nocasematch
if [[ "${{ inputs.runs-on }}" == *"windows"* ]]; then
echo "LC_COVERAGE_EXCLUDE_CLASS_FILTER=-*.Linux.*" >> "$GITHUB_OUTPUT"
echo "LC_PIVOT=windows-${{ inputs.tfm }}-${{ inputs.configuration }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ inputs.runs-on }}" == *"ubuntu"* ]]; then
echo "LC_COVERAGE_EXCLUDE_CLASS_FILTER=-*.Windows.*" >> "$GITHUB_OUTPUT"
echo "LC_PIVOT=ubuntu-${{ inputs.tfm }}-${{ inputs.configuration }}" >> "$GITHUB_OUTPUT"
fi
if [[ "${{ inputs.code-coverage }}" == "true" ]]; then
echo "LC_COVERAGE_TEST_OPTIONS=--collect \"Code Coverage;Format=Cobertura\"" >> "$GITHUB_OUTPUT"
Expand All @@ -83,20 +84,20 @@ jobs:
${{ steps.configure.outputs.LC_COVERAGE_TEST_OPTIONS }}
--verbosity normal
--logger trx
--results-directory "TestResults-${{ env.LC_PIVOT }}"
--results-directory "TestResults-${{ steps.configure.outputs.LC_PIVOT }}"
- name: Upload TestResults
uses: actions/upload-artifact@v4
with:
name: test-results-${{ env.LC_PIVOT }}
path: TestResults-${{ env.LC_PIVOT }}
name: test-results-${{ steps.configure.outputs.LC_PIVOT }}
path: TestResults-${{ steps.configure.outputs.LC_PIVOT }}
if: ${{ always() }}

- name: Generage coverage report
uses: danielpalme/ReportGenerator-GitHub-Action@5.3.11
with:
reports: '${{ github.workspace }}/TestResults-${{ env.LC_PIVOT }}/**/*.cobertura.xml'
targetdir: '${{ github.workspace }}/CoverageReport-${{ env.LC_PIVOT }}'
reports: '${{ github.workspace }}/TestResults-${{ steps.configure.outputs.LC_PIVOT }}/**/*.cobertura.xml'
targetdir: '${{ github.workspace }}/CoverageReport-${{ steps.configure.outputs.LC_PIVOT }}'
reporttypes: 'Html;Html_Dark;Cobertura;MarkdownSummaryGithub;Badges;JsonSummary'
assemblyfilters: '-*.Tests;-LCTestTarget*'
classfilters: '${{ steps.configure.outputs.LC_COVERAGE_EXCLUDE_CLASS_FILTER }}'
Expand All @@ -105,16 +106,16 @@ jobs:
if: ${{ inputs.code-coverage && inputs.configuration == inputs.code-coverage-configuration }}

- name: Add coverage report to summary
run: cat $GITHUB_WORKSPACE/CoverageReport-${{ env.LC_PIVOT }}/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
run: cat $GITHUB_WORKSPACE/CoverageReport-${{ steps.configure.outputs.LC_PIVOT }}/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
shell: bash
if: ${{ inputs.code-coverage && inputs.configuration == inputs.code-coverage-configuration }}

- name: Update CodeCoverage badge
run: |
chmod +rx .github/workflows/update_gist.sh
.github/workflows/update_gist.sh 9bd61dea93406219c4985641039c4e2f \
code-coverage-windows-${{ env.LC_PIVOT }}.svg \
$GITHUB_WORKSPACE/CoverageReport-${{ env.LC_PIVOT }}/badge_combined.svg
code-coverage-windows-${{ steps.configure.outputs.LC_PIVOT }}.svg \
$GITHUB_WORKSPACE/CoverageReport-${{ steps.configure.outputs.LC_PIVOT }}/badge_combined.svg
shell: bash
env:
GH_TOKEN: ${{ secrets.BADGE_GIST_TOKEN }}
Expand All @@ -123,6 +124,6 @@ jobs:
- name: Upload CoverageReport
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ env.LC_PIVOT }}
path: CoverageReport-${{ env.LC_PIVOT }}
name: coverage-report-${{ steps.configure.outputs.LC_PIVOT }}
path: CoverageReport-${{ steps.configure.outputs.LC_PIVOT }}
if: ${{ always() && inputs.code-coverage && inputs.configuration == inputs.code-coverage-configuration }}
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
dotnet-version: ${{ matrix.dotnet-version }}
configuration: ${{ matrix.configuration }}
tfm: ${{ matrix.tfm }}
code-coverage: true
code-coverage: true
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
dotnet-version: ${{ matrix.dotnet-version }}
configuration: ${{ matrix.configuration }}
tfm: ${{ matrix.tfm }}
code-coverage: true
code-coverage: true
56 changes: 56 additions & 0 deletions .github/workflows/upload-coverage-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Upload Coverage Report

on:
workflow_dispatch:

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
strategy:
matrix:
spec:
- .github/workflows/dotnet-windows.yml codecoverage-report-windows-net8.0-Release, codecoverage-report-windows-net481-Release
- .github/workflows/dotnet-ubuntu.yml codecoverage-report-ubuntu-net8.0-Release
steps:
- name: 'Download latest successful build artifact'
run: |
IFS=' ' read -ra spec <<< "${{ matrix.spec }}"
workflow_id=$(echo ${spec[0]} | xargs)
run_id=$(gh run list -w $workflow_id --json conclusion,headBranch,databaseId --jq 'first(.[] | select(.conclusion | contains("success"))) | .databaseId')
[ -z "$run_id" ] && echo "::error:::No successful run found for workflow '$workflow_id'" && exit 1 || true
echo "::notice::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=$(echo $artifact_id | sed 's/codecoverage-report-//g')
echo "::notice::Downloading '$artifact_id'"
gh run download $run_id -n $artifact_id -D $ARTIFACTS_TMP_DIR
unzip $ARTIFACTS_TMP_DIR/${artifact_id}.zip -d $OUTPUT_DIR/$artifact_subdir
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WF_SPEC: ${{ matrix.spec }}
ARTIFACTS_TMP_DIR: artifacts
OUTPUT_DIR: coverage-results
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages
uses: actions/upload-pages-artifact@v3
with:
path: coverage-results
- name: Deploy Pages
id: deployment
uses: actions/deploy-pages@v4

0 comments on commit e587a86

Please sign in to comment.