-
Notifications
You must be signed in to change notification settings - Fork 14
125 lines (116 loc) · 4.34 KB
/
publish.yml
File metadata and controls
125 lines (116 loc) · 4.34 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
name: Publish
on:
push:
branches:
- master
paths:
- RELEASE_NOTES.md
- .github/workflows/publish.yml
jobs:
release-check:
name: Check release version
runs-on: windows-latest
permissions:
contents: read
outputs:
should_publish: ${{ steps.compare.outputs.should_publish }}
release_notes_version: ${{ steps.compare.outputs.release_notes_version }}
latest_release_version: ${{ steps.compare.outputs.latest_release_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore Tools
run: dotnet tool restore
- name: Compare release versions
id: compare
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
function Normalize-Version([string] $Version) {
if ([string]::IsNullOrWhiteSpace($Version)) {
return ""
}
return $Version.Trim() -replace '^[vV]', ''
}
$parseOutput = & dotnet aardpack --parse-only
if ($LASTEXITCODE -ne 0) {
throw "dotnet aardpack --parse-only failed with exit code $LASTEXITCODE."
}
$releaseNotesVersion = ($parseOutput | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Last 1).Trim()
if ([string]::IsNullOrWhiteSpace($releaseNotesVersion)) {
throw "dotnet aardpack --parse-only did not return a release notes version."
}
$headers = @{
Authorization = "Bearer $env:GITHUB_TOKEN"
Accept = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "github-actions"
}
$latestReleaseVersion = ""
$shouldPublish = "true"
try {
$latestRelease = Invoke-RestMethod `
-Uri "https://api.github.com/repos/${{ github.repository }}/releases/latest" `
-Headers $headers
$latestReleaseVersion = [string] $latestRelease.tag_name
if ((Normalize-Version $releaseNotesVersion) -eq (Normalize-Version $latestReleaseVersion)) {
$shouldPublish = "false"
}
}
catch {
$statusCode = $_.Exception.Response.StatusCode.value__
if ($statusCode -eq 404) {
Write-Host "No latest GitHub release found. Continuing publish workflow."
}
else {
throw
}
}
"release_notes_version=$releaseNotesVersion" >> $env:GITHUB_OUTPUT
"latest_release_version=$latestReleaseVersion" >> $env:GITHUB_OUTPUT
"should_publish=$shouldPublish" >> $env:GITHUB_OUTPUT
"## Publish release check" >> $env:GITHUB_STEP_SUMMARY
"" >> $env:GITHUB_STEP_SUMMARY
"- Release notes version: ``$releaseNotesVersion``" >> $env:GITHUB_STEP_SUMMARY
"- Latest GitHub release: ``$latestReleaseVersion``" >> $env:GITHUB_STEP_SUMMARY
"- Should publish: ``$shouldPublish``" >> $env:GITHUB_STEP_SUMMARY
pack:
name: Package
runs-on: windows-latest
needs: release-check
if: needs.release-check.outputs.should_publish == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore Tools
run: dotnet tool restore
- name: Restore
run: dotnet paket restore
- name: Pack
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: dotnet aardpack src\Aardvark.Rendering.sln --notag
- name: Upload Packages
uses: actions/upload-artifact@v4
with:
name: packages
path: bin\pack
- name: GitHub Packages
env:
NUGET_KEY: ${{ secrets.GITHUB_TOKEN }}
shell: cmd
run: dotnet nuget push "bin\pack\*.nupkg" -k %NUGET_KEY% -s "https://nuget.pkg.github.com/aardvark-platform/index.json" --skip-duplicate
- name: NuGet
env:
NUGET_KEY: ${{ secrets.NUGET_KEY }}
shell: cmd
run: dotnet nuget push "bin\pack\*.nupkg" -k %NUGET_KEY% -s "https://api.nuget.org/v3/index.json" --skip-duplicate