Skip to content

WIP: Modernizing CI #4887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
50 changes: 50 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
ci:
name: dotnet
strategy:
matrix:
os: [ windows-latest, macos-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
env:
DOTNET_NOLOGO: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dotnet
uses: actions/setup-dotnet@v4
with:
cache: true
cache-dependency-path: '**/*.csproj'
global-json-file: ./global.json

- name: Install PSResources
shell: pwsh
run: ./tools/installPSResources.ps1

- name: Build, test, and package
shell: pwsh
run: Invoke-Build -Configuration Release -TestFramework net8.0 RunTests, ZipRelease

- name: Upload build artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: PSReadLine-module-${{ matrix.os }}
path: bin/Release/PSReadLine.zip

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: PSReadLine-test-results-${{ matrix.os }}
path: test/TestResults/xUnitTestResults.en-US.xml
6 changes: 3 additions & 3 deletions MockPSConsole/MockPSConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>MockPSConsole</RootNamespace>
<AssemblyName>MockPSConsole</AssemblyName>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<FileAlignment>512</FileAlignment>
<ApplicationManifest>Program.manifest</ApplicationManifest>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
Expand All @@ -14,8 +14,8 @@
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.2.24" />
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.4.11" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions PSReadLine.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = (property Configuration Release),

[ValidateSet("net472", "net6.0")]
[ValidateSet("net472", "net8.0")]
[string]$TestFramework,

[switch]$CheckHelpContent
Expand All @@ -31,7 +31,7 @@ Import-Module "$PSScriptRoot/tools/helper.psm1"
$targetDir = "bin/$Configuration/PSReadLine"

if (-not $TestFramework) {
$TestFramework = $IsWindows ? "net472" : "net6.0"
$TestFramework = $IsWindows ? "net472" : "net8.0"
}

function ConvertTo-CRLF([string] $text) {
Expand All @@ -58,7 +58,7 @@ Synopsis: Build the Polyfiller assembly
#>
task BuildPolyfiller @polyFillerParams {
exec { dotnet publish -c $Configuration -f 'netstandard2.0' Polyfill }
exec { dotnet publish -c $Configuration -f 'net6.0' Polyfill }
exec { dotnet publish -c $Configuration -f 'net8.0' Polyfill }
}

<#
Expand Down Expand Up @@ -123,7 +123,7 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
}

Copy-Item "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/netstd" -Force
Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force
Copy-Item "Polyfill/bin/$Configuration/net8.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force

$binPath = "PSReadLine/bin/$Configuration/netstandard2.0/publish"
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir
Expand Down
6 changes: 3 additions & 3 deletions Polyfill/Polyfill.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<PropertyGroup>
<AssemblyName>Microsoft.PowerShell.PSReadLine.Polyfiller</AssemblyName>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Management.Automation" Version="7.2.24" />
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Management.Automation" Version="7.4.11" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ The build script `build.ps1` can be used to bootstrap, build and test the projec
* Build: `./build.ps1 -Configuration Debug`
* Test:
* Targeting .NET 4.7.2 (Windows only): `./build.ps1 -Test -Configuration Debug -Framework net472`
* Targeting .NET 6.0: `./build.ps1 -Test -Configuration Debug -Framework net6.0`
* Targeting .NET 6.0: `./build.ps1 -Test -Configuration Debug -Framework net8.0`

After build, the produced artifacts can be found at `<your-local-repo-root>/bin/Debug`.

Expand Down
26 changes: 0 additions & 26 deletions appveyor.yml

This file was deleted.

8 changes: 4 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Build the main module with the default configuration (Debug) targeting 'netstandard2.0'.
.EXAMPLE
PS > .\build.ps1 -Test
Run xUnit tests with the default configuration (Debug) and the default target framework (net472 on Windows or net6.0 otherwise).
Run xUnit tests with the default configuration (Debug) and the default target framework (net472 on Windows or net8.0 otherwise).
.PARAMETER Clean
Clean the local repo, but keep untracked files.
.PARAMETER Bootstrap
Expand All @@ -28,10 +28,10 @@
.PARAMETER Framework
The target framework when testing:
- net472: run tests with .NET Framework
- net6.0: run tests with .NET 6.0
- net8.0: run tests with .NET 6.0
When not specified, the target framework is determined by the current OS platform:
- use 'net472' on Windows
- use 'net6.0' on Unix platforms
- use 'net8.0' on Unix platforms
#>
[CmdletBinding(DefaultParameterSetName = 'default')]
param(
Expand All @@ -48,7 +48,7 @@ param(
[switch] $CheckHelpContent,

[Parameter(ParameterSetName = 'test')]
[ValidateSet("net472", "net6.0")]
[ValidateSet("net472", "net8.0")]
[string] $Framework,

[Parameter(ParameterSetName = 'default')]
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.405",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
5 changes: 1 addition & 4 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<configuration>
<packageSources>
<clear />
<add key="PowerShell_PublicPackages" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
<add key="PowerShellCore_PublicPackages" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
10 changes: 9 additions & 1 deletion test/ConsoleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public static IEnumerable<string> GetKeyboardLayoutList()

public static string GetKeyboardLayout()
{
// In CI environments like GitHub Actions, keyboard layout detection can fail
// or return incorrect results. Default to en-US in these cases.
if (Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true" ||
Environment.GetEnvironmentVariable("TF_BUILD") == "true" ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "en-US";
}

var layout = GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), out var processId));
return GetLayoutNameFromHKL(layout);
}
Expand Down Expand Up @@ -100,4 +109,3 @@ public override string ToString()
}
}
}

