8000 Refactor macOS CI so that tests run in parallel by TravisEz13 · Pull Request #9056 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

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
2 changes: 1 addition & 1 deletion .vsts-ci/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:

- powershell: |
Import-Module ./tools/ci.psm1
Invoke-Bootstrap-Stage
Invoke-BootstrapStage
displayName: Bootstrap
condition: succeeded()

Expand Down
85 changes: 53 additions & 32 deletions .vsts-ci/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,64 @@ resources:
- repo: self
clean: true
jobs:
- job: macOS_CI
- template: templates/ci-build.yml
parameters:
pool: Hosted macOS
jobName: mac_build
displayName: macOS Build

pool:
name: Hosted macOS
- template: templates/nix-test.yml
parameters:
purpose: UnelevatedPesterTests
tagSet: CI
parentJobs:
- mac_build

timeoutInMinutes: 120
- template: templates/nix-test.yml
parameters:
purpose: ElevatedPesterTests
tagSet: CI
parentJobs:
- mac_build

steps:
- powershell: |
Get-ChildItem -Path env:
displayName: Capture environment
condition: succeededOrFailed()
- template: templates/nix-test.yml
parameters:
purpose: UnelevatedPesterTests
tagSet: Others
parentJobs:
- mac_build

- powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))"
displayName: Set Build Name for Non-PR
condition: ne(variables['Build.Reason'], 'PullRequest')
- template: templates/nix-test.yml
parameters:
purpose: ElevatedPesterTests
tagSet: Others
parentJobs:
- mac_build

- template: ../tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml
- job: verify_xunit
displayName: Verify xUnit Results
pool:
name: 'Hosted macOS'
dependsOn:
- mac_build
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download build artifacts'
inputs:
downloadType: specific
itemPattern: |
xunit/**/*
downloadPath: '$(System.ArtifactsDirectory)'

- powershell: |
Import-Module ./tools/ci.psm1
Invoke-Bootstrap-Stage
displayName: Bootstrap
condition: succeeded()
- pwsh: |
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
displayName: 'Capture artifacts directory'
continueOnError: true

- powershell: |
Import-Module ./tools/ci.psm1
$env:NugetKey = '$(NUGET_KEY)'
Invoke-LinuxTests
displayName: Build and Test
condition: succeeded()
- pwsh: |
Import-Module .\tools\ci.psm1
$xUnitTestResultsFile = "$(System.ArtifactsDirectory)\xunit\xUnitTestResults.xml"

# Uploads any packages as an artifact
- powershell: |
Get-ChildItem -Path ${env:BUILD_ARTIFACTSTAGINGDIRECTORY} -Include *.nupkg, *.pkg, *.tar.gz, TestPackage.zip -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object {
Write-Host "##vso[artifact.upload containerfolder=artifacts;artifactname=artifacts]$_"
}
displayName: Publish Artifacts
condition: succeededOrFailed()
continueOnError: true
Test-XUnitTestResults -TestResultsFile $xUnitTestResultsFile
displayName: Test
condition: succeeded()
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
parameters:
pool: 'Hosted VS2017'
jobName: 'win_build'
displayName: Windows Build

jobs:
- job: ${{ parameters.jobName }}
pool:
name: ${{ parameters.pool }}

displayName: Windows Build
displayName: ${{ parameters.displayName }}

steps:
- powershell: |
Expand All @@ -24,7 +25,7 @@ jobs:
- powershell: |
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Import-Module .\tools\ci.psm1
Invoke-CIInstall
Invoke-CIInstall -SkipUser
displayName: Bootstrap
condition: succeededOrFailed()

Expand Down
72 changes: 72 additions & 0 deletions .vsts-ci/templates/nix-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
parameters:
pool: 'Hosted macOS'
parentJobs: []
purpose: ''
tagSet: 'CI'
name: 'mac'

jobs:
- job: ${{ parameters.name }}_test_${{ parameters.purpose }}_${{ parameters.tagSet }}
dependsOn:
${{ parameters.parentJobs }}
pool:
name: ${{ parameters.pool }}

displayName: ${{ parameters.name }} Test - ${{ parameters.purpose }} - ${{ parameters.tagSet }}

steps:
- pwsh: |
Get-ChildItem -Path env:
displayName: Capture environment
condition: succeededOrFailed()

- task: DownloadBuildArtifacts@0
displayName: 'Download build artifacts'
inputs:
downloadType: specific
itemPattern: |
build/**/*
downloadPath: '$(System.ArtifactsDirectory)'

- pwsh: |
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
displayName: 'Capture artifacts directory'
continueOnError: true

- pwsh: |
Import-Module .\tools\ci.psm1
Invoke-CIInstall -SkipUser
displayName: Bootstrap
condition: succeededOrFailed()

- task: ExtractFiles@1
displayName: 'Extract build zip'
inputs:
archiveFilePatterns: '$(System.ArtifactsDirectory)/build/build.zip'
destinationFolder: '$(System.ArtifactsDirectory)/bins'

