-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (141 loc) · 5.34 KB
/
Copy pathrelease.yml
File metadata and controls
164 lines (141 loc) · 5.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
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
name: release
# A tag push builds, packs and publishes to nuget.org. Run the workflow by hand to do
# everything except the publish, then download the release-packages artifact and inspect it.
on:
push:
tags: ['v*']
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
CI: true
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
build:
# net462 tests only run on Windows.
runs-on: windows-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
# global.json pins the SDK to 10.0.100. 8.0.x is here for the net8.0 test runtime.
dotnet-version: |
8.0.x
10.0.x
- name: Cache NuGet packages
uses: actions/cache@v6
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/Directory.*.props', 'global.json') }}
restore-keys: nuget-${{ runner.os }}-
- name: Restore
run: dotnet restore
# Manual runs have no tag to compare against: github.ref_name is a branch name there.
- name: Verify tag matches package version
if: github.event_name == 'push'
run: |
$expected = '${{ github.ref_name }}'.TrimStart('v')
$actual = (dotnet msbuild src/RequestFlow/RequestFlow.csproj -getProperty:Version).Trim()
if ($actual -ne $expected) {
Write-Error "Tag says $expected but the projects build as $actual. Update src/Directory.Build.props and re-tag."
exit 1
}
# Extracted here, before the publish job runs, because a package pushed to nuget.org
# cannot be replaced or deleted. Everything that can fail has to fail first.
- name: Extract release notes from CHANGELOG
if: github.event_name == 'push'
run: >
./.github/scripts/Get-ReleaseNotes.ps1
-Version '${{ github.ref_name }}'
-OutputPath artifacts/release-notes.md
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --no-build -c Release --logger trx
- name: Pack
run: dotnet pack --no-build -c Release -o artifacts/packages
- name: List packed files
run: Get-ChildItem artifacts/packages | Select-Object Name, Length
- name: Upload packages
uses: actions/upload-artifact@v7
with:
name: release-packages
# The .snupkg symbol packages ride along so the publish job can push both.
path: artifacts/packages/*
# An empty pack output is a regression, not a warning to scroll past.
if-no-files-found: error
- name: Upload release notes
if: github.event_name == 'push'
uses: actions/upload-artifact@v7
with:
name: release-notes
path: artifacts/release-notes.md
if-no-files-found: error
publish:
needs: build
# Only a tag push publishes. Manual runs stop here, having built, tested and packed.
if: github.event_name == 'push'
environment: nuget
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
# Trusted Publishing: NuGet/login exchanges the GitHub OIDC token for a short-lived API key.
id-token: write
steps:
- uses: actions/download-artifact@v8
with:
name: release-packages
path: artifacts/packages
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Get short-lived NuGet API key
id: login
uses: NuGet/login@v1
with:
user: illia1f
- name: Push to nuget.org
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
# The wildcard is quoted so dotnet expands it, not the shell. Each .nupkg push
# also sends the .snupkg sitting next to it.
run: >
dotnet nuget push 'artifacts/packages/*.nupkg'
--api-key "$NUGET_API_KEY"
--source https://api.nuget.org/v3/index.json
--skip-duplicate
release:
# Runs last so the Release entry never points at packages that failed to upload.
needs: [build, publish]
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
# Creating the Release is the only thing here that writes to the repository.
contents: write
steps:
- uses: actions/download-artifact@v8
with:
name: release-packages
path: artifacts/packages
- uses: actions/download-artifact@v8
with:
name: release-notes
path: artifacts
- name: Create GitHub Release
# Pinned to a commit, not a tag: this is the one third-party action here, and it
# runs with contents: write. A moved tag would be a silent code swap.
uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3.0.2
with:
body_path: artifacts/release-notes.md
# Any tag with a suffix (v1.0.0-preview.2) is a prerelease, which also keeps it
# off the Latest badge. Only a bare v1.0.0 becomes the headline release.
prerelease: ${{ contains(github.ref_name, '-') }}
files: artifacts/packages/*
fail_on_unmatched_files: true