-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (153 loc) · 5.8 KB
/
Copy pathci-cd.yml
File metadata and controls
186 lines (153 loc) · 5.8 KB
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
name: CI/CD Pipeline
on:
push:
branches: [ develop, master ]
tags:
- 'v*'
pull_request:
branches: [ develop, master ]
env:
DOTNET_VERSION: '10.0.x'
CONFIGURATION: Release
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
MINVERBUILDMETADATA: build.${{ github.run_number }}
MINVERVERBOSITY: diagnostic
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Full history for versioning
ref: ${{ github.ref }} # Checkout the exact ref (tag or branch)
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Verify Git tags for MinVer
run: |
git fetch --tags --force
echo "Checking for tags..."
git describe --tags 2>/dev/null || echo "No tags found yet - this is expected for first release"
git tag --points-at HEAD || echo "No tag at current commit"
- name: Restore dependencies
run: dotnet restore
- name: Build library projects
run: |
dotnet build src/CountryData.Globalization/CountryData.Globalization.csproj --configuration ${{ env.CONFIGURATION }} --no-restore
dotnet build src/CountryData.Globalization.Hosting/CountryData.Globalization.Hosting.csproj --configuration ${{ env.CONFIGURATION }} --no-restore
dotnet build tests/CountryData.Globalization.Tests/CountryData.Globalization.Tests.csproj --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Run tests
run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results
path: '**/TestResults/*.trx'
- name: Pack NuGet packages
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
run: |
dotnet pack src/CountryData.Globalization/CountryData.Globalization.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts
dotnet pack src/CountryData.Globalization.Hosting/CountryData.Globalization.Hosting.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts
- name: Upload NuGet artifacts
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
uses: actions/upload-artifact@v7
with:
name: nuget-packages
path: ./artifacts/*.nupkg
publish-develop:
name: Publish to GitHub Packages (Develop)
needs: build-and-test
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Download NuGet artifacts
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to GitHub Packages
run: |
dotnet nuget add source --username ${{ github.repository_owner }} \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text \
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget push "./artifacts/*.nupkg" \
--source "github" \
--api-key ${{ secrets.GITHUB_TOKEN }} \
--skip-duplicate
publish-release:
name: Publish to NuGet.org (Release)
needs: build-and-test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download NuGet artifacts
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet.org
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--source https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_API_KEY }} \
--skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
create-release:
name: Create GitHub Release
needs: publish-release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download NuGet artifacts
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: ./artifacts
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.version.outputs.VERSION }}
body: |
## CountryData.Globalization v${{ steps.version.outputs.VERSION }}
### NuGet Packages Published
- ✅ CountryData.Globalization
- ✅ CountryData.Globalization.Hosting
### Installation
```bash
# Core package
dotnet add package CountryData.Globalization
# Hosting package (for DI support)
dotnet add package CountryData.Globalization.Hosting
```
### What's Changed
See [CHANGELOG.md](CHANGELOG.md) for detailed release notes.
files: ./artifacts/*.nupkg
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}