feat: 테스트 실패 확인 #37
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: build | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
# paths: [ 'src/**', 'tests/**', '.github/workflows/dotnet-ci.yml' ] | |
paths-ignore: | |
- '**.md' | |
- '**.pptx' | |
- '**.png' | |
#- '.github/workflows/build-docs.yml' | |
# pull_request: | |
# branches: [ main ] | |
# 1. publish-unit-test-result-action: 솔루션 테스트 결과 trx 추가: Summary | |
# - https://github.com/EnricoMi/publish-unit-test-result-action?tab=readme-ov-file#permissions | |
# 2. dorny/test-reporter: 솔루션 테스트 메서드 목록 | |
# - https://github.com/dorny/test-reporter | |
permissions: | |
checks: write | |
pull-requests: write | |
# contents: read | |
# actions: read | |
jobs: | |
build: | |
name: Build | |
# 빌드 환경 경우의 수 정의 | |
strategy: | |
matrix: | |
dotnet-version: [ '9.0.x' ] | |
configuration: [ Release ] | |
os: [ ubuntu-24.04 ] | |
# 빌드 환경 지정 | |
runs-on: ${{ matrix.os }} | |
# $GITHUB_OUTPUT | |
# $GITHUB_STEP_SUMMARY | |
# 환경 변수 | |
# - 규칙: ${{ env.환경_변수_이름 }} | |
# - 예제: ${{ env.solution_dir }} | |
# 예약 변수 | |
# - ${{ github.workspace }} | |
# - ${{ github.run_number }} | |
# - ${{ github.run_id }} | |
env: | |
solution_file: ./Template/Hello.sln | |
coverage_in_cobertura_files: ./Template/**/*.cobertura.xml | |
coverage_out_dir: ./Template/.build/coverage | |
#coverage_out_cobertura_file: ./Template/.build/coverage/Cobertura.xml | |
testresults_in_trx_files: ./Template/**/*.trx | |
#testresult_dirs: ./Template/**/TestResults/**/* | |
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 로그 파일 | |
- 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 | |
# {솔루션} | |
# └─.build | |
# └─coverage | |
# ├─Cobertura.xml | |
# └─SummaryGithub.md | |
# https://github.com/danielpalme/ReportGenerator-GitHub-Action | |
# | |
# reportgenerator 결과물 | |
# - ./Template/.build/coverage/Cobertura.xml | |
# - ./Template/.build/coverage/SummaryGithub.md | |
# | |
# .dotnet toool 설치 명령 | |
# /usr/share/dotnet/dotnet tool install dotnet-reportgenerator-globaltool \ | |
# --tool-path reportgeneratortool \ | |
# --version 5.4.1 \ | |
# --ignore-failed-sources | |
# | |
# reportgenerator 명령 | |
# /home/runner/work/better-code-with-ddd/better-code-with-ddd/reportgeneratortool/reportgenerator \ | |
# -reports:./Template/**/*.cobertura.xml \ <- 입력 파일 N개 | |
# -targetdir:./Template/.build/coverage \ <- 출력 경로 | |
# -reporttypes:Cobertura;MarkdownSummaryGithub \ <- 출력 타입 | |
# -title:Code Coverage \ <- 제목 | |
# -verbosity:Info \ <- 로그 수준 | |
# -tag:2_12382597103 <- run_number-run_id | |
# -sourcedirs: \ | |
# -historydir: \ | |
# -plugins: \ | |
# -assemblyfilters:+* \ | |
# -classfilters:+* \ # -classfilters:"+MyNamespace.*;-MyNamespace.Tests.*" | |
# -filefilters:+* \ | |
# -riskhotspotassemblyfilters:+* \ | |
# -riskhotspotclassfilters:+* \ | |
# -license: | |
# 코드 커버리지 생성 | |
- name: Generate Coverage Reports | |
uses: danielpalme/[email protected] | |
with: | |
reports: '${{ env.coverage_in_cobertura_files }}' | |
targetdir: '${{ env.coverage_out_dir }}' | |
reporttypes: 'Cobertura;MarkdownSummaryGithub' | |
verbosity: "Warning" | |
title: "Code Coverage" | |
tag: "${{ github.run_number }}_${{ github.run_id }}" | |
customSettings: "" # https://github.com/danielpalme/ReportGenerator/wiki/Settings. | |
toolpath: "reportgeneratortool" # dotnet tool. | |
# $GITHUB_STEP_SUMMARY에 코드 커버리지 보고 | |
- name: Publish Coverage Reports in Build Summary | |
run: cat "${{ env.coverage_out_dir }}/SummaryGithub.md" >> $GITHUB_STEP_SUMMARY | |
shell: bash | |
# Publish-Unit-Test-Result-Action: https://github.com/EnricoMi/publish-unit-test-result-action?tab=readme-ov-file#permissions | |
# | |
# 결과: GitHub Summary | |
# Test Results | |
# 4 files 4 suites 1s ⏱️ | |
# 22 tests 22 ✅ 0 💤 0 ❌ | |
# 23 runs 23 ✅ 0 💤 0 ❌ | |
- name: Publish Test Summary | |
uses: EnricoMi/[email protected] | |
if: always() | |
with: | |
files: | | |
${{ env.testresults_in_trx_files }} | |
check_name: "Test Summary" | |
# CodeCoverageSummary: https://github.com/irongut/CodeCoverageSummary | |
# | |
# 결과: code-coverage-results.md | |
# Package | Line Rate | Branch Rate | Complexity | Health | |
# -------- | --------- | ----------- | ---------- | ------ | |
# Crop.Hello.Api | 74% | 88% | 11 | ➖ | |
# Crop.Hello.Api.Adapters.Infrastructure | 51% | 57% | 39 | ➖ | |
# Crop.Hello.Api.Adapters.Persistence | 50% | 100% | 2 | ➖ | |
# Crop.Hello.Api.Application | 50% | 100% | 2 | ➖ | |
# Crop.Hello.Api.Domain | 100% | 100% | 1 | ✔ | |
# Crop.Hello.Framework | 71% | 50% | 7 | ➖ | |
# Crop.Hello.Framework.Contracts | 43% | 38% | 64 | ❌ | |
# **Summary** | **52%** (107 / 205) | **52%** (26 / 50) | **126** | ➖ | |
- name: Publish Code Coverage Report | |
uses: irongut/[email protected] | |
with: | |
filename: "${{ env.coverage_out_dir }}/Cobertura.xml" # 머지된 Cobertura.xml 파일 | |
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" | |
# - name: "출력" | |
# run: | | |
# #find "$(pwd)/.build" | |
# find . -type f -name "code-coverage-results.md" | |
- name: Publish Coverage Reports in Build Summary | |
run: cat ./code-coverage-results.md >> $GITHUB_STEP_SUMMARY | |
shell: bash | |
# https://github.com/dorny/test-reporter?tab=readme-ov-file | |
# | |
# 결과: Test Detail Report | |
# 23 passed, 0 failed and 0 skipped | |
# | |
# Report Passed Failed Skipped Time | |
# ./Template/Assets/Domains/Tests/Crop.Hello.Domain.Unit/TestResults/logs.trx 1✅ 3s | |
# ./Template/Assets/Frameworks/Tests/Crop.Hello.Framework.Tests.Unit/TestResults/logs.trx 7✅ 4s | |
# ./Template/Backend/Api/Tests/Crop.Hello.Api.Tests.Integration/TestResults/logs.trx 2✅ 4s | |
# ./Template/Backend/Api/Tests/Crop.Hello.Api.Tests.Unit/TestResults/logs.trx 13✅ 4s | |
- name: Publish Test Detail Report | |
uses: dorny/[email protected] | |
if: always() | |
with: | |
name: Test Detail Report | |
path: "${{ env.testresults_in_trx_files }}" | |
reporter: dotnet-trx | |
# - name: Add Coverage PR Comment | |
# uses: marocchino/sticky-pull-request-comment@v2 | |
# if: github.event_name == 'pull_request' | |
# with: | |
# recreate: true | |
# path: code-coverage-results.md | |
# # https://github.com/irongut/CodeCoverageSummary | |
# - name: Publish Code Coverage Report | |
# uses: irongut/[email protected] | |
# with: | |
# filename: ${{ env.coverage_out_cobertura_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" | |
# # 첨부 파일 | |
# - name: Upload Test Results | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: Test-Results_${{ matrix.dotnet-version }}_sha-${{ steps.vars.outputs.short_sha }} | |
# path: ${{ env.testresult_dirs }} | |
# retention-days: 5 | |
# # 첨부 파일 | |
# - name: Upload Combined Coverage XML | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: coverage_${{ matrix.dotnet-version }}_sha-${{ steps.vars.outputs.short_sha }} | |
# path: ${{ env.coverage_out_cobertura_file }} | |
# retention-days: 5 | |
# # 솔루션 코드 커버리지 전송(Codecov) | |
# - name: Upload coverage reports to Codecov | |
# uses: codecov/[email protected] | |
# with: | |
# token: ${{ secrets.CODECOV_TOKEN }} | |
# slug: hhko/ArchDdd | |
# 테스트와 코드 커버리지 coverage.cobertura.xml 파일 생성 | |
# - name: Find coverage output path | |
# run: | | |
# cp $(find . -name "coverage.cobertura.xml") . |