-
-
Notifications
You must be signed in to change notification settings - Fork 245
152 lines (119 loc) · 4.34 KB
/
cicd.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
name: Continuous Integration & Delivery
on:
push:
branches: [ develop, master, bugfix/*, feature/* ]
pull_request:
branches: [ develop, master ]
workflow_dispatch:
inputs:
publish_nuget_package:
description: Publish a new NuGet package?
required: false
type: boolean
concurrency:
group: ${{ github.head_ref || github.sha }}
cancel-in-progress: true
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
TZ: CET # https://stackoverflow.com/q/53510011
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
clean: true
lfs: true
- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: ${{ matrix.os }}-nuget-${{ hashFiles('Directory.Build.props') }}
path: ~/.nuget/packages
- name: Setup .NET
uses: actions/setup-dotnet@v3
- name: Restore .NET Tools
run: dotnet tool restore
- name: Restore NuGet Packages
run: dotnet cake --target=Restore-NuGet-Packages
- name: Run Build
run: dotnet cake --target=Build
- name: Run Tests
run: dotnet cake --target=Tests --test-filter=FullyQualifiedName~${{ startsWith(matrix.os, 'ubuntu') && 'DotNet.Testcontainers' || 'DotNet.Testcontainers.Tests.Unit.Containers.Windows' }}
- name: Rename Test And Coverage Results
run: Get-ChildItem -Path 'test-coverage' -Filter *.xml | Rename-Item -NewName { $_.Name -Replace 'coverage', '${{ matrix.os }}'.ToLower() }
shell: pwsh
- name: Upload Test And Coverage Results
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: |
test-coverage
test-results
publish:
if: ${{ contains(fromJson('["develop", "master"]'), github.ref_name) }}
needs: build
environment: production
runs-on: ubuntu-22.04
permissions:
contents: write
pull-requests: read
env:
FEED_SOURCE: https://api.nuget.org/v3/index.json
FEED_APIKEY: ${{ secrets.FEED_APIKEY }}
SONARCLOUD_URL: https://sonarcloud.io
SONARCLOUD_ORGANIZATION: testcontainers
SONARCLOUD_KEY: testcontainers_testcontainers-dotnet
SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
clean: true
lfs: true
fetch-depth: 0
- name: Download Test And Coverage Results (ubuntu-22.04)
uses: actions/download-artifact@v3
with:
name: ubuntu-22.04
- name: Download Test And Coverage Results (windows-2022)
uses: actions/download-artifact@v3
with:
name: windows-2022
- name: Fix Absolute Code Coverage Paths
run: |
Get-ChildItem -Path 'test-coverage' -Filter *.xml | % { (Get-Content $_) -Replace '[A-Za-z0-9:\-\/\\]+src', '${{ github.workspace }}/src' | Set-Content $_ }
Get-ChildItem -Path 'test-coverage' -Filter *.xml | % { (Get-Content $_) -Replace '[A-Za-z0-9:\-\/\\]+tests', '${{ github.workspace }}/tests' | Set-Content $_ }
shell: pwsh
- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: ubuntu-22.04-nuget-${{ hashFiles('Directory.Build.props') }}
path: ~/.nuget/packages
- name: Setup .NET
uses: actions/setup-dotnet@v3
- name: Restore .NET Tools
run: dotnet tool restore
- name: Restore NuGet Packages
run: dotnet cake --target=Restore-NuGet-Packages
- name: Run Sonar Analysis
run: dotnet cake --target=Sonar-Begin
- name: Run Build
run: dotnet cake --target=Build
- name: Upload Sonar Results
run: dotnet cake --target=Sonar-End
- name: Publish NuGet Package
run: dotnet cake --target=Publish
env:
PUBLISH_NUGET_PACKAGE: ${{ inputs.publish_nuget_package }}
- uses: release-drafter/release-drafter@6df64e4ba4842c203c604c1f45246c5863410adb
with:
version: ${{ env.semVer }} # Cake sets the semVer environment variable
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}