6 changes: 3 additions & 3 deletions test/PSReadLine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>library</OutputType>
<RootNamespace>UnitTestPSReadLine</RootNamespace>
<AssemblyName>PSReadLine.Tests</AssemblyName>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<IsCodedUITest>False</IsCodedUITest>
Expand All @@ -19,8 +19,8 @@
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.24" />
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.11" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 3 additions & 5 deletions tools/helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function Start-TestRun
$testResultFile = Join-Path $testResultFolder $testResultFile

$stdOutput, $stdError = @(New-TemporaryFile; New-TemporaryFile)
$arguments = 'test', '--no-build', '-c', $Configuration, '-f', $Framework, '--filter', $filter, '--logger', "xunit;LogFilePath=$testResultFile"
$arguments = 'test', '--no-build', '-c', $Configuration, '-f', $Framework, '--filter', $filter, '--logger', "xunit;LogFilePath=$testResultFile", '--logger', 'console;verbosity=normal'

Start-Process -FilePath dotnet -Wait -RedirectStandardOutput $stdOutput -RedirectStandardError $stdError -ArgumentList $arguments
Get-Content $stdOutput, $stdError
Expand All @@ -224,15 +224,14 @@ function Start-TestRun

try
{
$env:PSREADLINE_TESTRUN = 1
Push-Location "$RepoRoot/test"

$xUnitTestExecuted = $true
if ($IsWindowsEnv)
{
if ($env:APPVEYOR -or $env:TF_BUILD)
if ($env:GITHUB_ACTIONS -or $env:TF_BUILD)
{
# AppVeyor CI builder only has en-US keyboard layout installed.
# GitHub Actions CI builder only has en-US keyboard layout installed.
# We have to run tests from a new process because `GetCurrentKeyboardLayout` simply fails when called from
# the `pwsh` process started by AppVeyor. Our xUnit tests depends on `GetCurrentKeyboardLayout` to tell if
# a test case should run.
Expand Down Expand Up @@ -298,7 +297,6 @@ function Start-TestRun
finally
{
Pop-Location
Remove-Item env:PSREADLINE_TESTRUN
}
}

Expand Down
20 changes: 20 additions & 0 deletions tools/installPSResources.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param(
[ValidateSet("PSGallery", "CFS")]
[string]$PSRepository = "PSGallery"
)

if ($PSRepository -eq "CFS" -and -not (Get-PSResourceRepository -Name CFS -ErrorAction SilentlyContinue)) {
Register-PSResourceRepository -Name CFS -Uri "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/PowerShellGalleryMirror/nuget/v3/index.json"
}

# NOTE: Due to a bug in Install-PSResource with upstream feeds, we have to
# request an exact version. Otherwise, if a newer version is available in the
# upstream feed, it will fail to install any version at all.
Install-PSResource -Verbose -TrustRepository -RequiredResource @{
InvokeBuild = @{
version = "5.12.1"
repository = $PSRepository
}
}
Loading