Skip to content

feat: code coverage 요약 #20

feat: code coverage 요약

feat: code coverage 요약 #20

Workflow file for this run

name: build
# TODO: PR일 때 코드 커버리지 댓글 추가
on:
workflow_dispatch:
push:
branches:
- main
# paths: [ 'src/**', 'tests/**', '.github/workflows/dotnet-ci.yml' ]
paths-ignore:
- '**.md'
- '**.pptx'
- '**.png'
#- '.github/workflows/build-docs.yml'
#- 'docs/**'
# pull_request:
# branches: [ main ]
# # 솔루션 테스트 결과 trx 추가
# # - dorny/test-reporter@v1
# # - Error: HttpError: Resource not accessible by integration
# permissions:
# checks: write
# 솔루션 테스트 결과 trx 추가
# - https://github.com/EnricoMi/publish-unit-test-result-action?tab=readme-ov-file#permissions
# 2024-12-22 22:46:33 +0000
# - github.GithubRetry
# - INFO
# - Request POST /repos/hhko/better-code-with-ddd/check-runs failed with 403: Forbidden
permissions:
checks: write
pull-requests: write
jobs:
build:
name: Build
# 빌드 환경 경우의 수 정의
strategy:
matrix:
dotnet-version: [ '9.0.x' ]
configuration: [ Release ]
os: [ ubuntu-24.04 ]
# 빌드 환경 지정
runs-on: ${{ matrix.os }}
#runs-on: ubuntu-22.04
# 환경 변수
# - 규칙: ${{ env.환경_변수_이름 }}
# - 예제: ${{ env.solution_dir }}
env:
solution_file: ./Template/Hello.sln
coverage_in_files: ./Template/**/*.cobertura.xml
coverage_out_dir: ./Template/.build/coverage/output
coverage_out_file: ./Template/.build/coverage/output/Cobertura.xml
testresult_dirs: ./Template/**/TestResults/**/*
trx_files: ./Template/**/*.trx
steps:
# 형상관리 최신 소스 받기
- name: Checkout
uses: actions/checkout@v4
# Git Commit SHA 얻기
# - Deprecating save-state and set-output commands: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
# - GitHub Actions에서 output 변수의 문법 변경: https://blog.outsider.ne.kr/1651
# - Github Actions and creating a short SHA hash: https://dev.to/hectorleiva/github-actions-and-creating-a-short-sha-hash-8b7
#
# 동적 변수 만들기
# 규칙 1. $GITHUB_OUTPUT은 "steps.vars.outputs"을 지정한다.
# 규칙 2. "키=값" 형식으로 outputs을 정의한다.
# 예. ${{ steps.vars.outputs.short_sha }}
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "short_sha=$calculatedSha" >> $GITHUB_OUTPUT
# .NET SDK 설치
- name: Setup .NET SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
# 솔루션 패키지 복원
- name: Restore nuget packages
run: |
dotnet restore ${{ env.solution_file }} \
--verbosity q
# 솔루션 빌드
- name: Build
run: |
dotnet build ${{ env.solution_file }} \
--no-restore \
--configuration ${{ matrix.configuration }} \
--verbosity q
# 솔루션 테스트
# {테스트 프로젝트}
# └─TestResults
# ├─0ca60e99-32fb-43ac-bbd3-01f5a5ef6886 : XPlat Code Coverage 폴더
# │ └─coverage.cobertura.xml : 코드 커버리지 파일(dotnet-coverage merge 대상)
# ├─{username}_{hostname}_2024-03-14_15_16_30 : trx 로그 폴더
# │ └─In
# │ └─{hostname}
# │ └─coverage.cobertura.xml : 코드 커버리지 파일(사용 안함, Junit 로그 생성시 자동 생성됨)
# └─logs.trx : trx 로그 파일
# 테스트와 코드 커버리지 coverage.cobertura.xml 파일 생성
# - name: Find coverage output path
# run: |
# cp $(find . -name "coverage.cobertura.xml") .
- name: Test
run: |
dotnet test ${{ env.solution_file }} \
--configuration ${{ matrix.configuration }} \
--no-restore \
--no-build \
--collect "XPlat Code Coverage" \
--logger "trx;LogFileName=logs.trx" \
--verbosity q
# {솔루션}
# └─.results
# └─coverage
# ├─coverage.cobertura.merged.xml
# └─report
# ├─...
# └─SummaryGithub.md
# - name: Create coverage markdown file
# uses: danielpalme/[email protected]
# with:
# reports: '${{ env.coverage_path }}'
# targetdir: '${{ env.coverage_dir }}/report'
# reporttypes: 'MarkdownSummaryGithub;Html'
# /usr/share/dotnet/dotnet tool install dotnet-reportgenerator-globaltool \
# --tool-path reportgeneratortool \
# --version 5.4.1 \
# --ignore-failed-sources
# /home/runner/work/better-code-with-ddd/better-code-with-ddd/reportgeneratortool/reportgenerator \
# -reports:./Template/**/*.cobertura.xml \
# -targetdir:./Template/.build/coverage/output \
# -reporttypes:Cobertura \
# -sourcedirs: \
# -historydir: \
# -plugins: \
# -assemblyfilters:+* \
# -classfilters:+* \
# -filefilters:+* \
# -riskhotspotassemblyfilters:+* \
# -riskhotspotclassfilters:+* \
# -verbosity:Info \
# -title:Code Coverage \
# -tag:2_12382597103
# -license:
# ./Template/.build/coverage/output/Cobertura.xml
- name: Combine Coverage Reports # This is because one report is produced per project, and we want one result for all of them.
uses: danielpalme/[email protected]
with:
reports: '${{ env.coverage_in_files }}' # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
targetdir: '${{ env.coverage_out_dir }}'
#targetdir: "${{ github.workspace }}" # REQUIRED # The directory where the generated report should be saved.
reporttypes: 'Cobertura' # The output formats and scope (separated by semicolon) Values: Badges, Clover, Cobertura, CsvSummary, Html, Html_Dark, Html_Light, Html_BlueRed, HtmlChart, HtmlInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlInline_AzurePipelines_Light, HtmlSummary, JsonSummary, Latex, LatexSummary, lcov, MarkdownSummary, MarkdownSummaryGithub, MarkdownDeltaSummary, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, TextDeltaSummary, Xml, XmlSummary
verbosity: "Info" # The verbosity level of the log messages. Values: Verbose, Info, Warning, Error, Off
title: "Code Coverage" # Optional title.
tag: "${{ github.run_number }}_${{ github.run_id }}" # Optional tag or build version.
customSettings: "" # Optional custom settings (separated by semicolon). See: https://github.com/danielpalme/ReportGenerator/wiki/Settings.
toolpath: "reportgeneratortool" # Default directory for installing the dotnet tool.
- name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
run: cat "${{ env.coverage_out_dir }}/SummaryGithub.md" >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary
shell: bash
# # https://github.com/irongut/CodeCoverageSummary
# - name: Publish Code Coverage Report
# uses: irongut/[email protected]
# with:
# filename: ${{ env.coverage_out_file }}
# badge: true
# fail_below_min: false # just informative for now
# format: markdown
# hide_branch_rate: false
# hide_complexity: false
# indicators: true
# output: both
# #thresholds: "10 30"
# # https://github.com/EnricoMi/publish-unit-test-result-action?tab=readme-ov-file#permissions
# - name: Publish Test Results
# uses: EnricoMi/[email protected]
# if: always()
# with:
# trx_files: ${{ env.trx_files }}
# # 첨부 파일
# - name: Upload Test Results
# uses: actions/upload-artifact@v4
# with:
# name: Test-Results
# path: ${{ env.testresult_dirs }}
# retention-days: 5
# # 첨부 파일
# - name: Upload Combined Coverage XML
# uses: actions/upload-artifact@v4
# with:
# name: coverage
# path: ${{ env.coverage_out_file }}
# retention-days: 5
# # 솔루션 테스트 상세 보고서 생성
# - name: Create test detail report
# uses: dorny/test-reporter@v1
# if: always()
# with:
# name: Test Detail Report
# path: "tests/**/logs.trx"
# reporter: dotnet-trx
# # dotnet-coverage 도구 설치
# - name: Install dotnet-coverage tool
# run: dotnet tool install -g dotnet-coverage --version 17.9.6
# # 솔루션 코드 커버리지 폴더 생성
# - name: Create coverage folder
# run: mkdir -p ${{ env.coverage_dir }}
# # 솔루션 코드 커버지리 병합
# # N개 coverage.cobertura.xml 파일을 1개 coverage.cobertura.merged.xml로 통합
# - name: Convert .coverage.xml to .cobertura.merged.xml
# run: |
# dotnet-coverage merge "**/TestResults/*/*.cobertura.xml" \
# -f cobertura \
# -o ${{ env.coverage_path }}
# 솔루션 코드 커버리지 보고서 생성
# {솔루션}
# └─.results
# └─coverage
# ├─coverage.cobertura.merged.xml
# └─report
# ├─...
# └─SummaryGithub.md
# - name: Create coverage markdown file
# uses: danielpalme/[email protected]
# with:
# reports: '${{ env.coverage_path }}'
# targetdir: '${{ env.coverage_dir }}/report'
# reporttypes: 'MarkdownSummaryGithub;Html'
# # 솔루션 코드 커버리지 보고서 Summary 업로드
# - name: Upload coverage markdown into github actions summary
# run: cat ${{ env.coverage_dir }}/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
# # 솔루션 테스트 결과 Artifacts 업로드
# - name: Upload coverage files into github actions artifacts
# uses: actions/upload-artifact@v4
# with:
# name: coverage_${{ matrix.dotnet-version }}_sha-${{ steps.vars.outputs.short_sha }}
# path: ${{ env.coverage_dir }}/report
# # 솔루션 코드 커버리지 전송(Codecov)
# - name: Upload coverage reports to Codecov
# uses: codecov/[email protected]
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# slug: hhko/ArchDdd