-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (184 loc) · 6.2 KB
/
ci.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
name: CI
on:
push:
branches:
- 'master'
tags: [ 'v*' ]
pull_request:
branches:
- 'master'
defaults:
run:
shell: bash
env:
LOCAL_SOURCE_NAME: local
PACKAGES_DIRECTORY: nupkgs
PROJECT_NAME: Gon
TEST_PROJECT_NAME: TestProject
jobs:
test:
name: 'Test'
runs-on: ${{ matrix.os }}
strategy:
matrix:
dotnet_sdk_version: [ '7.x' ]
dotnet_runtime_version: [
'net45', 'net46', 'net47', 'net48',
'netstandard1.3', 'netstandard1.4', 'netstandard1.5',
'netstandard1.6', 'netstandard2.0', 'netstandard2.1',
'net5.0', 'net6.0', 'net7.0'
]
python_version: [ '3.11' ]
os: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ]
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet_sdk_version }}
- name: 'Run dotnet format'
run: dotnet format style --verify-no-changes
- name: 'Install CSharpier'
run: dotnet tool install csharpier -g
- name: 'Run CSharpier'
run: dotnet csharpier --check .
- name: 'Setup Python'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: 'Compare example from README with code'
run: >
python -c "import re;from pathlib import Path;
raise SystemExit(
'\n'.join(re.findall(r'(?<=\`\`\`cs\n)([^\`]+)', Path('README.md').read_text()))
!= Path('src/GonExamples/Basic.cs').read_text()
)"
- name: 'Install MyPy'
run: python -m pip install mypy
- name: 'Run MyPy'
run: mypy --ignore-missing-imports tests
- name: 'Install tests dependencies'
run: python -m pip install -r requirements-tests.txt
- name: 'Publish project'
run: >
dotnet publish --property:CheckEolTargetFramework=false
--property:PublishDir=$PWD/tests/
--framework ${{ matrix.dotnet_runtime_version }} .
- name: 'Install coverage dependencies'
run: dotnet tool install --global dotnet-coverage
- name: 'Run tests'
run: dotnet coverage collect pytest -f cobertura -o coverage.xml
- name: 'Upload coverage'
uses: codecov/[email protected]
continue-on-error: true
pre-deploy:
name: 'Pre-deploy'
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- name: '_'
run: echo "Pre-deploy step"
build:
name: 'Build'
runs-on: ubuntu-latest
needs: pre-deploy
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: 'Build'
run: >
dotnet pack -c Release -o ${{ env.PACKAGES_DIRECTORY }}
src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj
- name: 'Upload'
uses: actions/upload-artifact@v3
with:
name: ${{ env.PACKAGES_DIRECTORY }}
path: ${{ env.PACKAGES_DIRECTORY }}
test-distributions:
name: Test distributions
runs-on: ${{ matrix.os }}
needs: build
strategy:
matrix:
dotnet_runtime_version: [
'net45', 'net46', 'net47', 'net48',
'netstandard1.3', 'netstandard1.4', 'netstandard1.5',
'netstandard1.6', 'netstandard2.0', 'netstandard2.1',
'net5.0', 'net6.0', 'net7.0'
]
os: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ]
steps:
- name: 'Download distributions'
uses: actions/download-artifact@v3
with:
name: ${{ env.PACKAGES_DIRECTORY }}
path: ${{ env.PACKAGES_DIRECTORY }}
- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: 'Setup Python'
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: 'Configure NuGet'
run: |
dotnet nuget add source \
"${{ github.workspace }}$(python -c 'import os;print(os.sep)')${{ env.PACKAGES_DIRECTORY }}" \
--name ${{ env.LOCAL_SOURCE_NAME }}
cat > nuget.config <<EOF
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*"/>
</packageSource>
<packageSource key="${{ env.LOCAL_SOURCE_NAME }}">
<package pattern="${{ env.PROJECT_NAME }}"/>
</packageSource>
</packageSourceMapping>
</configuration>
EOF
- name: 'Create test project'
run: >
dotnet new classlib -o ${{ env.TEST_PROJECT_NAME }}
--target-framework-override ${{ matrix.dotnet_runtime_version }}
&& rm -rf ${{ env.TEST_PROJECT_NAME }}/*.cs
- name: 'Install'
run: >
dotnet add ${{ env.TEST_PROJECT_NAME }} package
${{ env.PROJECT_NAME }} -v [${GITHUB_REF_NAME#v}]
- name: 'Build test project'
# "Nullable=disable" fixes "CS8630: Invalid 'nullable' value: 'Enable' for C# 7.3"
# "ImplicitUsings=disable" fixes "CS8370: Feature 'global using directive' is not available in C# 7.3"
run: >
dotnet build --property:Nullable=disable
--property:ImplicitUsings=disable
${{ env.TEST_PROJECT_NAME }}
deploy:
name: 'Deploy'
environment: release
needs: test-distributions
runs-on: ubuntu-latest
steps:
- name: 'Download distributions'
uses: actions/download-artifact@v3
with:
name: ${{ env.PACKAGES_DIRECTORY }}
path: ${{ env.PACKAGES_DIRECTORY }}
- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
- name: 'NuGet upload'
run: >
dotnet nuget push ${{ env.PACKAGES_DIRECTORY }}/*.nupkg --api-key $NUGET_API_KEY
-s https://api.nuget.org/v3/index.json
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}