Skip to content

Build, pack, and publish to MyGet #183

Build, pack, and publish to MyGet

Build, pack, and publish to MyGet #183

#################################################
################### 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
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
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 }}