-
Notifications
You must be signed in to change notification settings - Fork 4
209 lines (202 loc) · 7.51 KB
/
core_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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Corelibrary Build & Publish
on:
push:
branches:
- "v[0-9]+.[0-9]+-?*"
pull_request:
workflow_dispatch:
env:
DOTNET_VERSION: 9.0.100
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
jobs:
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
prepare:
name: Prepare & Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
publish_artifacts: ${{ steps.version.outputs.publish_artifacts }}
publish_nuget: ${{ steps.version.outputs.publish_nuget }}
artifacts_name: ${{ steps.version.outputs.artifacts_name }}
steps:
- name: Version
id: version
run: |
BRANCH=${GITHUB_REF#refs/*/}
if [[ $BRANCH =~ ^v([0-9]+.[0-9]+)(-[a-zA-Z0-9]+)?$ ]]
then
BUILD_NUMBER=$(( GITHUB_RUN_NUMBER + 500 )) # compensate for old jenkins CI
BRANCH_VERSION=${BASH_REMATCH[1]}
VERSION_SUFFIX=${BASH_REMATCH[2]}
VERSION="${BRANCH_VERSION}.${BUILD_NUMBER}${VERSION_SUFFIX}"
PUBLISH_ARTIFACTS=1
ARTIFACTS_NAME="LeanCode.CoreLibrary.$VERSION.zip"
else
VERSION="0.0.0"
PUBLISH_ARTIFACTS=0
ARTIFACTS_NAME="<none>"
fi
echo Building on "$BRANCH"
echo Building version: "$VERSION"
echo "Artifacts will be saved as $ARTIFACTS_NAME"
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
echo "artifacts_name=${ARTIFACTS_NAME}" >> $GITHUB_OUTPUT
build:
name: Build
runs-on: ubuntu-latest
needs: [prepare]
permissions:
checks: write
pull-requests: write
env:
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
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
if: false
run: dotnet csharpier . --check
- name: Build
run: dotnet build --configuration Release --no-restore
env:
GIT_COMMIT: ${{ github.sha }}
- name: Pack
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
env:
ZIP: ${{ needs.prepare.outputs.artifacts_name }}
run: |
dotnet pack --no-build -c Release -o "$PWD/packed"
zip -j "$ZIP" "$PWD"/packed/*.nupkg
- name: Publish artifacts
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
uses: actions/upload-artifact@v4
with:
name: ${{ needs.prepare.outputs.artifacts_name }}
path: ${{ needs.prepare.outputs.artifacts_name }}
test:
runs-on: ubuntu-latest
name: Test
needs: [prepare, build]
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Passw12#
ports:
- "1433:1433"
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: Passw12#
ports:
- "5432:5432"
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
- name: Unit tests
run: dotnet test
- name: Azure Test
run: dotnet test -- --explicit on --filter-trait 'service=azure'
env:
CORELIB_TESTS_TENANT_ID: ${{ secrets.CORELIB_TESTS_TENANT_ID }}
CORELIB_TESTS_CLIENT_ID: ${{ secrets.CORELIB_TESTS_CLIENT_ID }}
CORELIB_TESTS_CLIENT_SECRET: ${{ secrets.CORELIB_TESTS_CLIENT_SECRET }}
CORELIB_TESTS_NPGSQL_CONNECTION_STRING: ${{ secrets.CORELIB_TESTS_NPGSQL_CONNECTION_STRING }}
CORELIB_TESTS_AZURE_BLOB_STORAGE_SERVICE_URI: ${{ secrets.CORELIB_TESTS_AZURE_BLOB_STORAGE_SERVICE_URI }}
CORELIB_TESTS_AZURE_TABLE_STORAGE_SERVICE_URI: ${{ secrets.CORELIB_TESTS_AZURE_TABLE_STORAGE_SERVICE_URI }}
CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME: ${{ secrets.CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME }}
CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME: ${{ secrets.CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME }}
- name: Integration Test - SQL Server
run: dotnet test -- --explicit on --filter-trait 'category=integration'
env:
SqlServer__ConnectionStringBase: Server=localhost,1433;User Id=sa;Password=Passw12#;Encrypt=false
LeanCodeIntegrationTests__Database: sqlserver
- name: Integration Test - Postgres
run: dotnet test -- --explicit on --filter-trait 'category=integration'
env:
ASPNETCORE_TEST_CONTENTROOT_LEANCODE_INTEGRATIONTESTS: /home/runner/work/corelibrary/corelibrary/test/LeanCode.IntegrationTests
Postgres__ConnectionStringBase: Host=localhost;Username=postgres;Password=Passw12#
LeanCodeIntegrationTests__Database: postgres
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
directory: ./TestResults
- name: Upload test report
if: always()
run: |
# Strip BOM first :clown:
find TestResults -name '*.json' | xargs -n 1 sed -i "$(printf '1s/^\357\273\277//')"
npx ctrf merge TestResults --output merged.json
npx github-actions-ctrf TestResults/merged.json
publish:
runs-on: ubuntu-latest
name: Publish to feeds
needs: [prepare, build, test]
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
steps:
- name: Fetch build
id: download
uses: actions/download-artifact@v4
with:
name: ${{ needs.prepare.outputs.artifacts_name }}
- name: Unzip
run: |
unzip "$ZIP"
env:
ZIP: ${{ needs.prepare.outputs.artifacts_name }}
- name: Push to Feedz
run: |
find -name '*.nupkg' -exec dotnet nuget push -k "$FEEDZ_API_KEY" -s 'https://f.feedz.io/leancode/public/nuget/index.json' -n '{}' ';'
env:
FEEDZ_API_KEY: ${{ secrets.FEEDZ_API_KEY }}
- name: Create release
if: ${{ needs.prepare.outputs.publish_nuget == '1' }}
uses: actions/create-release@v1
with:
tag_name: ${{ format('v{0}', needs.prepare.outputs.version) }}
release_name: ${{ format('Release v{0}', needs.prepare.outputs.version) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push to NuGet
if: ${{ needs.prepare.outputs.publish_nuget == '1' }}
run: |
find -name '*.nupkg' -exec dotnet nuget push -k "$NUGET_API_KEY" -s 'https://api.nuget.org/v3/index.json' -n '{}' ';'
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}