-
Notifications
You must be signed in to change notification settings - Fork 26
198 lines (176 loc) · 7.02 KB
/
ci-cd.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
name: .NET CI/CD
on: [push, pull_request]
env:
# more info on dotnet cli environment variables here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Disable welcome message on dotnet CLI first run
DOTNET_NOLOGO: true
# Disable redundant package caching
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
tests:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
dotnet-target: ["3.1.x", "6.0.x", "8.0.x"]
exclude:
- os: macOS-latest
dotnet-target: "3.1.x"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.x
8.0.x
if: ${{ !startsWith(matrix.os, 'macOS') }}
- name: Set up dotnet macOS ARM
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
if: startsWith(matrix.os, 'macOS')
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: |
dotnet restore
- name: Build
run: |
dotnet build --configuration Release --version-suffix "$GITHUB_RUN_ID-prerelease" --no-restore
- name: Run tests (Linux and macOS)
if: runner.os != 'Windows'
run: |
if [ "${{ matrix.dotnet-target }}" == "3.1.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests
elif [ "${{ matrix.dotnet-target }}" == "6.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
elif [ "${{ matrix.dotnet-target }}" == "8.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
else
echo "Error: Unsupported .NET version ${{ matrix.dotnet-target }}" && exit 1
fi
- name: Run tests (Windows)
if: runner.os == 'Windows'
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if ("${{ matrix.dotnet-target }}" -eq "3.1.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "5.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net5.0 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "6.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "8.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
} else {
Write-Error "Unsupported .NET version $env:MATRIX_DOTNET_VERSION"
exit 1
}
integrationTests:
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
needs:
- "tests"
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
dotnet-version: [3.1.x, 8.0.x]
exclude:
- os: macOS-latest
dotnet-version: 3.1.x
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: |
dotnet restore
- name: Build
run: |
dotnet build --configuration Release --version-suffix "$GITHUB_RUN_ID-prerelease" --no-restore
- name: Run tests on mac and linux
if: ${{ !startsWith(matrix.os, 'windows') }}
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if [ ${{ matrix.dotnet-version }} == "3.1.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests.Integration
elif [ ${{ matrix.dotnet-version }} == "6.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
else
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests.Integration
fi
- name: Run tests on windows
if: startsWith(matrix.os, 'windows')
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if ("${{ matrix.dotnet-version }}" -eq "6.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
} elseif ("${{ matrix.dotnet-version }}" -eq "3.1.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests.Integration
} elseif ("${{ matrix.dotnet-version }}" -eq "8.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests.Integration
} else {
Write-Error "Unsupported .NET version $env:MATRIX_DOTNET_VERSION"
exit 1
}
publish:
if: |
github.repository == 'tinify/tinify-net' &&
startsWith(github.ref, 'refs/tags') &&
github.event_name == 'push'
needs:
- "tests"
- "integrationTests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Check if properly tagged
run: |
PACKAGE_VERSION="$(sed 's/\s*<VersionPrefix>\(.*\)<\/VersionPrefix>/\1/p' -n < src/Tinify/Tinify.csproj | tr -d '\n\r')";
CURRENT_TAG="${GITHUB_REF#refs/*/}";
if [[ "${PACKAGE_VERSION}" != "${CURRENT_TAG}" ]]; then
>&2 echo "Tag mismatch"
>&2 echo "Version in tinify/version.py (${PACKAGE_VERSION}) does not match the current tag=${CURRENT_TAG}"
>&2 echo "Skipping deploy"
exit 1;
fi
- name: Create Release NuGet package
run: |
CURRENT_TAG="${GITHUB_REF#refs/*/}";
echo "Clean Version: ${CURRENT_TAG}"
dotnet pack src/Tinify/Tinify.csproj -v normal -c Release --include-symbols --include-source -p:PackageVersion="${CURRENT_TAG}" -o .
- name: Push to Nuget
run: |
dotnet nuget push *.nupkg --skip-duplicate -s https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}}