-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (174 loc) · 6.04 KB
/
build_publish.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: AppRating Build, Test & Publish
on:
push:
branches: [ main ]
tags-ignore: [ "*-v*" ]
paths:
- "backend/**"
pull_request:
branches: [ main ]
paths:
- "backend/**"
workflow_dispatch:
jobs:
ci:
name: Build, Test & Publish
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: Passw12#
ports:
- "1433:1433"
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: Passw12#
ports:
- "5432:5432"
env:
DOTNET_VERSION: 8.0
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
id: version
run: |
BRANCH=${GITHUB_REF#refs/*/}
if [[ $BRANCH == "main" ]]
then
BUILD_NUMBER=$GITHUB_RUN_NUMBER
VERSION="1.0.${BUILD_NUMBER}"
PUBLISH_ARTIFACTS=1
else
VERSION="0.0.0"
PUBLISH_ARTIFACTS=0
fi
echo Building on "$BRANCH"
echo Building version: "$VERSION"
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]
then
echo "Packages will be published to NuGet"
PUBLISH_NUGET=1
else
PUBLISH_NUGET=0
fi
if [[ $PUBLISH_ARTIFACTS == 0 && $PUBLISH_NUGET == 1 ]]
then
echo "Only vX.Y branches can be published to NuGet, failing"
exit 1
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "publish_artifacts=${PUBLISH_ARTIFACTS}" >> "${GITHUB_OUTPUT}"
echo "publish_nuget=${PUBLISH_NUGET}" >> "${GITHUB_OUTPUT}"
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
- name: Tool Restore
run: dotnet tool restore
- name: Check formatting
run: dotnet csharpier . --check
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet msbuild -t:RunTests -p:Configuration=Release -p:LogFileName="$PWD/../TestResults/tests.trx"
working-directory: ./backend/tests
- name: Integration Test SqlServer
run: |
dotnet test \
./tests/LeanCode.AppRating.IntegrationTests/LeanCode.AppRating.IntegrationTests.csproj \
--no-build \
--logger "trx;LogFileName=LeanCode.AppRating.IntegrationTests.trx" \
--results-directory TestResults
env:
AppReviewIntegrationTests__Database: sqlserver
SqlServer__ConnectionStringBase: Server=localhost,1433;User Id=sa;Password=Passw12#;Encrypt=false
- name: Integration Test Postgres
run: |
dotnet test \
./tests/LeanCode.AppRating.IntegrationTests/LeanCode.AppRating.IntegrationTests.csproj \
--no-build \
--logger "trx;LogFileName=LeanCode.AppRating.IntegrationTests.Postgres.trx" \
--results-directory TestResults
env:
AppReviewIntegrationTests__Database: postgres
Postgres__ConnectionStringBase: Host=localhost;Username=postgres;Password=Passw12#
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: test_results.zip
path: backend/TestResults/*.trx
- name: Pack AppRating Contracts
if: ${{ steps.version.outputs.publish_artifacts == '1' }}
env:
BUILD_VERSION: ${{ steps.version.outputs.version }}
run: dotnet pack --no-build -c Release -p:Version=$BUILD_VERSION
working-directory: ./backend/src/LeanCode.AppRating.Contracts
- name: Pack AppRating
if: ${{ steps.version.outputs.publish_artifacts == '1' }}
env:
BUILD_VERSION: ${{ steps.version.outputs.version }}
run: dotnet pack --no-build -c Release -p:Version=$BUILD_VERSION
working-directory: ./backend/src/LeanCode.AppRating
- name: Publish to Feedz
if: ${{ steps.version.outputs.publish_artifacts == '1' }}
run: |
dotnet nuget push \
"src/LeanCode.AppRating.Contracts/bin/Release/LeanCode.AppRating.Contracts.${BUILD_VERSION}.nupkg" \
"src/LeanCode.AppRating/bin/Release/LeanCode.AppRating.${BUILD_VERSION}.nupkg" \
-k "$FEEDZ_API_KEY" \
-s 'https://f.feedz.io/leancode/public/nuget/index.json' \
-n
env:
BUILD_VERSION: ${{ steps.version.outputs.version }}
FEEDZ_API_KEY: ${{ secrets.FEEDZ_API_KEY }}
- name: Publish to Nuget
if: ${{ steps.version.outputs.publish_nuget == '1' }}
run: |
dotnet nuget push \
"src/LeanCode.AppRating.Contracts/bin/Release/LeanCode.AppRating.Contracts.${BUILD_VERSION}.nupkg" \
"src/LeanCode.AppRating/bin/Release/LeanCode.AppRating.${BUILD_VERSION}.nupkg" \
-k "$NUGET_API_KEY" \
-s 'https://api.nuget.org/v3/index.json' \
-n
env:
BUILD_VERSION: ${{ steps.version.outputs.version }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
publish-test-results:
name: Publish Tests Results
needs: ci
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
pull-requests: write
if: always()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Extract Artifacts
run: |
for file in artifacts/*.zip; do
if [[ -f "$file" ]]; then
dir="${file%.zip}"
mkdir -p "$dir"
unzip -d "$dir" "$file"
fi
done
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
trx_files: "artifacts/*/**/*.trx"