Removed old not-used-anymore docker-based tests for PS release packages (#16224)

This commit is contained in:
Andrew 2021-10-15 10:46:36 -07:00 committed by GitHub
parent 3ecf4b3a1d
commit a5f283537a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 0 additions and 812 deletions

View File

@ -1,25 +0,0 @@
# Docker tests
## Windows and Linux containers
The tests must be run separately on the Windows and Linux docker daemons. You can use the Linux docker daemon on Windows, but that will only test Linux containers not Windows Containers.
## To building and basic behavior of the containers
```PowerShell
Invoke-Pester
```
Note: be sure to do this using both the Windows and Linux docker daemon.
## To test the productions containers
```PowerShell
Invoke-Pester -Tag Behavior
```
## To test only building the containers
```PowerShell
Invoke-Pester -Tag Build
```

View File

@ -1,23 +0,0 @@
FROM centos:7
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN yum install -y \
curl \
glibc-locale-source \
git
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME \
&& yum install -y $PACKAGENAME
RUN $TESTDOWNLOADCOMMAND
RUN pwsh$PREVIEWSUFFIX -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,29 +0,0 @@
FROM debian:stretch
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
curl \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME
RUN dpkg -i $PACKAGENAME || :
RUN apt-get install -y -f --no-install-recommends
RUN $TESTDOWNLOADCOMMAND
RUN pwsh$PREVIEWSUFFIX -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,26 +0,0 @@
FROM fedora:28
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN dnf install -y \
curl \
glibc-locale-source \
git \
compat-openssl10 \
&& dnf upgrade-minimal -y --security \
&& dnf clean all
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME
RUN dnf install -y $PACKAGENAME
RUN $TESTDOWNLOADCOMMAND
RUN pwsh$PREVIEWSUFFIX -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,31 +0,0 @@
FROM centos:7
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN yum install -y \
glibc-locale-source \
git
# Install dotnet-runtime
RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
RUN yum install -y \
dotnet-runtime-2.1
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell
RUN tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,31 +0,0 @@
FROM microsoft/dotnet:2.1.7-runtime-stretch-slim
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell
RUN tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,31 +0,0 @@
FROM microsoft/dotnet:3.0.100-preview-sdk
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell \
&& tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,38 +0,0 @@
FROM fedora:28
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN dnf install -y \
glibc-locale-source \
git \
compat-openssl10 \
&& dnf upgrade-minimal -y --security \
&& dnf clean all
# Install dotnet-runtime
RUN rpm --import https://packages.microsoft.com/keys/microsoft.asc
ADD https://packages.microsoft.com/config/fedora/27/prod.repo .
RUN mv prod.repo /etc/yum.repos.d/microsoft-prod.repo
RUN dnf install -y \
dotnet-runtime-2.1 \
&& dnf upgrade-minimal -y --security \
&& dnf clean all
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell \
&& tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,41 +0,0 @@
FROM opensuse:42.3
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN zypper --non-interactive update --skip-interactive \
&& zypper --non-interactive install \
glibc-locale \
glibc-i18ndata \
tar \
libunwind \
libicu \
openssl \
git
# Install dotnet-runtime
ADD https://packages.microsoft.com/keys/microsoft.asc .
RUN rpmkeys --import microsoft.asc
ADD https://packages.microsoft.com/config/opensuse/42.2/prod.repo .
RUN mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
RUN zypper --non-interactive update --skip-interactive \
&& zypper --non-interactive install \
dotnet-runtime-2.1
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell
RUN tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,39 +0,0 @@
FROM ubuntu:xenial
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
apt-transport-https \
locales \
git \
&& apt-get clean
# Install dotnet-runtime
ADD https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb .
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
dotnet-runtime-2.1 \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell \
&& tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,31 +0,0 @@
FROM microsoft/dotnet:2.1.7-runtime-bionic
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
# Install PowerShell package
ADD $PACKAGELOCATION/$PACKAGENAME .
RUN mkdir -p /opt/microsoft/powershell \
&& tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Download and run tests
RUN $TESTDOWNLOADCOMMAND
RUN dotnet /opt/microsoft/powershell/pwsh.dll -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,39 +0,0 @@
FROM opensuse:42.3
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
ARG POWERSHELL_LINKFILE=/usr/bin/pwsh
# Install dependencies
RUN zypper --non-interactive update --skip-interactive \
&& zypper --non-interactive install \
glibc-locale \
glibc-i18ndata \
tar \
curl \
libunwind \
libicu \
openssl \
git
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME
# Create the target folder where powershell will be placed
RUN mkdir -p /opt/microsoft/powershell
# Expand powershell to the target folder
RUN tar zxf $PACKAGENAME -C /opt/microsoft/powershell
# Create the symbolic link that points to powershell
RUN ln -s /opt/microsoft/powershell/pwsh $POWERSHELL_LINKFILE
RUN $TESTDOWNLOADCOMMAND
RUN pwsh -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,29 +0,0 @@
FROM ubuntu:xenial
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
curl \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME
RUN dpkg -i $PACKAGENAME || :
RUN apt-get install -y -f --no-install-recommends
RUN $TESTDOWNLOADCOMMAND
RUN pwsh$PREVIEWSUFFIX -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,29 +0,0 @@
FROM ubuntu:bionic
ARG PACKAGENAME
ARG PACKAGELOCATION
ARG PREVIEWSUFFIX=
ARG TESTLIST=/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module
ARG TESTDOWNLOADCOMMAND="git clone --recursive https://github.com/PowerShell/PowerShell.git"
# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ca-certificates \
curl \
apt-transport-https \
locales \
git \
&& apt-get clean
# Setup the locale
ENV LANG en_US.UTF-8
ENV LC_ALL $LANG
RUN locale-gen $LANG && update-locale
RUN curl -L -o $PACKAGENAME $PACKAGELOCATION/$PACKAGENAME
RUN dpkg -i $PACKAGENAME || :
RUN apt-get install -y -f --no-install-recommends
RUN $TESTDOWNLOADCOMMAND
RUN pwsh$PREVIEWSUFFIX -c "Import-Module /PowerShell/build.psm1;\$dir='/usr/local/share/powershell/Modules';\$null=New-Item -Type Directory -Path \$dir -ErrorAction SilentlyContinue;Restore-PSPester -Destination \$dir;exit (Invoke-Pester $TESTLIST -PassThru).FailedCount"

View File

@ -1,370 +0,0 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
$script:forcePull = $true
# Get docker Engine OS
function Get-DockerEngineOs
{
docker info --format '{{ .OperatingSystem }}'
}
# Call Docker with appropriate result checksfunction Invoke-Docker
function Invoke-Docker
{
param(
[Parameter(Mandatory=$true)]
[string[]]
$Command,
[ValidateSet("error","warning",'ignore')]
$FailureAction = 'error',
[Parameter(Mandatory=$true)]
[string[]]
$Params,
[switch]
$PassThru,
[switch]
$SuppressHostOutput
)
$ErrorActionPreference = 'Continue'
# Log how we are running docker for troubleshooting issues
Write-Verbose "Running docker $command $params" -Verbose
if($SuppressHostOutput.IsPresent)
{
$result = docker $command $params 2>&1
}
else
{
&'docker' $command $params 2>&1 | Tee-Object -Variable result -ErrorAction SilentlyContinue | Out-String -Stream -ErrorAction SilentlyContinue | Write-Host -ErrorAction SilentlyContinue
}
$dockerExitCode = $LASTEXITCODE
if($PassThru.IsPresent)
{
Write-Verbose "passing through docker result$($result.length)..." -Verbose
return $result
}
elseif($dockerExitCode -ne 0 -and $FailureAction -eq 'error')
{
Write-Error "docker $command failed with: $result" -ErrorAction Stop
return $false
}
elseif($dockerExitCode -ne 0 -and $FailureAction -eq 'warning')
{
Write-Warning "docker $command failed with: $result"
return $false
}
elseif($dockerExitCode -ne 0)
{
return $false
}
return $true
}
# Return a list of Linux Container Test Cases
function Get-LinuxContainer
{
foreach($os in 'centos7','ubuntu16.04')
{
Write-Output @{
Name = $os
Path = "$PSScriptRoot/../release/$os"
}
}
}
# Return a list of Windows Container Test Cases
function Get-WindowsContainer
{
foreach($os in 'windowsservercore','nanoserver')
{
Write-Output @{
Name = $os
Path = "$PSScriptRoot/../release/$os"
}
}
}
$script:repoName = 'microsoft/powershell'
function Get-RepoName
{
return $script:repoName
}
function Set-RepoName
{
param([string]$RepoName)
$script:repoName = $RepoName
$script:forcePull = $false
}
function Test-SkipWindows
{
[bool] $canRunWindows = (Get-DockerEngineOs) -like 'Windows*'
return ($IsLinux -or $IsMacOS -or !$canRunWindows)
}
function Test-SkipLinux
{
$os = Get-DockerEngineOs
switch -wildcard ($os)
{
'*Linux*' {
return $false
}
'*Mac' {
return $false
}
# Docker for Windows means we are running the linux kernel
'Docker for Windows' {
return $false
}
'Windows*' {
return $true
}
default {
throw "Unknown docker os '$os'"
}
}
}
function Get-TestContext
{
param(
[ValidateSet('Linux','Windows','macOS')]
[string]$Type
)
$resultFileName = 'results.xml'
$logFileName = 'results.log'
$containerTestDrive = '/test'
# Return a windows context if the Context in Windows *AND*
# the current system is windows, otherwise Join-path will fail.
if($Type -eq 'Windows' -and $IsWindows)
{
$ContainerTestDrive = 'C:\test'
}
$resolvedTestDrive = (Resolve-Path "Testdrive:\").providerPath
return @{
ResolvedTestDrive = $resolvedTestDrive
ResolvedXmlPath = Join-Path $resolvedTestDrive -ChildPath $resultFileName
ResolvedLogPath = Join-Path $resolvedTestDrive -ChildPath $logFileName
ContainerTestDrive = $ContainerTestDrive
ContainerXmlPath = Join-Path $containerTestDrive -ChildPath $resultFileName
ContainerLogPath = Join-Path $containerTestDrive -ChildPath $logFileName
Type = $Type
ForcePull = $script:forcePull
}
}
function Get-ContainerPowerShellVersion
{
param(
[HashTable] $TestContext,
[string] $RepoName,
[string] $Name
)
$imageTag = "${script:repoName}:${Name}"
if($TestContext.ForcePull)
{
$null=Invoke-Docker -Command 'image', 'pull' -Params $imageTag -SuppressHostOutput
}
$runParams = @()
$localVolumeName = $testContext.resolvedTestDrive
$runParams += '--rm'
if($TestContext.Type -ne 'Windows' -and $IsWindows)
{
# use a container volume on windows because host volumes are not automatic
$volumeName = "test-volume-" + (Get-Random -Minimum 100 -Maximum 999)
# using alpine because it's tiny
$null=Invoke-Docker -Command create -Params '-v', '/test', '--name', $volumeName, 'alpine' -SuppressHostOutput
$runParams += '--volumes-from'
$runParams += $volumeName
}
else {
$runParams += '-v'
$runParams += "${localVolumeName}:$($testContext.containerTestDrive)"
}
$runParams += $imageTag
$runParams += 'pwsh'
$runParams += '-c'
$runParams += ('$PSVersionTable.PSVersion.ToString() | out-string | out-file -encoding ascii -FilePath '+$testContext.containerLogPath)
$null = Invoke-Docker -Command run -Params $runParams -SuppressHostOutput
if($TestContext.Type -ne 'Windows' -and $IsWindows)
{
$null = Invoke-Docker -Command cp -Params "${volumeName}:$($testContext.containerLogPath)", $TestContext.ResolvedLogPath
$null = Invoke-Docker -Command container, rm -Params $volumeName, '--force' -SuppressHostOutput
}
return (Get-Content -Encoding Ascii $testContext.resolvedLogPath)[0]
}
# Function defines a config mapping for testing Preview packages.
# The list of supported OS for each release can be found here:
# https://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/docs-conceptual/PowerShell-Core-Support.md#supported-platforms
function Get-DefaultPreviewConfigForPackageValidation
{
# format: <DockerfileFolderName>=<PartOfPackageFilename>
@{ 'centos7'='rhel.7';
'debian.9'='debian.9';
'fedora28'='rhel.7';
'opensuse42.3'='linux-x64.tar.gz';
'ubuntu16.04'='ubuntu.16.04';
'ubuntu18.04'='ubuntu.18.04';
'fxdependent-centos7'='linux-x64-fxdependent.tar.gz';
'fxdependent-debian.9'='linux-x64-fxdependent.tar.gz';
'fxdependent-fedora28'='linux-x64-fxdependent.tar.gz';
'fxdependent-opensuse42.3'='linux-x64-fxdependent.tar.gz';
'fxdependent-ubuntu16.04'='linux-x64-fxdependent.tar.gz';
'fxdependent-ubuntu18.04'='linux-x64-fxdependent.tar.gz';
'fxdependent-dotnetsdk-latest'='linux-x64-fxd-dotnetsdk.tar.gz'
}
}
# Function defines a config mapping for testing Stable packages.
# The list of supported OS for each release can be found here:
# https://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/docs-conceptual/PowerShell-Core-Support.md#supported-platforms
function Get-DefaultStableConfigForPackageValidation
{
# format: <DockerfileFolderName>=<PartOfPackageFilename>
@{ 'centos7'='rhel.7';
'debian.9'='debian.9';
'opensuse42.3'='linux-x64.tar.gz';
'ubuntu16.04'='ubuntu.16.04';
'fxdependent-centos7'='linux-x64-fxdependent.tar.gz';
'fxdependent-debian.9'='linux-x64-fxdependent.tar.gz';
'fxdependent-opensuse42.3'='linux-x64-fxdependent.tar.gz';
'fxdependent-ubuntu16.04'='linux-x64-fxdependent.tar.gz'
}
}
# Returns a list of files in a specified Azure container.
function Get-PackageNamesOnAzureBlob
{
param(
[string]
$ContainerUrl,
# $SAS (shared access signature) param should include beginning '?' and trailing '&'
[string]
$SAS
)
$response = Invoke-RestMethod -Method Get -Uri $($ContainerUrl + $SAS + 'restype=container&comp=list')
$xmlResponce = [xml]$response.Substring($response.IndexOf('<EnumerationResults')) # remove some bad chars in the beginning that break XML parsing
($xmlResponce.EnumerationResults.Blobs.Blob).Name
}
# This function is used for basic validation of PS packages during a release;
# During the process Docker files are filled out and executed with Docker build;
# During the build PS packages are downloaded onto Docker containers, installed and selected Pester tests from PowerShell Github repo are executed.
# This function must be run on a Docker host machine in 'Linux containers' mode, such as Windows 10 server with Hyper-V role installed.
function Test-PSPackage
{
param(
[string]
[Parameter(Mandatory=$true)]
$PSPackageLocation, # e.g. Azure container storage url
[string]
$SAS,# $SAS (shared access signature) param should include beginning '?' and trailing '&'
[Hashtable]
$Config, # hashtable that maps packages to dockerfiles; for example see Get-DefaultConfigForPackageValidation
[string]
$TestList = "/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module",
[string]
$TestDownloadCommand = "git clone --recursive https://github.com/PowerShell/PowerShell.git",
[switch]
$Preview = $false
)
$PSPackageLocation = $PSPackageLocation.TrimEnd('/','\') # code below assumes there is no trailing separator in PSPackageLocation url
$RootFolder = Join-Path $PSScriptRoot 'Templates'
$packageList = Get-PackageNamesOnAzureBlob -ContainerUrl $PSPackageLocation -SAS $SAS
if (!$Config)
{
if ($Preview)
{
$Config = Get-DefaultPreviewConfigForPackageValidation
}
else
{
$Config = Get-DefaultStableConfigForPackageValidation
}
}
# pre-process $Config: verify build directories and packages exist
$map = @{}
foreach($kp in $Config.GetEnumerator())
{
$buildDir = Join-Path $RootFolder $kp.Key
$packageName = $packageList | Where-Object {$_ -like $('*'+$kp.Value+'*')}
if (-not (Test-Path $buildDir))
{
Write-Error "Directory does Not exist - $buildDir; Check `$Config parameter and '$RootFolder' folder"
}
elseif (-not ($packageName))
{
Write-Error "Can not find package that matches filter *$($kp.Value)*; Check `$Config parameter and '$PSPackageLocation'"
}
else
{
$map.Add($buildDir, $packageName)
}
}
Write-Verbose "Using configuration:" -Verbose
Write-Verbose ($map | Format-List | Out-String) -Verbose
$results = @{}
$returnValue = $true
# run builds sequentially, but don't block for errors so that configs after failed one can run
foreach($kp in $map.GetEnumerator())
{
$dockerDirPath = $kp.Key
$packageFileName = $kp.Value
$buildArgs = @()
$buildArgs += "--build-arg","PACKAGENAME=$packageFileName"
$buildArgs += "--build-arg","PACKAGELOCATION=$PSPackageLocation"
if ($Preview)
{
$buildArgs += "--build-arg","PREVIEWSUFFIX=-preview"
}
$buildArgs += "--build-arg","TESTLIST=$TestList"
$buildArgs += "--build-arg","TESTDOWNLOADCOMMAND=$TestDownloadCommand"
$buildArgs += "--no-cache"
$buildArgs += $dockerDirPath
$dockerResult = Invoke-Docker -Command 'build' -Params $buildArgs -FailureAction warning
$confName = Split-Path -Leaf $dockerDirPath
$results.Add($confName, $dockerResult)
if (-not $dockerResult) {$returnValue = $false}
}
# in the end print results for all configurations
Write-Verbose "Package validation results:" -Verbose
$results
return $returnValue
}