Skip to content

Commit d614b74

Browse files
authored
Merge pull request #1240 from Gijsreyn/nightly-build
Nightly build artifact script
2 parents cf01ba4 + 4ef77b1 commit d614b74

File tree

3 files changed

+418
-0
lines changed

3 files changed

+418
-0
lines changed

docs/installing-nightly.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Installing the "Nightly" build of DSC CLI
2+
3+
> [!NOTE]
4+
> Nightly builds contain the latest development features but may have bugs or breaking changes.
5+
> Only install if you want to test unreleased functionality. If you encounter issues, please
6+
> [open an issue](https://github.com/PowerShell/DSC/issues/new).
7+
8+
## Using a script
9+
10+
> [!NOTE]
11+
> This script requires the [GitHub CLI](https://cli.github.com/) to have already been installed.
12+
13+
### DSC CLI
14+
15+
This will install the latest nightly DSC CLI binary to the following location depending on your
16+
platform:
17+
18+
- **Windows**: `%LOCALAPPDATA%\dsc\dsc.exe`
19+
- **Linux/macOS**: `~/.dsc/bin/dsc`
20+
21+
1. Retrieve the appropriate script. You can use the PowerShell script for Windows and the Bash script for Linux and macOS.
22+
23+
- Bash (Linux and macOS):
24+
25+
```sh
26+
curl -o https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh
27+
```
28+
29+
- PowerShell (Windows):
30+
31+
```powershell
32+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1 -OutFile install_cli_nightly.ps1
33+
```
34+
35+
1. Review the script before invoking it.
36+
1. Invoke the script to install `dsc`:
37+
38+
- Bash (Linux and macOS):
39+
40+
```sh
41+
./install_cli_nightly.sh
42+
```
43+
44+
- PowerShell (Windows):
45+
46+
```powershell
47+
./install_cli_nightly.ps1
48+
```
49+
50+
1. Add the installation directory to your `PATH` environment variable.
51+
52+
## Manual
53+
54+
We don't currently publish nightly releases, but you can get the latest builds by viewing the most
55+
recent Action workflows for the `main` branch.
56+
57+
The easiest way to get these artifacts is through the GitHub site. The following link directs you
58+
to the latest successful Action workflows for merges to the `main` branch:
59+
60+
<https://github.com/PowerShell/DSC/actions?query=workflow%3ARust+is%3Asuccess+branch%3Amain+event%3Apush>
61+
62+
Select the first link in the list to show the related artifacts. At the bottom of the page,
63+
download the artifact by selecting the artifact for your platform:
64+
65+
- `windows-bin` for Windows
66+
- `linux-bin` for Linux
67+
- `macos-bin` for macOS
68+
69+
Extract the archive using the following steps:
70+
71+
- The artifact will be downloaded as `<platform>-bin.zip`. You can invoke the following commands to
72+
extract the contents into a folder called `dsc` in the current directory:
73+
74+
- Bash (Linux, macOS)
75+
76+
```sh
77+
# Be sure to set this to the appropriate platform: 'linux' or 'macos'
78+
platform="linux"
79+
artifact="$platform-bin.zip"
80+
# requires `unzip`, install if needed to expand the zip file
81+
unzip $artifact
82+
# Expand the tar file
83+
tar -xvf bin.tar
84+
# Move the subfolder containing the binaries and manifests
85+
mv ./bin/debug dsc
86+
```
87+
88+
- PowerShell (Linux, macOS, Windows):
89+
90+
```powershell
91+
# Be sure to set this to the appropriate platform: 'linux', 'macos', or 'windows'
92+
$platform = 'linux'
93+
$artifact = "$platform-bin.zip"
94+
# Expand the zip file
95+
Expand-Archive -Path $artifact -DestinationPath .
96+
# Expand the tar file
97+
tar -xvf bin.tar
98+
# Move the subfolder containing the binaries and manifests
99+
Move-Item -Path ./bin/debug -Destination dsc
100+
```
101+
102+
- Optionally, you can clean up the downloaded archive and intermediary files and folders:
103+
104+
- Bash (Linux, macOS)
105+
106+
```sh
107+
rm -rf ./bin ./bin.tar ./linux-bin.zip
108+
```
109+
110+
- PowerShell (Linux, macOS, Windows)
111+
112+
```powershell
113+
Remove-Item -Path ./$artifact, ./bin.tar, ./bin -Recurse -Force
114+
```
115+
116+
- Finally, make sure to add the folder containing the extracted binaries and resource manifests to
117+
your `PATH` environmental variable
118+
119+
## Advanced script options
120+
121+
### CLI installation options
122+
123+
- Install to a custom directory:
124+
125+
- Bash (Linux, macOS):
126+
127+
```bash
128+
install_cli_nightly.sh --install-path /usr/local/bin
129+
```
130+
131+
- PowerShell (Windows):
132+
133+
```powershell
134+
install_cli_nightly.ps1 -InstallPath C:\tools\dsc
135+
```
136+
137+
- Install from a forking repository:
138+
139+
- Bash (Linux, macOS):
140+
141+
```bash
142+
install_cli_nightly.sh --repo myusername/DSC
143+
```
144+
145+
- PowerShell (Windows):
146+
147+
```powershell
148+
install_cli_nightly.ps1 -Repo myusername/DSC"
149+
```
150+
151+
- Install from a branch other than `main`:
152+
153+
- Bash (Linux, macOS):
154+
155+
```bash
156+
install_cli_nightly.sh --branch feature-branch
157+
```
158+
159+
- PowerShell (Windows):
160+
161+
```powershell
162+
install_cli_nightly.ps1 -Branch feature-branch"
163+
```
164+
165+
- Install from a specific GitHub Action run:
166+
167+
- Bash (Linux, macOS):
168+
169+
```bash
170+
install_cli_nightly.sh --run-id 6146657618
171+
```
172+
173+
- PowerShell (Windows):
174+
175+
```powershell
176+
install_cli_nightly.ps1 -RunId 6146657618"
177+
```
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
<#
4+
.SYNOPSIS
5+
Install the latest build of DSC from a GitHub Actions run
6+
.DESCRIPTION
7+
This script installs a build of DSC from the artifact generated by a GitHub Actions run. The
8+
artifact is retrieved as a `.zip` file containing a `.tar` archive with the required files.
9+
The script retrieves the artifacts, extracts the contents, and then installs them to the `dsc`
10+
folder in `LOCALAPPDATA`.
11+
You can override the installation directory with the `-InstallPath` parameter.
12+
By default, the script installs the artifact from the latest successful build on the `main`
13+
branch in the `PowerShell/DSC` repository. You can select a different branch with the `-Branch`
14+
parameter, a different repository with the `-Repo` parameter, and a specific run with the
15+
`-RunId` parameter.
16+
By default, the script removes the downloaded artifact archive and intermediary files and
17+
folders. Use the `-NoClean` parameter to skip this cleanup step if needed.
18+
This script requires the `gh` CLI and `tar` executable. If either tool isn't installed and
19+
available, the script throws an error.
20+
.PARAMETER InstallPath
21+
Defines the folder to install DSC to. Defaults to the `dsc` folder in `LOCALAPPDATA`. Define
22+
this value as the full path to an alternate location. The script will create the directory
23+
path if it doesn't already exist.
24+
.PARAMETER Branch
25+
Defines which branch to retrieve the build artifact from. Defaults to `main`.
26+
.PARAMETER Repo
27+
Defines the repository to retrieve the build artifact from. Defaults to `PowerShell/DSC`.
28+
Define this value with the user or organization followed by a forward slash and then the
29+
repository name, like `SomeUserName/DSC`.
30+
.PARAMETER RunId
31+
Defines a specific GitHub Action run to retrieve the build artifact from. When this parameter
32+
isn't specified, the script retrieves the build artifact from the latest successful build
33+
agains the specified branch and repository.
34+
.PARAMETER NoClean
35+
By default, the script deletes the downloaded artifact and intermediary files and folders after
36+
installing DSC to the specified path. Use this parameter to prevent the script from removing
37+
these files and folders if needed.
38+
#>
39+
[cmdletbinding()]
40+
param(
41+
[string]
42+
$InstallPath = [System.IO.Path]::combine($env:LOCALAPPDATA, "dsc"),
43+
44+
[string]
45+
$Branch = 'main',
46+
47+
[ValidatePattern('^\w+\/\w+$')]
48+
[string]
49+
$Repo = 'PowerShell/DSC',
50+
51+
[string]
52+
$RunId,
53+
54+
[switch]
55+
$NoClean
56+
)
57+
begin {
58+
[string[]]$missing = @()
59+
if (-not (Get-Command 'gh' -ErrorAction SilentlyContinue)) {
60+
$missing += 'gh'
61+
}
62+
if (-not (Get-Command 'tar' -ErrorAction SilentlyContinue)) {
63+
$missing += 'tar'
64+
}
65+
if ($missing.Count -gt 0) {
66+
throw (@(
67+
"This script requires the 'gh' CLI and 'tar' executable."
68+
'Please install the missing tools before invoking the script again:'
69+
"'$($missing -join "', '")'"
70+
) -join ' ')
71+
}
72+
if ([string]::IsNullOrEmpty($RunId)) {
73+
$latestRunParameters = @(
74+
'-R', $Repo
75+
'--branch', $Branch
76+
'--workflow', 'rust'
77+
'--status', 'success'
78+
'-L', 1
79+
'--json', 'databaseId'
80+
'-q', '.[0].databaseId'
81+
)
82+
$RunId = & gh run list @latestRunParameters
83+
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrEmpty($RunId)) {
84+
throw "Unable to find a successful build to install from"
85+
}
86+
}
87+
$tmpDir = [System.IO.Path]::combine(
88+
[System.IO.Path]::GetTempPath(),
89+
[System.IO.Path]::GetRandomFileName()
90+
)
91+
$installationFiles = Join-Path -Path $tmpDir -ChildPath 'bin' -AdditionalChildPath 'debug'
92+
$dscExe = Join-Path $InstallPath "dsc.exe"
93+
}
94+
process {
95+
$ErrorActionPreference = 'Stop'
96+
#region Download the artifact
97+
$downloadArtifactParams = @(
98+
'-R', $Repo
99+
$RunId
100+
'-n', "$platform-bin"
101+
"--dir", $tmpDir
102+
)
103+
gh run download @downloadArtifactParams
104+
if ($LASTEXITCODE -ne 0) {
105+
throw "Unable to download artifact"
106+
}
107+
#endregion Download the artifact
108+
#region Expand the tar file
109+
$tar = Get-ChildItem -Path $tmpDir | Select-Object -First 1
110+
if ($null -eq $tar) {
111+
throw "Failed to find downloaded artifact"
112+
}
113+
tar -xf $tar.FullName -C $tmpDir
114+
if ($LASTEXITCODE -ne 0) {
115+
throw "Unable to extract the tar file from the artifact"
116+
}
117+
#endregion Expand the tar file
118+
#region Move extracted files to the install directory
119+
# Create the install directory if it doesn't exist
120+
if (-not (Test-Path -Path $InstallPath -PathType Container)) {
121+
$null = New-Item -ItemType Directory -Force -Path $InstallPath
122+
}
123+
Move-Item -Path "$installationFiles/*" -Destination $InstallPath -Force -ErrorAction Ignore
124+
#endregion Copy extracted files to the install directory
125+
#region Retrieve and display version information
126+
$versionStdout = & $dscExe --version; if(!$?) { throw }
127+
$version = $versionStdout -replace 'dsc ', ''
128+
Write-Information "Installed DSC CLI $version from https://github.com/$Repo/actions/runs/$RunId to $InstallPath"
129+
#endregion Retrieve and display version information
130+
Write-Information "Make sure to add $InstallPath to your PATH environment variable to use the 'dsc' command."
131+
}
132+
clean {
133+
if (-not $NoClean) {
134+
Remove-Item $tmpDir -Recurse
135+
}
136+
}

0 commit comments

Comments
 (0)