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
9 changes: 2 additions & 7 deletions .github/actions/run-dotnet-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ inputs:
runs:
using: composite
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ inputs.dotnet }}

- name: Setup repository .NET SDK
uses: actions/setup-dotnet@v6
uses: ./.github/actions/setup-repository-dotnet
with:
global-json-file: global.json
dotnet-version: ${{ inputs.dotnet }}

- name: Set cloud version
shell: pwsh
Expand Down
55 changes: 55 additions & 0 deletions .github/actions/setup-repository-dotnet/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Setup repository .NET SDK
description: >-
Installs the exact .NET SDK pinned in global.json, plus any additional SDKs
the job needs, into a job-private directory and verifies that the build
resolves the pinned version. global.json rolls forward to newer SDK feature
bands for contributors; runner images preinstall newer SDKs into the default
directory, which that policy would otherwise select on CI. See
.github/scripts/select-repository-sdk.ps1.

inputs:
dotnet-version:
description: >-
Newline-separated additional .NET SDK versions, for example the 8.0.x,
9.0.x and 10.0.x SDKs whose runtimes older target frameworks execute on.
The global.json SDK is always installed and always selected.
required: false
default: ''

outputs:
sdk:
description: The exact .NET SDK version the job builds with.
value: ${{ steps.select.outputs.sdk }}

runs:
using: composite
steps:
- name: Select the repository .NET SDK
id: select
shell: pwsh
env:
ADDITIONAL_SDKS: ${{ inputs.dotnet-version }}
run: ./.github/scripts/select-repository-sdk.ps1 -AdditionalSdks $env:ADDITIONAL_SDKS

- name: Install .NET SDKs
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ steps.select.outputs.versions }}

- name: Verify the repository .NET SDK
shell: pwsh
env:
EXPECTED_SDK: ${{ steps.select.outputs.sdk }}
run: |
$dotnet = (Get-Command dotnet).Source
dotnet --list-sdks
$actual = (dotnet --version | Out-String).Trim()
if ($actual -cne $env:EXPECTED_SDK) {
Write-Host "::error::'$dotnet' selected .NET SDK '$actual' instead of the global.json SDK '$($env:EXPECTED_SDK)'."
exit 1
}
if (-not $dotnet.StartsWith($env:DOTNET_INSTALL_DIR, [StringComparison]::OrdinalIgnoreCase)) {
Write-Host "::error::'$dotnet' is not the job-private installation in '$($env:DOTNET_INSTALL_DIR)'."
exit 1
}
Write-Host "Using .NET SDK $actual from '$dotnet'."
81 changes: 81 additions & 0 deletions .github/scripts/install-aspire-bundle.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<#
.SYNOPSIS
Installs the Aspire CLI bundle before a solution build that contains an Aspire AppHost.

.DESCRIPTION
tools/Opc.Ua.Lens.AppHost builds with AspireUseCliBundle. When Aspire home
holds no bundle, the AppHost build downloads it (about 350 MB) by running
'aspire setup' itself under a two-minute timeout. On cold CI runners that
in-build setup intermittently fails, and the build then fails with
ASPIRE009. Installing the bundle up front, without that timeout and with
retries, lets the AppHost build resolve the existing layout instead.

The bundle version is the Aspire.Hosting.AppHost version that
Directory.Packages.props pins.

.PARAMETER PackagesPropsPath
Path to Directory.Packages.props.

.PARAMETER AspireHome
Aspire home that receives the bundle. Defaults to ASPIRE_HOME or, when that
is not set, to the .aspire directory in the user profile, which is where the
AppHost build looks.

.PARAMETER Attempts
Number of install attempts before the script fails.
#>
param(
[string] $PackagesPropsPath = 'Directory.Packages.props',
[string] $AspireHome = '',
[int] $Attempts = 3
)

$ErrorActionPreference = 'Stop'

if (-not (Test-Path -LiteralPath $PackagesPropsPath -PathType Leaf))
{
Write-Host "::error::'$PackagesPropsPath' does not exist; check out the repository first."
exit 1
}

