Repository navigation
210 lines (201 loc) · 8.63 KB
/
Copy pathrelease.yml
File metadata and controls
210 lines (201 loc) · 8.63 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Release
on:
push:
branches:
- master
paths:
- RELEASE_NOTES.md
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
detect-release:
name: Detect new release
# A fork that enables Actions and syncs master would otherwise build a release, and fail to publish it
if: github.repository == 'fsprojects/Paket'
runs-on: ubuntu-26.04
permissions:
contents: read
outputs:
is-release: ${{ steps.release.outputs.is-release }}
version: ${{ steps.release.outputs.version }}
prerelease: ${{ steps.release.outputs.prerelease }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Compare release headings
id: release
shell: pwsh
env:
BEFORE_SHA: ${{ github.event.before }}
run: |
function Get-CurrentRelease([string[]] $lines) {
$releasePattern = '^####\s+(?<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\b'
$headingPattern = '^####\s+'
$start = 0..($lines.Count - 1) | Where-Object { $lines[$_] -match $releasePattern } | Select-Object -First 1
if ($null -eq $start) {
throw 'RELEASE_NOTES.md has no versioned #### release heading.'
}
$match = [regex]::Match($lines[$start], $releasePattern)
$end = (($start + 1)..($lines.Count - 1) | Where-Object { $lines[$_] -match $headingPattern } | Select-Object -First 1)
if ($null -eq $end) { $end = $lines.Count }
return [pscustomobject]@{
Version = $match.Groups['version'].Value
Content = ($lines[$start..($end - 1)] -join "`n").TrimEnd()
}
}
$currentRelease = Get-CurrentRelease (Get-Content RELEASE_NOTES.md)
$previousRelease = $null
if ($env:BEFORE_SHA -and $env:BEFORE_SHA -notmatch '^0+$') {
$previousNotes = git show "${env:BEFORE_SHA}:RELEASE_NOTES.md" 2>$null
if ($LASTEXITCODE -eq 0) {
$previousRelease = Get-CurrentRelease $previousNotes
}
}
$isRelease = $null -eq $previousRelease -or
$currentRelease.Version -cne $previousRelease.Version -or
$currentRelease.Content -cne $previousRelease.Content
"is-release=$($isRelease.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
"version=$($currentRelease.Version)" >> $env:GITHUB_OUTPUT
"prerelease=$($currentRelease.Version.Contains('-').ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
Write-Host "Current release: $($currentRelease.Version); previous release: $($previousRelease.Version); publish: $isRelease"
release:
name: Build and publish ${{ needs.detect-release.outputs.version }}
needs: detect-release
if: needs.detect-release.outputs.is-release == 'true'
runs-on: windows-latest
timeout-minutes: 90
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Configure git autocrlf
run: git config --global core.autocrlf input
- uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
- name: Install integration test runtime
shell: pwsh
run: |
$installScript = Join-Path $env:RUNNER_TEMP 'dotnet-install.ps1'
Invoke-WebRequest https://dot.net/v1/dotnet-install.ps1 -OutFile $installScript
& $installScript -Channel 8.0 -Runtime dotnet -InstallDir (Join-Path $env:LOCALAPPDATA 'dotnetcore')
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Cache NuGet packages
uses: actions/cache@v6
with:
path: |
~/.nuget/packages
packages
key: ${{ runner.os }}-nuget-${{ hashFiles('paket.lock', 'paket.dependencies', 'global.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build release artifacts
shell: cmd
run: .\build.cmd BuildPackage < NUL
# Paket 11.0.0 and earlier download paket.targets and paket.bootstrapper.exe from the latest
# release, and so does the --self of the bootstrappers older than 11.0. Republish the ones
# of the latest Paket 11 release: they still run paket.exe, and that bootstrapper never goes
# past 11.x.
- name: Fetch the Paket 11 assets
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$release = gh release list --limit 200 --exclude-drafts --exclude-pre-releases --json tagName |
ConvertFrom-Json |
Where-Object { $_.tagName -match '^11\.\d+\.\d+$' } |
Sort-Object { [version]$_.tagName } |
Select-Object -Last 1
if (-not $release) { throw 'No Paket 11 release found' }
gh release download $release.tagName --pattern paket.targets --pattern paket.bootstrapper.exe --dir bin/paket-11
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Verify release artifacts
shell: pwsh
env:
VERSION: ${{ needs.detect-release.outputs.version }}
run: |
$requiredFiles = @(
'bin/legacy-stub/paket.exe',
'bin/legacy-stub/paket-sha256.txt',
'src/FSharp.DependencyManager.Paket/bin/Release/netstandard2.0/FSharp.DependencyManager.Paket.dll',
'bin/paket-11/paket.targets',
'bin/paket-11/paket.bootstrapper.exe',
'.paket/Paket.Restore.targets',
"temp/Paket.$env:VERSION.nupkg",
"temp/Paket.Core.$env:VERSION.nupkg",
"temp/FSharp.DependencyManager.Paket.$env:VERSION.nupkg"
)
$missingFiles = $requiredFiles | Where-Object { -not (Test-Path $_ -PathType Leaf) }
if ($missingFiles) {
throw "Missing release artifacts:`n$($missingFiles -join "`n")"
}
- name: Obtain NuGet key
id: login
# NuGet/login v1.2.0
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841
with:
user: dsyme
- name: Publish NuGet packages
shell: pwsh
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: |
Get-ChildItem temp/*.nupkg | ForEach-Object {
dotnet nuget push $_.FullName --source https://api.nuget.org/v3/index.json --api-key $env:NUGET_API_KEY --skip-duplicate
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
- name: Create release notes body
shell: pwsh
run: |
$lines = Get-Content RELEASE_NOTES.md
$start = 0..($lines.Count - 1) | Where-Object { $lines[$_] -match '^####\s+\d+\.\d+\.\d+' } | Select-Object -First 1
$end = (($start + 1)..($lines.Count - 1) | Where-Object { $lines[$_] -match '^####\s+' } | Select-Object -First 1)
if ($null -eq $end) { $end = $lines.Count }
$body = $lines[($start + 1)..($end - 1)] -join "`n"
$body.Trim() | Set-Content release-notes-body.md
- name: Create GitHub release
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.detect-release.outputs.version }}
PRERELEASE: ${{ needs.detect-release.outputs.prerelease }}
run: |
$assets = @(
'bin/legacy-stub/paket.exe',
'bin/legacy-stub/paket-sha256.txt',
'src/FSharp.DependencyManager.Paket/bin/Release/netstandard2.0/FSharp.DependencyManager.Paket.dll',
'bin/paket-11/paket.targets',
'bin/paket-11/paket.bootstrapper.exe',
'.paket/Paket.Restore.targets'
) + @(Get-ChildItem temp/*.nupkg | ForEach-Object FullName)
gh release view $env:VERSION *> $null
if ($LASTEXITCODE -eq 0) {
gh release upload $env:VERSION $assets --clobber
} else {
$arguments = @(
'release', 'create', $env:VERSION
) + $assets + @(
'--target', '${{ github.sha }}',
'--title', $env:VERSION,
'--notes-file', 'release-notes-body.md'
)
if ($env:PRERELEASE -eq 'true') {
$arguments += '--prerelease'
}
& gh @arguments
}
docs:
name: Publish the documentation of ${{ needs.detect-release.outputs.version }}
needs: [detect-release, release]
# The site documents the latest stable release: a prerelease must not replace it
if: needs.detect-release.outputs.prerelease == 'false'
permissions:
contents: write
uses: ./.github/workflows/docs.yml
with:
version: ${{ needs.detect-release.outputs.version }}