Skip to content

Commit

Permalink
dressca-backendのCIパイプラインを修正。
Browse files Browse the repository at this point in the history
  • Loading branch information
fkoyama committed Oct 23, 2023
1 parent ec6b223 commit 3c370f5
Showing 1 changed file with 66 additions and 15 deletions.
81 changes: 66 additions & 15 deletions .github/workflows/samples-dressca-backend.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
BUILD_CONFIGURATION: Debug
BUILD_SUMMARY_FILE: BuildSummary.md
permissions:
checks: write
contents: read
pull-requests: write

steps:
- name: ブランチのチェックアウト
Expand All @@ -39,21 +44,67 @@ jobs:
- name: NuGet パッケージの復元
run: dotnet restore

- name: アプリケーションのビルド
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIGURATION }}
- id: application-build
name: アプリケーションのビルド
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} > build-result.txt

- name: 単体テストの実行
- name: ビルド結果の表示
shell: bash
if: ${{ success() || (failure() && steps.application-build.conclusion == 'failure') }}
run: |
dotnet add tests/Dressca.UnitTests/Dressca.UnitTests.csproj package coverlet.msbuild
dotnet test --no-build --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov > testResult.txt
echo '# Build Result :gear:' >> $GITHUB_STEP_SUMMARY
cat testResult.txt | sed -n -e '/Done/,/Elapsed/p' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '# Test Result :memo:' >> $GITHUB_STEP_SUMMARY
cat testResult.txt | sed -n -e '/A total of/,/Passed/p' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '# Coverage :triangular_ruler:' >> $GITHUB_STEP_SUMMARY
cat testResult.txt | sed -n -e '/+----------------------------------+--------+--------+--------+/,/+---------+--------+--------+--------+/p' | sed -e '$d' | sed -e '$d' | sed -e '$d' | sed -e '/+----------------------------------+--------+--------+--------+/d' | sed -e 's/|//' | sed -e 's/|*$//g' | sed -e '1d' | sed -e '1i --------------------------|--------|--------|------------------' | sed -e '1i Module | Line | Branch | Method' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
cat testResult.txt | sed -n -e '/+---------+--------+--------+--------+/,/Average/p' | sed -e '1,2d' | sed -e '/+---------+--------+--------+--------+/d' | sed -e 's/|//' | sed -e 's/|*$//g' | sed -e '1i ----------|--------|--------|---------' | sed -e '1i --- | Line | Branch | Method' | sed -e '$d' | sed -e '$d' | sed -e '$d' | sed -e '$d' | sed -e '$d' | sed -e '$d' | sed -e '$d' >> $GITHUB_STEP_SUMMARY
cat buildResult.txt | sed -n -e '/Done/,/Elapsed/p' >> $GITHUB_STEP_SUMMARY
- id: run-tests
name: テストの実行
continue-on-error: true
run: dotnet test --no-build --logger trx --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} --collect "XPlat Code Coverage"

- id: create-test-result-report
name: テスト結果ページの作成
uses: dorny/test-reporter@v1
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
name: 'Test results'
path: '**/TestResults/*.trx'
path-replace-backslashes: 'true'
reporter: 'dotnet-trx'
only-summary: 'false'
list-suites: 'all'
list-tests: 'all'
max-annotations: '10'
fail-on-error: 'true'

- name: テスト結果のサマリー表示
shell: bash
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
run: |
echo '## Test Result :memo:' >> ${{ env.BUILD_SUMMARY_FILE }}
echo 'Test was a **${{ steps.create-test-result-report.outputs.conclusion }}**.' >> ${{ env.BUILD_SUMMARY_FILE }}
echo 'Completed in ${{ steps.create-test-result-report.outputs.time }}ms with **${{ steps.create-test-result-report.outputs.passed }}** passed, **${{ steps.create-test-result-report.outputs.failed }}** failed and ${{ steps.create-test-result-report.outputs.skipped }} skipped.' >> ${{ env.BUILD_SUMMARY_FILE }}
cat ${{ env.BUILD_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY
- id: create-coverage-report
name: コードカバレッジレポートの解析と作成
uses: danielpalme/ReportGenerator-GitHub-Action@5
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
reports: '**/TestResults/*/coverage.cobertura.xml'
targetdir: '${{ env.WORKING_DIRECTORY }}/CoverageReport'
reporttypes: 'MarkdownSummaryGithub'

- name: コードカバレッジの結果表示
shell: bash
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
run: |
sed -i s/'# Summary'/'## Coverage :triangular_ruler:'/g CoverageReport/SummaryGithub.md
sed -i -e '/^## Coverage$/d' CoverageReport/SummaryGithub.md
cat CoverageReport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
cat CoverageReport/SummaryGithub.md >> ${{ env.BUILD_SUMMARY_FILE }}
- name: ビルドサマリーをPull-requestに表示
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event_name == 'pull_request' && (success() || (failure() && steps.run-tests.conclusion == 'failure')) }}
with:
recreate: true
path: '${{ env.WORKING_DIRECTORY }}/${{ env.BUILD_SUMMARY_FILE }}'

0 comments on commit 3c370f5

Please sign in to comment.