Skip to content

Commit 2ee4651

Browse files
committed
First PS script
1 parent c31ec1c commit 2ee4651

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

docs/installing-nightly.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Installing the "Nightly" build of DSC CLI
2+
3+
> **Note**: Nightly builds contain the latest development features but may have bugs or breaking
4+
> changes. Only install if you want to test unreleased functionality. If you encounter issues,
5+
> please [open an issue](https://github.com/PowerShell/DSC/issues/new).
6+
7+
## Via script
8+
9+
> **Note**: This script requires the [GitHub CLI](https://cli.github.com/) to have already been
10+
> installed.
11+
12+
### DSC CLI
13+
14+
This will install the latest nightly DSC CLI binary:
15+
16+
- **Windows**: `%LOCALAPPDATA%\dsc\dsc.exe`
17+
- **Linux/macOS**: `~/.dsc/bin/dsc`
18+
19+
1. (macOS/Linux) Run the following:
20+
21+
```sh
22+
bash <(curl -Ls https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh)
23+
```
24+
25+
1. (Windows) Run the following in a PowerShell window:
26+
27+
```powershell
28+
iex "& { $(irm https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1) }"
29+
```
30+
31+
1. Add the installation directory to your PATH environment variable to use `dsc` from any location.
32+
33+
## Manual
34+
35+
We are not currently publishing "nightly" releases, but you can grab the latest bits by viewing
36+
the latest Action workflows for the `main` branch (or any other branch).
37+
38+
The easiest way to get these artifacts is through the GitHub site. Follow
39+
[this link](https://github.com/PowerShell/DSC/actions/workflows/rust.yml?query=branch%3Amain+is%3Asuccess)
40+
to view the latest successful Action workflows for the `main` branch. Select it to show the related
41+
artifacts.
42+
43+
On the details page, select the artifact for your platform:
44+
45+
- `windows-bin` for Windows
46+
- `linux-bin` for Linux
47+
- `macos-bin` for macOS
48+
49+
Extract the archive and place the `dsc` executable (or `dsc.exe` on Windows) in a directory in
50+
your PATH.
51+
52+
## Advanced Script Options
53+
54+
### DSC CLI
55+
56+
- macOS/Linux
57+
58+
```sh
59+
# install to a custom directory
60+
bash <(curl -Ls https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh) --install-path /usr/local/bin
61+
62+
# install from a fork repo
63+
bash <(curl -Ls https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh) --repo myusername/DSC
64+
65+
# install from a custom branch
66+
bash <(curl -Ls https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh) --branch feature-branch
67+
68+
# install from a specific github action run
69+
bash <(curl -Ls https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.sh) --run-id 6146657618
70+
```
71+
72+
- Windows
73+
74+
```powershell
75+
# install to a custom directory
76+
iex "& { $(irm https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1) } -InstallPath C:\tools\dsc"
77+
78+
# install from a fork repo
79+
iex "& { $(irm https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1) } -Repo myusername/DSC"
80+
81+
# install from a custom branch
82+
iex "& { $(irm https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1) } -Branch feature-branch"
83+
84+
# install from a specific github action run
85+
iex "& { $(irm https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/sharedScripts/install_cli_nightly.ps1) } -RunId 6146657618"
86+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[cmdletbinding()]
2+
param(
3+
[string]$RunId,
4+
[string]$Branch,
5+
[string]$Repo,
6+
[string]$InstallPath
7+
)
8+
9+
$ErrorActionPreference="Stop"
10+
11+
if ($null -eq (Get-Command "gh" -ErrorAction SilentlyContinue)) {
12+
throw "Please install the GitHub CLI: https://cli.github.com/"
13+
}
14+
15+
$platform = if ($IsWindows) { "windows" } elseif ($IsLinux) { "linux" } elseif ($IsMacOS) { "macos" } else { throw "Unsupported OS" }
16+
17+
# Fetch
18+
if (!$InstallPath) {
19+
# Default install paths by platform
20+
if ($IsWindows) {
21+
$InstallPath = [System.IO.Path]::combine($env:LOCALAPPDATA, "dsc")
22+
} else {
23+
$InstallPath = [System.IO.Path]::combine($HOME, ".dsc", "bin")
24+
}
25+
}
26+
if (!$Repo) {
27+
$Repo = "PowerShell/DSC"
28+
}
29+
if (!$Branch) {
30+
$Branch = "main"
31+
}
32+
if (!$RunId) {
33+
$RunId = & gh run list -R $Repo --branch $Branch --workflow rust --status success -L 1 --json databaseId -q ".[0].databaseId"; if(!$?) { throw }
34+
if (!$RunId) {
35+
throw "Failed to find a successful build to install from"
36+
}
37+
}
38+
39+
$tmpDir = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
40+
& gh run download -R $Repo $RunId -n "$platform-bin" --dir $tmpDir; if(!$?) { throw }
41+
42+
$tar = Get-ChildItem -Path $tmpDir | Select-Object -First 1
43+
if (!$tar) {
44+
throw "Failed to find downloaded artifact"
45+
}
46+
47+
if (-not (Get-Command "tar" -ErrorAction SilentlyContinue)) {
48+
throw "Please install 'tar' to extract the downloaded artifact."
49+
}
50+
51+
tar -xf $tar.FullName -C $tmpDir; if(!$?) { throw }
52+
53+
$installationFiles = Join-Path $tmpDir 'bin' 'debug'
54+
New-Item -ItemType Directory -Force -Path $InstallPath | Out-Null
55+
Move-Item -Path "$installationFiles/*" -Destination $InstallPath -Force -ErrorAction Ignore
56+
57+
$dscExe = if ($IsWindows) { Join-Path $InstallPath "dsc.exe" } else { Join-Path $InstallPath "dsc" }
58+
$versionStdout = & $dscExe --version; if(!$?) { throw }
59+
$version = $versionStdout -replace 'dsc ', ''
60+
Write-Host "Installed DSC CLI $version from https://github.com/$Repo/actions/runs/$RunId to $InstallPath"
61+
Write-Host "Make sure to add $InstallPath to your PATH environment variable to use the 'dsc' command."
62+
63+
# Cleanup
64+
Remove-Item $tmpDir -Recurse

0 commit comments

Comments
 (0)