[xml] $props = Get-Content -LiteralPath $PackagesPropsPath -Raw
$version = @($props.Project.ItemGroup.PackageVersion |
Where-Object { $_.Include -ceq 'Aspire.Hosting.AppHost' } |
ForEach-Object { $_.Version })
if ($version.Count -ne 1 -or $version[0] -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$')
{
Write-Host "::error::'$PackagesPropsPath' must pin exactly one Aspire.Hosting.AppHost version."
exit 1
}
$version = $version[0]

if ([string]::IsNullOrWhiteSpace($AspireHome))
{
$AspireHome = if ([string]::IsNullOrWhiteSpace($env:ASPIRE_HOME))
{
Join-Path ([Environment]::GetFolderPath('UserProfile')) '.aspire'
}
else
{
$env:ASPIRE_HOME
}
}

$bundle = Join-Path $AspireHome 'bundle'
for ($attempt = 1; $attempt -le $Attempts; $attempt++)
{
Write-Host "Installing the Aspire $version CLI bundle into '$AspireHome' (attempt $attempt of $Attempts)."
dotnet dnx --yes "aspire.cli@$version" -- setup --install-path $AspireHome
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0 -and
(Test-Path -LiteralPath (Join-Path $bundle 'dcp') -PathType Container) -and
(Test-Path -LiteralPath (Join-Path $bundle 'dashboard') -PathType Container))
{
Write-Host "Installed the Aspire $version CLI bundle into '$bundle'."
exit 0
}
Write-Host "::warning::Aspire bundle setup attempt $attempt exited with $exitCode or left no complete bundle."
}

Write-Host "::error::Could not install the Aspire $version CLI bundle into '$AspireHome' after $Attempts attempts."
exit 1
98 changes: 98 additions & 0 deletions .github/scripts/select-repository-sdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<#
.SYNOPSIS
Selects the exact repository .NET SDK and a job-private install directory.

.DESCRIPTION
global.json pins the minimum SDK version with rollForward 'latestFeature' so
that contributors can build with any newer feature band or patch of that
major version they have installed. The dotnet host applies that policy to
every SDK in its own installation directory, and GitHub-hosted runner images
preinstall newer SDKs into the default directory. A job that installs the
repository SDK there therefore builds with whatever newer SDK the image
happens to carry, and that SDK's new analyzers can break the build.

This script points actions/setup-dotnet at a directory under RUNNER_TEMP
that contains only the SDKs the job installs, so the host can resolve
nothing newer than the global.json version. It writes:

DOTNET_INSTALL_DIR (GITHUB_ENV) The job-private install directory.
sdk (GITHUB_OUTPUT) The exact global.json SDK version.
versions (GITHUB_OUTPUT) The SDKs to install, the global.json
version last.

.PARAMETER AdditionalSdks
Newline-separated SDK versions the job needs besides the global.json SDK,
for example the 8.0.x and 9.0.x SDKs whose runtimes the older target
frameworks' tests execute on.

.PARAMETER GlobalJsonPath
Path to the repository global.json.

.PARAMETER InstallDirectory
Directory that receives the SDKs. Defaults to RUNNER_TEMP/dotnet, which is
empty at the start of every job.
#>
param(
[string] $AdditionalSdks = '',
[string] $GlobalJsonPath = 'global.json',
[string] $InstallDirectory = ''
)

$ErrorActionPreference = 'Stop'

if (-not (Test-Path -LiteralPath $GlobalJsonPath -PathType Leaf))
{
Write-Host "::error::'$GlobalJsonPath' does not exist; check out the repository first."
exit 1
}

$sdk = (Get-Content -LiteralPath $GlobalJsonPath -Raw | ConvertFrom-Json).sdk.version
if ([string]::IsNullOrWhiteSpace($sdk) -or $sdk -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$')
{
Write-Host "::error::'$GlobalJsonPath' must pin an exact sdk.version; found '$sdk'."
exit 1
}

if ([string]::IsNullOrWhiteSpace($InstallDirectory))
{
if ([string]::IsNullOrWhiteSpace($env:RUNNER_TEMP))
{
Write-Host '::error::RUNNER_TEMP is not set; pass -InstallDirectory explicitly.'
exit 1
}
$InstallDirectory = Join-Path $env:RUNNER_TEMP 'dotnet'
}

$versions = [System.Collections.Generic.List[string]]::new()
foreach ($line in $AdditionalSdks -split '\r?\n')
{
$version = $line.Trim()
if ($version.Length -eq 0 -or $version -ceq $sdk -or $versions.Contains($version))
{
continue
}
if ($version -notmatch '^\d+(\.(\d+|x)){1,2}(-[0-9A-Za-z.-]+)?$')
{
Write-Host "::error::'$version' is not a .NET SDK version that actions/setup-dotnet accepts."
exit 1
}
$versions.Add($version)
}
$versions.Add($sdk)

if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_ENV))
{
"DOTNET_INSTALL_DIR=$InstallDirectory" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
}
if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_OUTPUT))
{
$delimiter = "versions_$([guid]::NewGuid().ToString('N'))"
@(
"sdk=$sdk"
"versions<<$delimiter"
$versions
$delimiter
) | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
}

