forked from tinify/tinify-net
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (132 loc) · 4.79 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
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]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: |
6.0.x
8.0.x
- uses: actions/cache@v3
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: |
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
- name: Run tests on windows
if: startsWith(matrix.os, 'windows')
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
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]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: |
6.0.x
8.0.x
- uses: actions/cache@v3
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: |
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests.Integration
- name: Run tests on windows
if: startsWith(matrix.os, 'windows')
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
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@v3
with:
fetch-depth: 0
- name: Set up dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: 8.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}}