mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 22:26:56 +00:00
Inital commit.
This commit is contained in:
124
images/win/scripts/ImageHelpers/ImageHelpers.psd1
Normal file
124
images/win/scripts/ImageHelpers/ImageHelpers.psd1
Normal file
@@ -0,0 +1,124 @@
|
||||
#
|
||||
# Module manifest for module 'ImageHelpers'
|
||||
#
|
||||
# Generated by: chrispat
|
||||
#
|
||||
# Generated on: 11/1/2017
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ImageHelpers.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.0.1'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'c9334909-16a1-48f1-a94a-c7baf1b961d9'
|
||||
|
||||
# Author of this module
|
||||
Author = 'chrispat'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Unknown'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2017 chrispat. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Helper functions for creating vsts images'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
||||
# Minimum version of the Windows PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# CLRVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
# ScriptsToProcess = @()
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# NestedModules = @()
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = '*'
|
||||
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = '*'
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||
AliasesToExport = '*'
|
||||
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
|
||||
# A URL to the license for this module.
|
||||
# LicenseUri = ''
|
||||
|
||||
# A URL to the main website for this project.
|
||||
# ProjectUri = ''
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
|
||||
} # End of PSData hashtable
|
||||
|
||||
} # End of PrivateData hashtable
|
||||
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
|
||||
}
|
||||
|
||||
|
||||
19
images/win/scripts/ImageHelpers/ImageHelpers.psm1
Normal file
19
images/win/scripts/ImageHelpers/ImageHelpers.psm1
Normal file
@@ -0,0 +1,19 @@
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
. $PSScriptRoot\PathHelpers.ps1
|
||||
. $PSScriptRoot\InstallHelpers.ps1
|
||||
. $PSScriptRoot\MarkdownHelpers.ps1
|
||||
|
||||
Export-ModuleMember -Function @(
|
||||
'Test-MachinePath'
|
||||
'Get-MachinePath'
|
||||
'Set-MachinePath'
|
||||
'Add-MachinePathItem'
|
||||
'Get-SystemVariable'
|
||||
'Set-SystemVariable'
|
||||
'Install-MSI'
|
||||
'Install-EXE'
|
||||
'Add-ContentToMarkdown'
|
||||
'Add-SoftwareDetailsToMarkdown'
|
||||
)
|
||||
83
images/win/scripts/ImageHelpers/InstallHelpers.ps1
Normal file
83
images/win/scripts/ImageHelpers/InstallHelpers.ps1
Normal file
@@ -0,0 +1,83 @@
|
||||
function Install-MSI
|
||||
{
|
||||
Param
|
||||
(
|
||||
[String]$MsiUrl,
|
||||
[String]$MsiName
|
||||
)
|
||||
|
||||
$exitCode = -1
|
||||
|
||||
try
|
||||
{
|
||||
Write-Host "Downloading $MsiName..."
|
||||
$FilePath = "${env:Temp}\$MsiName"
|
||||
|
||||
Invoke-WebRequest -Uri $MsiUrl -OutFile $FilePath
|
||||
|
||||
$Arguments = ('/i', $FilePath, '/QN', '/norestart' )
|
||||
|
||||
Write-Host "Starting Install $MsiName..."
|
||||
$process = Start-Process -FilePath msiexec.exe -ArgumentList $Arguments -Wait -PassThru
|
||||
$exitCode = $process.ExitCode
|
||||
|
||||
if ($exitCode -eq 0 -or $exitCode -eq 3010)
|
||||
{
|
||||
Write-Host -Object 'Installation successful'
|
||||
return $exitCode
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -Object "Non zero exit code returned by the installation process : $exitCode."
|
||||
exit $exitCode
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Host -Object "Failed to install the MSI $MsiName"
|
||||
Write-Host -Object $_.Exception.Message
|
||||
exit -1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Install-EXE
|
||||
{
|
||||
Param
|
||||
(
|
||||
[String]$Url,
|
||||
[String]$Name,
|
||||
[String[]]$ArgumentList
|
||||
)
|
||||
|
||||
$exitCode = -1
|
||||
|
||||
try
|
||||
{
|
||||
Write-Host "Downloading $Name..."
|
||||
$FilePath = "${env:Temp}\$Name"
|
||||
|
||||
Invoke-WebRequest -Uri $Url -OutFile $FilePath
|
||||
|
||||
Write-Host "Starting Install $Name..."
|
||||
$process = Start-Process -FilePath $FilePath -ArgumentList $ArgumentList -Wait -PassThru
|
||||
$exitCode = $process.ExitCode
|
||||
|
||||
if ($exitCode -eq 0 -or $exitCode -eq 3010)
|
||||
{
|
||||
Write-Host -Object 'Installation successful'
|
||||
return $exitCode
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -Object "Non zero exit code returned by the installation process : $exitCode."
|
||||
return $exitCode
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Host -Object "Failed to install the Executable $Name"
|
||||
Write-Host -Object $_.Exception.Message
|
||||
return -1
|
||||
}
|
||||
}
|
||||
25
images/win/scripts/ImageHelpers/MarkdownHelpers.ps1
Normal file
25
images/win/scripts/ImageHelpers/MarkdownHelpers.ps1
Normal file
@@ -0,0 +1,25 @@
|
||||
function Add-ContentToMarkdown {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
$Content = ""
|
||||
)
|
||||
|
||||
Add-Content 'C:\InstalledSoftware.md' $Content
|
||||
}
|
||||
|
||||
|
||||
function Add-SoftwareDetailsToMarkdown {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
$SoftwareName = "",
|
||||
$DescriptionMarkdown = ""
|
||||
)
|
||||
|
||||
$Content = @"
|
||||
|
||||
## $SoftwareName
|
||||
|
||||
$DescriptionMarkdown
|
||||
"@
|
||||
Add-ContentToMarkdown -Content $Content
|
||||
}
|
||||
68
images/win/scripts/ImageHelpers/PathHelpers.ps1
Normal file
68
images/win/scripts/ImageHelpers/PathHelpers.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
function Test-MachinePath{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$PathItem
|
||||
)
|
||||
|
||||
$currentPath = Get-MachinePath
|
||||
|
||||
$pathItems = $currentPath.Split(';')
|
||||
|
||||
if($pathItems.Contains($PathItem))
|
||||
{
|
||||
return $true
|
||||
}
|
||||
else
|
||||
{
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Set-MachinePath{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$NewPath
|
||||
)
|
||||
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name Path -Value $NewPath
|
||||
return $NewPath
|
||||
}
|
||||
|
||||
function Add-MachinePathItem
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$PathItem
|
||||
)
|
||||
|
||||
$currentPath = Get-MachinePath
|
||||
$newPath = $PathItem + ';' + $currentPath
|
||||
return Set-MachinePath -NewPath $newPath
|
||||
}
|
||||
|
||||
function Get-MachinePath{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
|
||||
)
|
||||
$currentPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
|
||||
return $currentPath
|
||||
}
|
||||
|
||||
function Get-SystemVariable{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$SystemVariable
|
||||
)
|
||||
$currentPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name $SystemVariable).$SystemVariable
|
||||
return $currentPath
|
||||
}
|
||||
|
||||
function Set-SystemVariable{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$SystemVariable,
|
||||
[string]$Value
|
||||
)
|
||||
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name $SystemVariable -Value $Value
|
||||
return $Value
|
||||
}
|
||||
13
images/win/scripts/ImageHelpers/test/ImageHelpers.Tests.ps1
Normal file
13
images/win/scripts/ImageHelpers/test/ImageHelpers.Tests.ps1
Normal file
@@ -0,0 +1,13 @@
|
||||
$ModuleManifestName = 'ImageHelpers.psd1'
|
||||
$ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName"
|
||||
|
||||
|
||||
|
||||
Describe 'Module Manifest Tests' {
|
||||
It 'Passes Test-ModuleManifest' {
|
||||
Test-ModuleManifest -Path $ModuleManifestPath | Should Not BeNullOrEmpty
|
||||
$? | Should Be $true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
images/win/scripts/ImageHelpers/test/PathHelpers.Tests.ps1
Normal file
34
images/win/scripts/ImageHelpers/test/PathHelpers.Tests.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
. $PSScriptRoot\..\PathHelpers.ps1
|
||||
|
||||
Describe 'Test-MachinePath Tests' {
|
||||
Mock Get-MachinePath {return "C:\foo;C:\bar"}
|
||||
It 'Path contains item' {
|
||||
Test-MachinePath -PathItem "C:\foo" | Should Be $true
|
||||
}
|
||||
It 'Path does not containe item' {
|
||||
Test-MachinePath -PathItem "C:\baz" | Should Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Set-MachinePath Tests' {
|
||||
Mock Get-MachinePath {return "C:\foo;C:\bar"}
|
||||
Mock Set-ItemProperty {return}
|
||||
It 'Set-MachinePath should return new path' {
|
||||
Set-MachinePath -NewPath "C:\baz" | Should Be "C:\baz"
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Add-MachinePathItem Tests"{
|
||||
Mock Get-MachinePath {return "C:\foo;C:\bar"}
|
||||
Mock Set-ItemProperty {return}
|
||||
It 'Add-MachinePathItem should return complete path' {
|
||||
Add-MachinePathItem -PathItem 'C:\baz' | Should Be 'C:\baz;C:\foo;C:\bar'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Set-SystemVariable Tests' {
|
||||
Mock Set-ItemProperty {return}
|
||||
It 'Set-SystemVariable should return new path' {
|
||||
Set-SystemVariable -SystemVariable "NewPathVar" -Value "C:\baz" | Should Be "C:\baz"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user