-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (140 loc) · 6.43 KB
/
samples-dressca-backend.ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
# cSpell:ignore lcov msbuild NOLOGO OPTOUT
name: dressca-backend CI
on:
pull_request:
branches: [ main ]
paths:
- 'samples/Dressca/dressca-backend/**'
- '.github/workflows/samples-dressca-backend.ci.yml'
workflow_dispatch:
env:
WORKING_DIRECTORY: samples/Dressca/dressca-backend
PATH_CACHE: /tmp/docker-img
defaults:
run:
working-directory: samples/Dressca/dressca-backend
jobs:
build:
name: バックエンドアプリケーションのビルド
runs-on: ubuntu-latest
env:
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: ブランチのチェックアウト
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: .NET SDK のセットアップ
uses: actions/[email protected]
with:
dotnet-version: 6.0.x
include-prerelease: false
- name: NuGet パッケージの復元
run: dotnet restore
- id: application-build
name: アプリケーションのビルド
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} --verbosity minimal > build-result.txt
- name: ビルド結果の表示
shell: bash
if: ${{ success() || (failure() && steps.application-build.conclusion == 'failure') }}
run: |
echo '# Build Result :gear:' >> $GITHUB_STEP_SUMMARY
cat build-result.txt | sed -n -e 's/^/> /p' >> $GITHUB_STEP_SUMMARY
- name: キャッシュIDの作成
id: imagetag
run: |
VARIANT=$(TZ=UTC-9 date '+%Y%m')
NAME_IMAGE=SQLServerDockerImage
# キャッシュする tar アーカイブ名とパスの設定
NAME_TAR="${NAME_IMAGE}.${VARIANT}.tar"
PATH_TAR=${{ env.PATH_CACHE }}"/${NAME_TAR}"
# 変数を他の run でも使えるように output
echo "NAME_TAR=${NAME_TAR}" >> "$GITHUB_OUTPUT"
echo "PATH_TAR=${PATH_TAR}" >> "$GITHUB_OUTPUT"
- name: キャッシュ有効化
id: cache
uses: actions/cache@v3
with:
path: ${{ env.PATH_CACHE }}
key: ${{ steps.imagetag.outputs.NAME_TAR }}
#- name: キャッシュがある場合にロード
# if: steps.cache.outputs.cache-hit == 'true'
# run: docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}
- name: キャッシュがない場合にイメージをプルして保存
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.PATH_CACHE }}
sudo docker pull mcr.microsoft.com/mssql/server:2022-latest
sudo docker run -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=P@ssw0rd" \
-p 1433:1433 --name sql1 \
--hostname sql1 \
-d \
mcr.microsoft.com/mssql/server:2022-latest
sudo docker exec sql1 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "P@ssw0rd" -Q "CREATE DATABASE Dressca_Eshop;"
sudo docker save mcr.microsoft.com/mssql/server:2022-latest -o ${{ steps.imagetag.outputs.PATH_TAR }}
- name: 結合テスト用にSQL Serverをセットアップ
run: |
sudo docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}
sudo docker run mcr.microsoft.com/mssql/server:2022-latest -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=P@ssw0rd" \
-p 1433:1433 --name sql1 \
--hostname sql1 \
-d \
mcr.microsoft.com/mssql/server:2022-latest
- id: run-tests
name: テストの実行
continue-on-error: true
run: dotnet test --settings:./tests/Dressca.IntegrationTest/citest.runsettings --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 }}'