-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (167 loc) · 6.1 KB
/
ci.yml
File metadata and controls
181 lines (167 loc) · 6.1 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
name: publish
on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: false
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NUGET_DIRECTORY: ${{ github.workspace}}/artifacts
defaults:
run:
shell: pwsh
jobs:
lint_config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Create artifacts directory
run: mkdir -p artifacts
- run: dotnet run --project=tools/ConfigFilesGenerator/ConfigFilesGenerator.csproj
compute_version:
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.compute-version.outputs.package_version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-dotnet@v5
- id: compute-version
run: |
$LatestTag = git describe --tags --abbrev=0 2>$null
if ($LatestTag -and $LatestTag -match '^v([0-9]+\.[0-9]+\.[0-9]+)$')
{
$NewVersion = $Matches[1]
Write-Host "Using tag version: $NewVersion"
}
else
{
try
{
# Match version like 1.1.X or 1.0.X
$(Invoke-WebRequest "https://www.nuget.org/api/v2/package/ANcpLua.NET.Sdk/").BaseResponse.RequestMessage.RequestUri -match "ANcpLua\.net\.sdk\.(\d+)\.(\d+)\.(\d+)\.nupkg"
$Major = [int]$Matches.1
$Minor = [int]$Matches.2
$Patch = [int]$Matches.3 + 1
$NewVersion = "$Major.$Minor.$Patch"
}
catch
{
$NewVersion = "1.1.3"
}
}
Write-Host "New version: $NewVersion"
"package_version=$NewVersion" >> $env:GITHUB_OUTPUT
create_nuget:
needs: [compute_version]
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Create artifacts directory
run: New-Item -ItemType Directory -Force -Path artifacts
- run: ./build.ps1 -Version ${{ needs.compute_version.outputs.package_version }}
- uses: actions/upload-artifact@v7
with:
name: nuget
if-no-files-found: error
retention-days: 3
path: "${{ env.NUGET_DIRECTORY }}/*.nupkg"
test:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.runs-on }}
needs: [create_nuget, compute_version]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/download-artifact@v8
with:
name: nuget
path: ${{ env.NUGET_DIRECTORY }}
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- run: Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse
- run: dotnet --info
- run: dotnet nuget locals all --clear
# CheckEnforcement is for SDK consumers, not the SDK repo itself
# (SDK repo uses Microsoft.NET.Sdk, can't dogfood ANcpLua.NET.Sdk)
- run: dotnet test --project tests/ANcpLua.Sdk.Tests/ANcpLua.Sdk.Tests.csproj --report-xunit-trx --report-github --results-directory test_results
env:
CI: true
NUGET_DIRECTORY: ${{ env.NUGET_DIRECTORY }}
PACKAGE_VERSION: ${{ needs.compute_version.outputs.package_version }}
- uses: actions/upload-artifact@v7
if: always()
with:
name: test_results_${{ matrix.runs-on }}
path: test_results
deploy:
runs-on: ubuntu-latest
needs: [create_nuget, lint_config, test, compute_version]
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/download-artifact@v8
with:
name: nuget
path: ${{ env.NUGET_DIRECTORY }}
- uses: actions/setup-dotnet@v5
- name: Must Publish Packages
id: has_changes
run: |
# When HEAD is tagged (release commit), diff against the PREVIOUS tag
# to detect changes. Without this, git diff $tag HEAD is always empty.
$ExactTag = git describe --tags --exact-match HEAD 2>$null
if ($ExactTag) {
Write-Host "HEAD is tagged: $ExactTag — finding previous tag"
$PreviousTag = git describe --tags --abbrev=0 "$ExactTag~1" 2>$null
} else {
$PreviousTag = git describe --tags --abbrev=0 2>$null
}
if ($PreviousTag) {
Write-Host "Previous tag: $PreviousTag"
$Changes = git diff --name-only $PreviousTag HEAD -- '*.nuspec' 'src/**/*'
} else {
Write-Host "No previous tag found, checking all files"
$Changes = $true
}
if ($Changes) {
Write-Host "Changes: $Changes"
echo "has_changes=true" >> $env:GITHUB_OUTPUT
exit 0
} else {
Write-Host "No changes detected in .nuspec or src/ files"
echo "has_changes=false" >> $env:GITHUB_OUTPUT
exit 0
}
- name: Publish NuGet packages
if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
Write-Host "Publishing to NuGet.org"
$files = Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse -Include *.nupkg
foreach ($file in $files) {
Write-Host "Pushing: $($file.Name)"
& dotnet nuget push "$($file.FullName)" --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
- run: gh release create "${{ needs.compute_version.outputs.package_version }}" --generate-notes
if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }}
env:
GH_TOKEN: ${{ github.token }}