GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DSC/sharedScripts/install_cli_nightly.ps1 at main · PowerShell/DSC

Expand file tree

/

install_cli_nightly.ps1

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
140 lines (135 loc) · 5.62 KB
/

install_cli_nightly.ps1

Copy path

File metadata and controls

140 lines (135 loc) · 5.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
<#
.SYNOPSIS
Install the latest build of DSC from a GitHub Actions run
.DESCRIPTION
This script installs a build of DSC from the artifact generated by a GitHub Actions run. The
artifact is retrieved as a `.zip` file containing a `.tar` archive with the required files.
The script retrieves the artifacts, extracts the contents, and then installs them to the `dsc`
folder in `LOCALAPPDATA`.
You can override the installation directory with the `-InstallPath` parameter.
By default, the script installs the artifact from the latest successful build on the `main`
branch in the `PowerShell/DSC` repository. You can select a different branch with the `-Branch`
parameter, a different repository with the `-Repo` parameter, and a specific run with the
`-RunId` parameter.
By default, the script removes the downloaded artifact archive and intermediary files and
folders. Use the `-NoClean` parameter to skip this cleanup step if needed.
This script requires the `gh` CLI and `tar` executable. If either tool isn't installed and
available, the script throws an error.
.PARAMETER InstallPath
Defines the folder to install DSC to. Defaults to the `dsc` folder in `LOCALAPPDATA`. Define
this value as the full path to an alternate location. The script will create the directory
path if it doesn't already exist.
.PARAMETER Branch
Defines which branch to retrieve the build artifact from. Defaults to `main`.
.PARAMETER Repo
Defines the repository to retrieve the build artifact from. Defaults to `PowerShell/DSC`.
Define this value with the user or organization followed by a forward slash and then the
repository name, like `SomeUserName/DSC`.
.PARAMETER RunId
Defines a specific GitHub Action run to retrieve the build artifact from. When this parameter
isn't specified, the script retrieves the build artifact from the latest successful build
agains the specified branch and repository.
.PARAMETER NoClean
By default, the script deletes the downloaded artifact and intermediary files and folders after
installing DSC to the specified path. Use this parameter to prevent the script from removing
these files and folders if needed.
#>
[cmdletbinding()]
param(
[string]
$InstallPath = [System.IO.Path]::combine($env:LOCALAPPDATA, "dsc"),
[string]
$Branch = 'main',
[ValidatePattern('^\w+\/\w+$')]
[string]
$Repo = 'PowerShell/DSC',
[string]
$RunId,
[switch]
$NoClean
)
begin {
if ($IsLinux -or $IsMacOS) {
throw "This script is only supported on Windows. Use 'install_cli_nightly.sh' on Linux or macOS systems."
}
[string[]]$missing = @()
if (-not (Get-Command 'gh' -ErrorAction SilentlyContinue)) {
$missing += 'gh'
}
if (-not (Get-Command 'tar' -ErrorAction SilentlyContinue)) {
$missing += 'tar'
}
if ($missing.Count -gt 0) {
throw (@(
"This script requires the 'gh' CLI and 'tar' executable."
'Please install the missing tools before invoking the script again:'
"'$($missing -join "', '")'"
) -join ' ')
}
if ([string]::IsNullOrEmpty($RunId)) {
$latestRunParameters = @(
'-R', $Repo
'--branch', $Branch
'--workflow', 'rust'
'--status', 'success'
'-L', 1
'--json', 'databaseId'
'-q', '.[0].databaseId'
)
$RunId = & gh run list @latestRunParameters
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrEmpty($RunId)) {
throw "Unable to find a successful build to install from"
}
}
$tmpDir = [System.IO.Path]::combine(
[System.IO.Path]::GetTempPath(),
[System.IO.Path]::GetRandomFileName()
)
$installationFiles = Join-Path -Path $tmpDir -ChildPath 'bin' -AdditionalChildPath 'debug'
$dscExe = Join-Path $InstallPath "dsc.exe"
}
process {
$ErrorActionPreference = 'Stop'
#region Download the artifact
$downloadArtifactParams = @(
'-R', $Repo
$RunId
'-n', "windows-bin"
"--dir", $tmpDir
)
gh run download @downloadArtifactParams
if ($LASTEXITCODE -ne 0) {
throw "Unable to download artifact"
}
#endregion Download the artifact
#region Expand the tar file
$tar = Get-ChildItem -Path $tmpDir | Select-Object -First 1
if ($null -eq $tar) {
throw "Failed to find downloaded artifact"
}
tar -xf $tar.FullName -C $tmpDir
if ($LASTEXITCODE -ne 0) {
throw "Unable to extract the tar file from the artifact"
}
#endregion Expand the tar file
#region Move extracted files to the install directory
# Create the install directory if it doesn't exist
if (-not (Test-Path -Path $InstallPath -PathType Container)) {
$null = New-Item -ItemType Directory -Force -Path $InstallPath
}
Move-Item -Path "$installationFiles/*" -Destination $InstallPath -Force -ErrorAction Ignore
#endregion Copy extracted files to the install directory
#region Retrieve and display version information
$versionStdout = & $dscExe --version; if(!$?) { throw }
$version = $versionStdout -replace 'dsc ', ''
Write-Information "Installed DSC CLI $version from https://github.com/$Repo/actions/runs/$RunId to $InstallPath"
#endregion Retrieve and display version information
Write-Information "Make sure to add $InstallPath to your PATH environment variable to use the 'dsc' command."
}
clean {
if (-not $NoClean) {
Remove-Item $tmpDir -Recurse
}
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.