Write-Host "Installing .NET SDK(s) $($versions -join ', ') into '$InstallDirectory'; the build uses $sdk."
38 changes: 17 additions & 21 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ jobs:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
uses: ./.github/actions/setup-repository-dotnet

- name: Download test results
uses: actions/download-artifact@v8
Expand Down Expand Up @@ -498,9 +496,7 @@ jobs:
fetch-depth: 0

- name: Setup .NET from global.json
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
uses: ./.github/actions/setup-repository-dotnet

- name: Set Cloud Version
shell: pwsh
Expand Down Expand Up @@ -568,20 +564,25 @@ jobs:
# a shallow clone.
fetch-depth: 0

- name: Setup .NET SDKs for build matrix
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ matrix.entry.dotnet }}

- name: Setup repository .NET SDK
uses: actions/setup-dotnet@v6
uses: ./.github/actions/setup-repository-dotnet
with:
global-json-file: global.json
dotnet-version: ${{ matrix.entry.dotnet }}

- name: Set cloud version
shell: pwsh
run: ./.azurepipelines/set-version.ps1

# Only UA.slnx contains the Aspire AppHost, which imports the Aspire SDK
# when CustomTestTarget is empty, net10.0 or net11.0.
- name: Install the Aspire CLI bundle
if: >-
${{ matrix.entry.solution == 'UA.slnx' &&
(matrix.entry.customTestTarget == 'net10.0' || matrix.entry.customTestTarget == 'net11.0' ||
matrix.entry.customTestTarget == '') }}
shell: pwsh
run: ./.github/scripts/install-aspire-bundle.ps1

- name: Build ${{ matrix.entry.solution }} (${{ matrix.entry.customTestTarget }})
shell: pwsh
env:
Expand Down Expand Up @@ -610,10 +611,9 @@ jobs:
# Full history: Nerdbank.GitVersioning refuses to compute a version from
# a shallow clone, which fails the build before any test runs.
fetch-depth: 0
- uses: actions/setup-dotnet@v6
- uses: ./.github/actions/setup-repository-dotnet
with:
dotnet-version: 10.0.x
global-json-file: global.json
- name: Validate manifest and negative controls
shell: pwsh
run: ./fuzzing/Scripts/validate-fuzz-manifest.ps1 -SelfTest
Expand Down Expand Up @@ -664,17 +664,13 @@ jobs:
# Full history: Nerdbank.GitVersioning refuses to compute a version from
# a shallow clone, which fails the build before any test runs.
fetch-depth: 0
- name: Setup .NET 8, 9 and 10 runtimes
uses: actions/setup-dotnet@v6
- name: Setup repository .NET SDK with .NET 8, 9 and 10 runtimes
uses: ./.github/actions/setup-repository-dotnet
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Setup repository .NET SDK
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
- name: Run fuzz regressions
shell: pwsh
run: ./fuzzing/Scripts/test-fuzzing.ps1 -Framework '${{ matrix.framework }}' -ResultsDirectory '${{ runner.temp }}/fuzz-results'
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ jobs:
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
uses: ./.github/actions/setup-repository-dotnet
# UA.slnx contains the Aspire AppHost, which needs the Aspire CLI bundle.
- name: Install the Aspire CLI bundle
shell: pwsh
run: ./.github/scripts/install-aspire-bundle.ps1
# https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#c-compiler-flags-injected-by-codeql-for-manual-builds
#
# CustomTestTarget pins the build to a single target framework (see
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ jobs:
fetch-depth: 0

- name: Set up .NET 10
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
uses: ./.github/actions/setup-repository-dotnet

- name: Set Version
shell: pwsh
Expand Down Expand Up @@ -217,9 +215,7 @@ jobs:
fetch-depth: 0

- name: Set up .NET 10
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
uses: ./.github/actions/setup-repository-dotnet

- name: Set Version
shell: pwsh
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/interop-foreign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ jobs:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v6
uses: ./.github/actions/setup-repository-dotnet
with:
dotnet-version: 10.0.x
global-json-file: global.json

# ---------------------------------------------------------------- node-opcua
- name: Setup Node.js
Expand Down
Loading
Loading