Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 254 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
name: Build, Test, Package and Push

# Controls when the action will run.
on:
push:
# Triggers the workflow on pull request events and merges/pushes to master
branches:
- release/*
tags-ignore:
- '**'

pull_request:
types: [opened, synchronize, reopened]

schedule:
# Daily 5am australian/brisbane time
- cron: '0 19 * * *'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
# Required for deploying to octopus.
OCTOPUS_SPACE: "Core Platform"

jobs:
build-packages:
runs-on: windows-latest
permissions:
id-token: write # Required to obtain the ID token from GitHub Actions
contents: write # Read Required to check out code, Write to create Git Tags
checks: write # Required for test-reporter
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET 9.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Set Octopus Deploy Flag
run: |
$shouldDeploy = $true

# Skip if dependabot or prettybot
if ("${{ github.ref }}" -like "*dependabot*" -or "${{ github.ref }}" -like "*prettybot*") {
$shouldDeploy = $false
}

# Skip merge builds unless targeting octopus or release branches
if ("${{ github.ref }}" -like "*/merge" -and
"${{ github.base_ref }}" -notlike "*octopus*" -and
"${{ github.base_ref }}" -notlike "*release/*") {
$shouldDeploy = $false
}
Write-Host "ref: ${{ github.ref }}"
Write-Host "base_ref: ${{ github.base_ref }}"
Write-Host "shouldDeploy: $shouldDeploy"

echo "DEPLOY_TO_OCTOPUS=$shouldDeploy" >> $env:GITHUB_ENV
shell: powershell

- name: Set Release Label
run: |
$branchName = "${{ github.head_ref || github.ref_name }}"

if ("${{ github.event_name }}" -eq "schedule") {
$releaseLabel = "octopus-nightly-$(Get-Date -Format 'yyyyMMdd')"
} elseif ($branchName -like "release/*") {
# All merges to "release/*" branches are considered release builds.
$releaseLabel = "octopus-release"
} else {
# Since we use pre release, we need to prefix all branch names with dev- so it is
# alphabetically sorted to be lower than the above "octopus-release" if we don't.
# a branch name starting with a letter greater than "o" would be selected by renovate bot.\

# Use the branch name, sanitizing it for version strings and prefix with dev-
$releaseLabel = "dev-" + ($branchName -replace '[^a-zA-Z0-9\-\.]', '-')

# Final Version must be less than 64 chars to comply with nuget version string limit
# e.g. dev-feature-very-long-branch-name-that-exceeds -> "6.14.1-dev-feature-very-long-branch-name-that-exc.1111"
if ($releaseLabel.Length -gt 40) {
$releaseLabel = $releaseLabel.Substring(0, 40)
}
}
Write-Host "event_name: ${{ github.event_name }}"
Write-Host "branch_name: $branchName"
Write-Host "release_label: $releaseLabel"

echo "RELEASE_LABEL=$releaseLabel" >> $env:GITHUB_ENV
shell: powershell

- name: Set BuildNumber
run: |
# The build number becomes the last part of the net472 assembly version and of every file version. That part
# must stay at or below 65534, and upstream NuGet 8.0 adds 100 to it (see Set PackageVersion).
# run_number * 10 + run_attempt gives each attempt its own number and leaves room for about 6,500 workflow runs.
# Attempts above 9 reuse the number of attempt 9.
$runNumber = [int]"${{ github.run_number }}"
$runAttempt = [Math]::Min([int]"${{ github.run_attempt }}", 9)
$buildNumber = $runNumber * 10 + $runAttempt
Write-Host "buildNumber: $buildNumber"
echo "BUILD_NUMBER=$buildNumber" >> $env:GITHUB_ENV

- name: Set PackageVersion
run: |
$buildNumber = "${{ env.BUILD_NUMBER }}"
$releaseLabel = "${{ env.RELEASE_LABEL }}"

# Read version from config.props
$configPath = "build\config.props"
$configContent = Get-Content $configPath -Raw

