-
Notifications
You must be signed in to change notification settings - Fork 764
212 lines (175 loc) · 6.9 KB
/
publish-packages-1.0.yml
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
211
212
#################################################
################### IMPORTANT ###################
# DON'T RENAME THIS FILE UNLESS WE START
# RELEASING THE VERSION 2.*
################### IMPORTANT ###################
#################################################
name: Build, pack, and publish to MyGet
on:
workflow_dispatch:
push:
tags:
- 'core-*'
- 'coreunstable-*'
- 'Instrumentation.*-'
schedule:
- cron: '0 0 * * *' # once in a day at 00:00
permissions:
contents: write
pull-requests: write
jobs:
build-pack-publish:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit. MinVer needs to find
# the version tag which is typically NOT on the first commit so we
# retrieve them all.
fetch-depth: 0
ref: ${{ github.ref || 'main' }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
- name: dotnet restore
run: dotnet restore OpenTelemetry.proj -p:RunningDotNetPack=true
- name: dotnet build
run: dotnet build OpenTelemetry.proj --configuration Release --no-restore -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} -p:RunningDotNetPack=true
- name: dotnet pack
run: dotnet pack OpenTelemetry.proj --configuration Release --no-restore --no-build -p:PackTag=${{ github.ref_type == 'tag' && github.ref_name || '' }}
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}-packages
path: '**/bin/**/*.*nupkg'
- name: Publish MyGet
env:
MYGET_TOKEN_EXISTS: ${{ secrets.MYGET_TOKEN != '' }}
if: env.MYGET_TOKEN_EXISTS == 'true' # Skip MyGet publish if run on a fork without the secret
run: |
nuget setApiKey ${{ secrets.MYGET_TOKEN }} -Source https://www.myget.org/F/opentelemetry/api/v2/package
nuget push **/bin/**/*.nupkg -Source https://www.myget.org/F/opentelemetry/api/v2/package
- name: Create GitHub Release draft
if: github.ref_type == 'tag'
shell: pwsh
run: |
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
$notes = ''
$firstPackageVersion = ''
foreach ($package in $packages)
{
$match = [regex]::Match($package, '(.*)\.(\d+\.\d+\.\d+.*?)\.nupkg')
$packageName = $match.Groups[1].Value
$packageVersion = $match.Groups[2].Value
if ($firstPackageVersion -eq '')
{
$firstPackageVersion = $packageVersion
}
$changelogContent = Get-Content -Path "src/$packageName/CHANGELOG.md"
$headingWritten = $false
$started = $false
$content = ""
foreach ($line in $changelogContent)
{
if ($line -like "## ${{ github.ref_name }}" -and $started -ne $true)
{
$started = $true
}
elseif ($line -like "Released *" -and $started -eq $true)
{
continue
}
elseif ($line -like "## *" -and $started -eq $true)
{
break
}
else
{
if ($started -eq $true -and ([string]::IsNullOrWhitespace($line) -eq $false -or $content.Length -gt 0))
{
$content += " " + $line + "`r`n"
}
}
}
if ([string]::IsNullOrWhitespace($content) -eq $true)
{
$content = " No notable changes."
}
$content = $content.trimend()
$notes +=
@"
* NuGet: [$packageName v$packageVersion](https://www.nuget.org/packages/$packageName/$packageVersion)
$content
See [CHANGELOG](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
"@
}
if ($firstPackageVersion -match '-alpha' -or $firstPackageVersion -match '-beta' -or $firstPackageVersion -match '-rc')
{
gh release create ${{ github.ref_name }} `
--title ${{ github.ref_name }} `
--verify-tag `
--notes "$notes" `
--prerelease `
--draft
}
else
{
gh release create ${{ github.ref_name }} `
--title ${{ github.ref_name }} `
--verify-tag `
--notes "$notes" `
--latest `
--draft
}
env:
GH_TOKEN: ${{ github.token }}
- name: Create GitHub draft Pull Request to update stable build version in props
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'core-') && !contains(github.ref_name, '-alpha') && !contains(github.ref_name, '-beta') && !contains(github.ref_name, '-rc')
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch --create release/post-stable-${{ github.ref_name }}-update 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git switch failure'
Return
}
$match = [regex]::Match('${{ github.ref_name }}', '.*?-(.*)')
$packageVersion = $match.Groups[1].Value
(Get-Content Directory.Packages.props) `
-replace '<OTelLatestStableVer>.*<\/OTelLatestStableVer>', "<OTelLatestStableVer>$packageVersion</OTelLatestStableVer>" |
Set-Content Directory.Packages.props
git add Directory.Packages.props 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git add failure'
Return
}
git commit -m "Update OTelLatestStableVer in Directory.Packages.props to $packageVersion." 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git commit failure'
Return
}
git push -u origin release/post-stable-${{ github.ref_name }}-update 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git push failure'
Return
}
$body =
@"
Note: This PR was opened automatically by the [package workflow](https://github.com/${{ github.repository }}/actions/workflows/publish-packages-1.0.yml).
Merge once packages are available on NuGet and the build passes.
## Changes
* Sets `OTelLatestStableVer` in `Directory.Packages.props` to `$packageVersion`.
"@
gh pr create `
--title "[repo] Core stable release $packageVersion updates" `
--body $body `
--base main `
--head release/post-stable-${{ github.ref_name }}-update `
--label infra `
--draft
env:
GH_TOKEN: ${{ github.token }}