-
-
Notifications
You must be signed in to change notification settings - Fork 36
156 lines (145 loc) · 5.51 KB
/
build.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
name: Build
on:
push:
branches: [ main ]
pull_request:
release:
types: [ published ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Disable the .NET logo in the console output.
DOTNET_NOLOGO: true
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending .NET CLI telemetry to Microsoft.
DOTNET_CLI_TELEMETRY_OPTOUT: true
BUILD_ARTIFACT_PATH: ${{github.workspace}}/build-artifacts
jobs:
build:
name: Build ${{matrix.os}}
runs-on: ${{matrix.os}}
continue-on-error: ${{matrix.optional}}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
mongodb: ['6.0']
optional: [false]
include:
- os: ubuntu-latest
ubuntu: 'jammy'
- os: macOS-latest
mongodb: '6.0'
optional: true
steps:
# Configure Redis
- name: Configure Redis (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install redis-server
- name: Configure Redis (Windows)
if: matrix.os == 'windows-latest'
run: choco install Memurai-Developer
- name: Configure Redis (MacOS)
if: matrix.os == 'macOS-latest'
run: brew install redis && brew services start redis
# Configure MongoDB
- name: Configure MongoDB (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
wget -qO - https://www.mongodb.org/static/pgp/server-${{matrix.mongodb}}.asc | gpg --dearmor | sudo tee /usr/share/keyrings/mongodb.gpg > /dev/null
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb.gpg ] https://repo.mongodb.org/apt/ubuntu ${{matrix.ubuntu}}/mongodb-org/${{matrix.mongodb}} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${{matrix.mongodb}}.list
sudo apt update
sudo apt install mongodb-org
sudo systemctl start mongod
- name: Configure MongoDB (Windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: |
$latestPackageVersion = Resolve-ChocoPackageVersion -TargetVersion ${{matrix.mongodb}} -PackageName "mongodb.install"
choco install mongodb.portable --version=$latestPackageVersion
- name: Configure MongoDB (MacOS)
if: matrix.os == 'macOS-latest'
run: |
brew tap mongodb/brew
brew update
brew install mongodb-community@${{matrix.mongodb}}
brew services start mongodb-community@${{matrix.mongodb}}
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Setup dotnet SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.306
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test with Coverage
run: dotnet test --no-restore --logger trx --results-directory ${{env.BUILD_ARTIFACT_PATH}}/coverage --collect "XPlat Code Coverage" --settings CodeCoverage.runsettings /p:SkipBuildVersioning=true
- name: Pack
run: dotnet pack --no-build -c Release /p:PackageOutputPath=${{env.BUILD_ARTIFACT_PATH}}
- name: Publish artifacts
uses: actions/upload-artifact@v3
with:
name: ${{matrix.os}}
path: ${{env.BUILD_ARTIFACT_PATH}}
coverage:
name: Process code coverage
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Download coverage reports
uses: actions/download-artifact@v3
- name: Install ReportGenerator tool
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Prepare coverage reports
run: reportgenerator -reports:*/coverage/*/coverage.cobertura.xml -targetdir:./ -reporttypes:Cobertura
- name: Upload coverage report
uses: codecov/[email protected]
with:
file: Cobertura.xml
fail_ci_if_error: false
- name: Save combined coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: Cobertura.xml
push-to-github-packages:
name: 'Push GitHub Packages'
needs: build
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
environment:
name: 'GitHub Packages'
url: https://github.com/TurnerSoftware/CacheTower/packages
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: 'Download build'
uses: actions/download-artifact@v3
with:
name: 'ubuntu-latest'
- name: 'Add NuGet source'
run: dotnet nuget add source https://nuget.pkg.github.com/TurnerSoftware/index.json --name GitHub --username Turnerj --password ${{secrets.GITHUB_TOKEN}} --store-password-in-clear-text
- name: 'Upload NuGet package'
run: dotnet nuget push *.nupkg --api-key ${{secrets.GH_PACKAGE_REGISTRY_API_KEY}} --source GitHub --skip-duplicate
push-to-nuget:
name: 'Push NuGet Packages'
needs: build
if: github.event_name == 'release'
environment:
name: 'NuGet'
url: https://www.nuget.org/packages/CacheTower
runs-on: ubuntu-latest
steps:
- name: 'Download build'
uses: actions/download-artifact@v3
with:
name: 'ubuntu-latest'
- name: 'Upload NuGet package'
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{secrets.NUGET_API_KEY}}