-
-
Notifications
You must be signed in to change notification settings - Fork 192
140 lines (121 loc) · 4.75 KB
/
release.yml
File metadata and controls
140 lines (121 loc) · 4.75 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
name: Build and Release
on:
push:
branches: [ main, 'release/*.x' ]
workflow_dispatch:
env:
configuration: Release
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
runs-on: windows-latest
environment:
name: release
permissions:
contents: write
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate publish branch
shell: pwsh
env:
REF_NAME: ${{ github.ref_name }}
run: |
$ErrorActionPreference = 'Stop'
if ($env:REF_NAME -ne 'main' -and $env:REF_NAME -notmatch '^release/(0|[1-9]\d*)\.x$') {
throw "release.yml triggered on '$env:REF_NAME' which is neither 'main' nor 'release/<major>.x'. Refusing to publish."
}
Write-Host "OK: publishing from '$env:REF_NAME'."
- name: Setup .NET (With cache)
uses: actions/setup-dotnet@v5.0.1
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
10.0.x
cache: true
cache-dependency-path: |
**/Directory.Packages.props
**/*.sln
**/*.csproj
**/global.json
**/nuget.config
- name: NBGV
id: nbgv
uses: dotnet/nbgv@v0.5.1
with:
setAllVars: true
- name: Verify version matches branch policy
shell: pwsh
env:
SEMVER2: ${{ steps.nbgv.outputs.SemVer2 }}
PRERELEASE: ${{ steps.nbgv.outputs.PrereleaseVersion }}
REF_NAME: ${{ github.ref_name }}
run: |
$ErrorActionPreference = 'Stop'
if ($env:REF_NAME -eq 'main' -and -not $env:PRERELEASE) {
throw "Refusing to publish stable '$env:SEMVER2' from main. main must always publish prereleases. Check version.json for an accidental switch to a non-prerelease form."
}
if ($env:PRERELEASE -and $env:REF_NAME -match '^release/(0|[1-9]\d*)\.x$') {
throw "Refusing to publish prerelease '$env:SEMVER2' from a release branch ('$env:REF_NAME'). Release branches must only publish stable versions."
}
if (-not $env:PRERELEASE) {
Write-Host "Stable release ($env:SEMVER2); skipping prerelease regression check."
exit 0
}
if ($env:SEMVER2 -notmatch '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-') {
throw "Could not parse SemVer2 '$env:SEMVER2'"
}
$major = $matches[1]
$minor = $matches[2]
git fetch --tags --force origin
if ($LASTEXITCODE -ne 0) { throw "git fetch --tags failed (exit $LASTEXITCODE); cannot validate prerelease regression." }
$majorEsc = [regex]::Escape($major)
$minorEsc = [regex]::Escape($minor)
$stableTags = git tag --list "$major.$minor.*" | Where-Object { $_ -match "^${majorEsc}\.${minorEsc}\.\d+$" }
if ($stableTags) {
$list = $stableTags -join ', '
throw "Stable for $major.$minor has already shipped (tags: $list); cannot publish prerelease '$env:SEMVER2'. Bump main's version.json to the next minor or major preview line."
}
Write-Host "OK: no stable $major.$minor.* tag exists; '$env:SEMVER2' is safe to publish."
- name: NuGet Restore
run: dotnet restore DynamicData.sln
working-directory: src
- name: Run Tests
run: dotnet test --no-restore --configuration Release DynamicData.sln
working-directory: src
- name: Pack
run: dotnet pack --no-restore --no-build --configuration Release DynamicData.sln
working-directory: src
- name: NuGet Push
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
SOURCE_URL: https://api.nuget.org/v3/index.json
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$packages = Get-ChildItem -Path src -Recurse -Filter '*.nupkg' | Where-Object { $_.FullName -like '*\bin\Release\*' }
if (-not $packages) { throw "No .nupkg files found under src/**/bin/Release/." }
foreach ($pkg in $packages) {
dotnet nuget push -s $env:SOURCE_URL -k $env:NUGET_AUTH_TOKEN --skip-duplicate $pkg.FullName
if ($LASTEXITCODE -ne 0) { throw "dotnet nuget push failed for $($pkg.Name) (exit $LASTEXITCODE)." }
}
- name: Changelog
uses: glennawatson/ChangeLog@0464dd89b26f61fecf24b41d675f8ffdb11c4c3f # v1
id: changelog
- name: Create GitHub Release
uses: softprops/action-gh-release@v2.6.2
with:
tag_name: ${{ steps.nbgv.outputs.SemVer2 }}
name: ${{ steps.nbgv.outputs.SemVer2 }}
prerelease: ${{ steps.nbgv.outputs.PrereleaseVersion != '' }}
body: |
${{ steps.changelog.outputs.commitLog }}