$majorMatch = [regex]::Match($configContent, '<MajorNuGetVersion[^>]*>(\d+)</MajorNuGetVersion>')
$minorMatch = [regex]::Match($configContent, '<MinorNuGetVersion[^>]*>(\d+)</MinorNuGetVersion>')
$patchMatch = [regex]::Match($configContent, '<PatchNuGetVersion[^>]*>(\d+)</PatchNuGetVersion>')

$major = $majorMatch.Groups[1].Value
$minor = $minorMatch.Groups[1].Value
# Version the fork one patch above the upstream release it is based on (e.g. upstream 8.0.0 -> 8.0.1-octopus-release.N).
# A pre-release of 8.0.0 sorts below 8.0.0, so security scanners would treat our package as older than the upstream
# release it contains and report vulnerabilities that release already fixed.
# build/config.props keeps the upstream version so merges from upstream stay conflict free. The build step reads the
# bumped patch from the PatchNuGetVersion environment variable, because config.props only sets it when it is empty.
$patch = [int]$patchMatch.Groups[1].Value + 1
echo "PatchNuGetVersion=$patch" >> $env:GITHUB_ENV
$baseVersion = "$major.$minor.$patch"

# Upstream NuGet 8.0 adds 100 to the build number of every package it builds. See the "Offset the CI build number
# by 100" block in build/config.props. Microsoft added it to stop 8.0 packages colliding with 7.12 packages on their
# own feeds, and it only applies while the result still fits in a UInt16 (<= 65535).
# build/config.props keeps that upstream logic so merges from upstream stay conflict free. We apply the same offset
# here so PACKAGE_VERSION matches the package file names the build writes to /artifacts/nupkgs/
# (e.g. build number 4621 produces 8.0.1-octopus-release.4721).
$packageBuildNumber = [int]$buildNumber
if (($packageBuildNumber + 100) -le 65535) {
$packageBuildNumber += 100
}

# This matches logic within the build that will take a 'final' and prepend 'octopus'
if ($releaseLabel -eq "final") {
$packageVersion = "$baseVersion-octopus.$packageBuildNumber"
} else {
# E.g releaseLabel = (xprivate, release, nightly#####)
$packageVersion = "$baseVersion-$releaseLabel.$packageBuildNumber"
}
Write-Host "packageVersion: $packageVersion"
# This needs to match the packages in the /artifacts/nupkgs/ folder after build
echo "PACKAGE_VERSION=$packageVersion" >> $env:GITHUB_ENV

# required for building the code see: https://github.com/NuGet/NuGet.Client/blob/dev/CONTRIBUTING.md#build
- name: Configure Build Environment
run: .\configure.ps1 -Force
shell: powershell

- name: Build NuGet Packages 📦
id: build
run: .\build.ps1 -Configuration Release -ReleaseLabel ${{ env.RELEASE_LABEL }} -BuildNumber ${{ env.BUILD_NUMBER }} -Pack -CI

- name: Run NuGet.Core Unit Tests 🧪
run: |
Get-ChildItem -Path "test/NuGet.Core.Tests" -Filter "*.csproj" -Recurse | ForEach-Object {
dotnet test $_.FullName --configuration Release --no-build --logger trx --results-directory ./build/TestResults/ --verbosity minimal
}
shell: powershell