- bash: |
find "$(System.ArtifactsDirectory)/bins" -type d -exec chmod +rwx {} \;
find "$(System.ArtifactsDirectory)/bins" -type f -exec chmod +rw {} \;
displayName: 'Fix permissions'
continueOnError: true

- pwsh: |
Get-ChildItem "$(System.ArtifactsDirectory)\bins\*" -Recurse -ErrorAction SilentlyContinue
displayName: 'Capture extracted build zip'
continueOnError: true

- pwsh: |
Import-Module .\tools\ci.psm1
Restore-PSOptions -PSOptionsPath '$(System.ArtifactsDirectory)\build\psoptions.json'
$options = (Get-PSOptions)
$rootPath = '$(System.ArtifactsDirectory)\bins'
$originalRootPath = Split-Path -path $options.Output
$path = Join-Path -path $rootPath -ChildPath (split-path -leaf -path $originalRootPath)
$pwshPath = Join-Path -path $path -ChildPath 'pwsh'
chmod a+x $pwshPath
$options.Output = $pwshPath
Set-PSOptions $options
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}'
displayName: Test
condition: succeeded()
10 changes: 5 additions & 5 deletions .vsts-ci/templates/windows-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
displayName: Windows Test - ${{ parameters.purpose }} - ${{ parameters.tagSet }}

steps:
- powershell: |
- pwsh: |
Get-ChildItem -Path env:
displayName: Capture environment
condition: succeededOrFailed()
Expand All @@ -27,19 +27,19 @@ jobs:
build/**/*
downloadPath: '$(System.ArtifactsDirectory)'

- powershell: |
dir "$(System.ArtifactsDirectory)\*" -Recurse
- pwsh: |
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
displayName: 'Capture artifacts directory'
continueOnError: true

# must be run frow Windows PowerShell
- powershell: |
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Import-Module .\tools\ci.psm1
Invoke-CIInstall
displayName: Bootstrap
condition: succeededOrFailed()

- powershell: |
- pwsh: |
Import-Module .\tools\ci.psm1
Restore-PSOptions -PSOptionsPath '$(System.ArtifactsDirectory)\build\psoptions.json'
$options = (Get-PSOptions)
Expand Down
2 changes: 1 addition & 1 deletion .vsts-ci/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resources:
clean: true

jobs:
- template: templates/windows-build.yml
- template: templates/ci-build.yml

- template: templates/windows-test.yml
parameters:
Expand Down
3 changes: 0 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,6 @@ function Start-PSBootstrap {
# Install dependencies
# ignore exitcode, because they may be already installed
Start-NativeExecution { brew install $Deps } -IgnoreExitcode

# Install patched version of curl
Start-NativeExecution { brew install curl --with-openssl --with-gssapi } -IgnoreExitcode
} elseif ($Environment.IsAlpine) {
$Deps += 'libunwind', 'libcurl', 'bash', 'cmake', 'clang', 'build-base', 'git', 'curl'

Expand Down
77 changes: 77 additions & 0 deletions tools/WindowsCI.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

if($PSVersionTable.PSEdition -ne 'Desktop')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code that other that this imperative code to protect against loading in PowerShell core was just moved from CI.psm1

52EC
{
throw 'Must be run from Windows PowerShell'
}

function New-LocalUser
{
<#
.SYNOPSIS
Creates a local user with the specified username and password
.DESCRIPTION
.EXAMPLE
.PARAMETER
username Username of the user which will be created
.PARAMETER
password Password of the user which will be created
.OUTPUTS
.NOTES
#>
param(
[Parameter(Mandatory=$true)]
[string] $username,

[Parameter(Mandatory=$true)]
[string] $password

)
$LocalComputer = [ADSI] "WinNT://$env:computername";
$user = $LocalComputer.Create('user', $username);
$user.SetPassword($password) | out-null;
$user.SetInfo() | out-null;
}

<#
Converts SID to NT Account Name
#>
function ConvertTo-NtAccount
{
param(
[Parameter(Mandatory=$true)]
[string] $sid
)
(new-object System.Security.Principal.SecurityIdentifier($sid)).translate([System.Security.Principal.NTAccount]).Value
}

<#
Add a user to a local security group
Requires Windows PowerShell
#>
function Add-UserToGroup
{
param(
[Parameter(Mandatory=$true)]
[string] $username,

[Parameter(Mandatory=$true, ParameterSetName = "SID")]
[string] $groupSid,

[Parameter(Mandatory=$true, ParameterSetName = "Name")]
[string] $group
)

$userAD = [ADSI] "WinNT://$env:computername/${username},user"

if($PsCmdlet.ParameterSetName -eq "SID")
{
$ntAccount=ConvertTo-NtAccount $groupSid
$group =$ntAccount.Split("\\")[1]
}

$groupAD = [ADSI] "WinNT://$env:computername/${group},group"

$groupAD.Add($userAD.AdsPath);
}
Loading
0