- name: Unit test report
uses: dorny/test-reporter@6e6a65b7a0bd2c9197df7d0ae36ac5cee784230c # v2.0.0
if: success() || failure() # run this step even if previous step failed
with:
name: NuGet Core unit test results
path: ./build/TestResults/*.trx
reporter: dotnet-trx
fail-on-error: true

- name: Tag release (when release label is final) 🏷️
if: ${{ env.RELEASE_LABEL == 'final' }}
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ env.PACKAGE_VERSION }}",
sha: context.sha
})

- name: Login to Octopus Deploy 🐙
if: env.DEPLOY_TO_OCTOPUS == 'True'
uses: OctopusDeploy/login@v1
with:
server: ${{ secrets.OCTOPUS_URL }}
service_account_id: cc09980f-9a73-46c3-8f3f-e3f673740c1f

- name: Push build information to Octopus Deploy 🐙
uses: OctopusDeploy/push-build-information-action@v3
if: (! contains(github.ref, '/merge')) && (! contains(github.ref, '/dependabot/')) && (! contains(github.ref, 'prettybot/'))
with:
packages: |
NuGet.CommandLine
NuGet.Common
NuGet.Configuration
NuGet.Frameworks
NuGet.Packaging
NuGet.Protocol
NuGet.Versioning
NuGet.PackageManagement
NuGet.Build.Tasks
NuGet.Commands
NuGet.Resolver
version: ${{ env.PACKAGE_VERSION }}

- name: Push to Octopus 🐙
if: env.DEPLOY_TO_OCTOPUS == 'True'
uses: OctopusDeploy/push-package-action@v3
with:
packages: |
./artifacts/nupkgs/NuGet.CommandLine.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Common.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Configuration.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Frameworks.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Packaging.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Protocol.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Versioning.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.PackageManagement.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Build.Tasks.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Commands.${{ env.PACKAGE_VERSION }}.nupkg
./artifacts/nupkgs/NuGet.Resolver.${{ env.PACKAGE_VERSION }}.nupkg

- name: Create Release in Octopus 🐙
if: env.DEPLOY_TO_OCTOPUS == 'True'
uses: OctopusDeploy/create-release-action@v3
with:
project: Nuget.Client
release_number: ${{ env.PACKAGE_VERSION }}
# Packages docs:
# Format: StepName:Version or PackageID:Version or StepName:PackageName:Version.
# We specifically target the package name of NuGet.CommandLine/SourcePackage because our step uses both
# - SourcePackage = ${{ env.PACKAGE_VERSION }} === 6.14.0-release.213 (this is StepName:PackageName:Version)
# - Nuget.CommandLine = 6.14.0 (this not listed here will resolve to its PackageID)
packages: |
Package Push - NuGet.CommandLine:SourcePackage:${{ env.PACKAGE_VERSION }}
NuGet.Common:${{ env.PACKAGE_VERSION }}
NuGet.Configuration:${{ env.PACKAGE_VERSION }}
NuGet.Frameworks:${{ env.PACKAGE_VERSION }}
NuGet.Packaging:${{ env.PACKAGE_VERSION }}
NuGet.Protocol:${{ env.PACKAGE_VERSION }}
NuGet.Versioning:${{ env.PACKAGE_VERSION }}
NuGet.PackageManagement:${{ env.PACKAGE_VERSION }}
NuGet.Build.Tasks:${{ env.PACKAGE_VERSION }}
NuGet.Commands:${{ env.PACKAGE_VERSION }}
NuGet.Resolver:${{ env.PACKAGE_VERSION }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ launchSettings.json
*.imagemanifest

test/ManualTests/
.claude/settings.local.json
6 changes: 3 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ param (
[ValidateSet('debug', 'release')]
[Alias('c')]
[string]$Configuration,
[ValidatePattern('^(beta|final|preview|rc|release|rtm|xprivate|zlocal)([0-9]*)$')]
[ValidatePattern('^[a-zA-Z0-9\-\.]+$')]
[Alias('l')]
[string]$ReleaseLabel = 'zlocal',
[Alias('n')]
Expand Down Expand Up @@ -221,7 +221,7 @@ Invoke-BuildStep 'Running Restore RTM' {
exit 1
}
} `
-skip:(-not $CI)`
-skip:(-not $CI -or ($ReleaseLabel -ne 'rtm'))`
-ev +BuildErrors


Expand Down Expand Up @@ -249,7 +249,7 @@ Invoke-BuildStep 'Packing RTM' {
exit 1
}
} `
-skip:(-not $CI)`
-skip:(-not $CI -or ($ReleaseLabel -ne 'rtm'))`
-ev +BuildErrors

## Calculating Build time
Expand Down
8 changes: 4 additions & 4 deletions build/config.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</PropertyGroup>
</When>
<!-- If we are excluding the build number, show the release label unless we are RTM. -->
<When Condition="'$(ReleaseLabel)' != 'rtm' AND '$(ReleaseLabel)' != 'svc' AND '$(ReleaseLabel)' != 'rc' ">
<When Condition="'$(ReleaseLabel)' != 'rtm' AND '$(ReleaseLabel)' != 'svc' AND '$(ReleaseLabel)' != 'rc'">
<PropertyGroup>
<PreReleaseInformationVersion>-$(ReleaseLabel)</PreReleaseInformationVersion>
</PropertyGroup>
Expand All @@ -90,12 +90,12 @@

<!-- Nuspec defaults -->
<PropertyGroup>
<Authors>Microsoft</Authors>
<PackageProjectUrl>https://aka.ms/nugetprj</PackageProjectUrl>
<Authors>Microsoft, Octopus Deploy</Authors>
<PackageProjectUrl>https://github.com/OctopusDeploy/NuGet.Client</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/NuGet/NuGet.Client</RepositoryUrl>
<RepositoryUrl>https://github.com/OctopusDeploy/NuGet.Client</RepositoryUrl>
<PackageTags>nuget</PackageTags>
<Description>NuGet client library.</Description>
<Copyright>&#169; Microsoft Corporation. All rights reserved.</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion runTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ param (
[ValidateSet('debug', 'release')]
[Alias('c')]
[string]$Configuration,
[ValidatePattern('^(beta|final|preview|rc|release|rtm|xprivate|zlocal)([0-9]*)$')]
[ValidatePattern('^[a-zA-Z0-9\-\.]+$')]
[Alias('l')]
[string]$ReleaseLabel = 'zlocal',
[Alias('n')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public sealed class PackageSearchMetadataContextInfo
public Uri? PackageDetailsUrl { get; internal set; }
public bool RequireLicenseAcceptance { get; internal set; }
public string? Summary { get; internal set; }
public string? ReleaseNotes { get; internal set; }
public bool PrefixReserved { get; internal set; }
public bool IsRecommended { get; internal set; }
public (string modelVersion, string vsixVersion)? RecommenderVersion { get; internal set; }
Expand Down Expand Up @@ -77,6 +78,7 @@ public static PackageSearchMetadataContextInfo Create(IPackageSearchMetadata pac
(packageSearchMetadata as ClonedPackageSearchMetadata)?.PackagePath,
RequireLicenseAcceptance = packageSearchMetadata.RequireLicenseAcceptance,
Summary = packageSearchMetadata.Summary,
ReleaseNotes = packageSearchMetadata.ReleaseNotes,
PrefixReserved = packageSearchMetadata.PrefixReserved,
IsListed = packageSearchMetadata.IsListed,
DependencySets = packageSearchMetadata.DependencySets?.ToList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public RecommendedPackageSearchMetadata(IPackageSearchMetadata inner, (string, s
public string? Summary => _inner.Summary;
public string? Tags => _inner.Tags;
public string Title => _inner.Title;
public string? ReleaseNotes => _inner.ReleaseNotes;
public bool IsListed => _inner.IsListed;
public bool PrefixReserved => _inner.PrefixReserved;
public LicenseMetadata? LicenseMetadata => _inner.LicenseMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class TransitivePackageSearchMetadata : IPackageSearchMetadata

public string Title => _packageSearchMetadata.Title;

public string? ReleaseNotes => _packageSearchMetadata.ReleaseNotes;

public bool IsListed => _packageSearchMetadata.IsListed;

public bool PrefixReserved => _packageSearchMetadata.PrefixReserved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public bool Equals(PackageSource? other)
}

return Name.Equals(other.Name, StringComparison.CurrentCultureIgnoreCase) &&
Source.Equals(other.Source, StringComparison.OrdinalIgnoreCase);
Source.Equals(other.Source, StringComparison.OrdinalIgnoreCase) &&
Equals(Credentials, other.Credentials);
}

public override bool Equals(object? obj)
Expand Down
1 change: 1 addition & 0 deletions src/NuGet.Core/NuGet.Configuration/Proxy/IProxyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ namespace NuGet.Configuration
public interface IProxyCache
{
IWebProxy? GetProxy(Uri uri);
ICredentials? GetDefaultProxyCredentials();
}
}
Loading
Loading