@workerstack/clients 1.0.0-rc.24 → 1.0.0-rc.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/assets/installers/examples/github.config.ts +21 -0
- package/assets/installers/examples/goreleaser.config.ts +21 -0
- package/assets/installers/examples/raw.config.ts +17 -0
- package/assets/installers/templates/install.ps1 +426 -0
- package/assets/installers/templates/install.sh +412 -0
- package/bin/installgen.js +19 -0
- package/dist/cli.js +4 -0
- package/dist/emit/cli/install.d.ts +8 -5
- package/dist/emit/cli/install.js +14 -7
- package/dist/emit/cli/release.js +8 -7
- package/dist/gen/args.js +4 -0
- package/dist/installers/cli.d.ts +21 -0
- package/dist/installers/cli.js +170 -0
- package/dist/installers/commands/build.d.ts +15 -0
- package/dist/installers/commands/build.js +34 -0
- package/dist/installers/commands/check.d.ts +10 -0
- package/dist/installers/commands/check.js +161 -0
- package/dist/installers/commands/init.d.ts +9 -0
- package/dist/installers/commands/init.js +32 -0
- package/dist/installers/config/define-config.d.ts +100 -0
- package/dist/installers/config/define-config.js +10 -0
- package/dist/installers/config/hooks/bun.d.ts +21 -0
- package/dist/installers/config/hooks/bun.js +21 -0
- package/dist/installers/config/hooks/node.d.ts +9 -0
- package/dist/installers/config/hooks/node.js +16 -0
- package/dist/installers/config/load.d.ts +35 -0
- package/dist/installers/config/load.js +97 -0
- package/dist/installers/config/resolve.d.ts +4 -0
- package/dist/installers/config/resolve.js +281 -0
- package/dist/installers/config/types.d.ts +45 -0
- package/dist/installers/config/types.js +1 -0
- package/dist/installers/errors.d.ts +5 -0
- package/dist/installers/errors.js +5 -0
- package/dist/installers/index.d.ts +11 -0
- package/dist/installers/index.js +11 -0
- package/dist/installers/render/quote.d.ts +7 -0
- package/dist/installers/render/quote.js +34 -0
- package/dist/installers/render/render.d.ts +24 -0
- package/dist/installers/render/render.js +133 -0
- package/dist/installers/ui.d.ts +15 -0
- package/dist/installers/ui.js +14 -0
- package/dist/release/bootstrap.d.ts +61 -0
- package/dist/release/bootstrap.js +191 -0
- package/dist/release/bump-args.d.ts +17 -0
- package/dist/release/bump-args.js +35 -0
- package/dist/release/bump-command.d.ts +18 -0
- package/dist/release/bump-command.js +186 -0
- package/dist/release/bump.d.ts +33 -0
- package/dist/release/bump.js +72 -0
- package/dist/release/cli.d.ts +23 -0
- package/dist/release/cli.js +85 -0
- package/dist/release/codegen.d.ts +6 -0
- package/dist/release/codegen.js +25 -0
- package/dist/release/constants.d.ts +39 -0
- package/dist/release/constants.js +35 -0
- package/dist/release/context.d.ts +33 -0
- package/dist/release/context.js +31 -0
- package/dist/release/digest.d.ts +11 -0
- package/dist/release/digest.js +59 -0
- package/dist/release/git.d.ts +10 -0
- package/dist/release/git.js +64 -0
- package/dist/release/index.d.ts +7 -0
- package/dist/release/index.js +6 -0
- package/dist/release/load.d.ts +30 -0
- package/dist/release/load.js +78 -0
- package/dist/release/manifest.d.ts +15 -0
- package/dist/release/manifest.js +164 -0
- package/dist/release/oasdiff.d.ts +20 -0
- package/dist/release/oasdiff.js +36 -0
- package/dist/release/registries.d.ts +46 -0
- package/dist/release/registries.js +243 -0
- package/dist/release/release-state.d.ts +15 -0
- package/dist/release/release-state.js +21 -0
- package/dist/release/release-workflow.d.ts +5 -0
- package/dist/release/release-workflow.js +72 -0
- package/dist/release/repo-settings.d.ts +22 -0
- package/dist/release/repo-settings.js +53 -0
- package/dist/release/spec-gate.d.ts +28 -0
- package/dist/release/spec-gate.js +107 -0
- package/dist/release/sync-command.d.ts +31 -0
- package/dist/release/sync-command.js +122 -0
- package/dist/release/sync-tree.d.ts +30 -0
- package/dist/release/sync-tree.js +123 -0
- package/dist/release/sync.d.ts +46 -0
- package/dist/release/sync.js +172 -0
- package/dist/release/types.d.ts +149 -0
- package/dist/release/types.js +1 -0
- package/dist/release/version-files.d.ts +16 -0
- package/dist/release/version-files.js +74 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +8 -0
- package/package.json +19 -9
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ This page is the whole generator — every target, every flag, and what each cli
|
|
|
23
23
|
- [The Java SDK](#the-java-sdk)
|
|
24
24
|
- [Errors and the safe mirror](#errors-and-the-safe-mirror)
|
|
25
25
|
- [The command-line client](#the-command-line-client)
|
|
26
|
+
- [Install scripts](#install-scripts)
|
|
27
|
+
- [Release tooling](#release-tooling)
|
|
26
28
|
- [The MCP server](#the-mcp-server)
|
|
27
29
|
- [Configuring generation](#configuring-generation)
|
|
28
30
|
- [What a run writes](#what-a-run-writes)
|
|
@@ -489,6 +491,60 @@ variables are the `--cli-env-prefix` (or the API's name) upper-cased.
|
|
|
489
491
|
Full reference: [the generated CLI](https://github.com/workerstack/clients/blob/main/docs/cli.md) and
|
|
490
492
|
[releasing it](https://github.com/workerstack/clients/blob/main/docs/cli-release.md).
|
|
491
493
|
|
|
494
|
+
## Install scripts
|
|
495
|
+
|
|
496
|
+
The CLI's `install.sh` and `install.ps1` are written by installgen, which ships in this package as the `installgen`
|
|
497
|
+
bin and the `@workerstack/clients/installers` library (it was `@lovrozagar/installgen`). The generated release
|
|
498
|
+
workflow checks every release with the installgen of the clients release that generated the module:
|
|
499
|
+
|
|
500
|
+
```sh
|
|
501
|
+
npx --yes --package @workerstack/clients@<version> installgen check --default-version v1.2.3
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
installgen also writes installers for any prebuilt binary, outside a generated CLI:
|
|
505
|
+
|
|
506
|
+
```ts
|
|
507
|
+
import { defineConfig } from "@workerstack/clients/installers"
|
|
508
|
+
|
|
509
|
+
export default defineConfig({
|
|
510
|
+
name: "my-cli",
|
|
511
|
+
baseUrl: "https://dl.example.com/my-cli",
|
|
512
|
+
assetPath: ({ version, os, arch }) => `${version}/my-cli-${os}-${arch}.tar.gz`,
|
|
513
|
+
})
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
Full reference: [installgen](https://github.com/workerstack/clients/blob/main/src/installers/README.md).
|
|
517
|
+
|
|
518
|
+
## Release tooling
|
|
519
|
+
|
|
520
|
+
`honey-clients release` cuts versions for a product's public packages and mirrors each one to its own GitHub repo.
|
|
521
|
+
A product describes its packages once, in a `release.config.ts` typed by the `@workerstack/clients/release`
|
|
522
|
+
library; each package's dir sits beside the config, and the repo root is the config's git toplevel:
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
import { defineRelease } from "@workerstack/clients/release"
|
|
526
|
+
|
|
527
|
+
export default defineRelease({
|
|
528
|
+
project: "acme",
|
|
529
|
+
codegen: ["bun", "run", "codegen"],
|
|
530
|
+
homepage: "https://example.com",
|
|
531
|
+
spec: { committedPath: "openapi.json", deployedUrl: "https://api.example.com/openapi.json" },
|
|
532
|
+
packages: [
|
|
533
|
+
{ name: "sdk", repo: "acme/sdk", description: "Acme SDK", commitMessage: "chore: sync", topics: ["acme"] },
|
|
534
|
+
],
|
|
535
|
+
})
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
```sh
|
|
539
|
+
honey-clients release bump --config acme-release/release.config.ts [--major]
|
|
540
|
+
honey-clients release sync --config acme-release/release.config.ts [--only sdk] [--dry-run] [--validate-only]
|
|
541
|
+
honey-clients release bootstrap --config acme-release/release.config.ts (--all | --only sdk) [--force-bootstrap]
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
`bump` writes each changed package's version files, `CHANGELOG.md` and `.release-state.json` (an API change is a
|
|
545
|
+
minor, measured by oasdiff through Go on PATH); `sync` and `bootstrap` push with `GH_TOKEN`, committing as
|
|
546
|
+
`committer` (default `public-sync[bot]`).
|
|
547
|
+
|
|
492
548
|
## The MCP server
|
|
493
549
|
|
|
494
550
|
`--target mcp` writes a standalone Model Context Protocol server: one tool per operation marked for MCP, its
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from "@workerstack/clients/installers"
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* GitHub Releases. Assets live at releases/download/<tag>/; each release also uploads:
|
|
5
|
+
*
|
|
6
|
+
* version.txt "v1.2.3", read through the releases/latest/download/ redirect
|
|
7
|
+
* install.sh served from releases/latest/download/ too
|
|
8
|
+
* install.ps1
|
|
9
|
+
*/
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
name: "my-cli",
|
|
12
|
+
baseUrl: "https://github.com/acme/my-cli/releases",
|
|
13
|
+
assetPath: ({ tag, version, os, arch }) =>
|
|
14
|
+
`download/${tag}/my-cli_${version}_${os}_${arch}${os === "windows" ? ".zip" : ".tar.gz"}`,
|
|
15
|
+
checksumsPath: ({ tag, version }) => `download/${tag}/my-cli_${version}_checksums.txt`,
|
|
16
|
+
latestPath: "latest/download/version.txt",
|
|
17
|
+
scriptUrls: {
|
|
18
|
+
sh: "https://github.com/acme/my-cli/releases/latest/download/install.sh",
|
|
19
|
+
ps1: "https://github.com/acme/my-cli/releases/latest/download/install.ps1",
|
|
20
|
+
},
|
|
21
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig, type Arch, type Os } from "@workerstack/clients/installers"
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* GoReleaser's `goreleaser init` archive names, uploaded to your own host under the tag:
|
|
5
|
+
*
|
|
6
|
+
* v1.2.3/my-cli_Linux_x86_64.tar.gz
|
|
7
|
+
* v1.2.3/my-cli_Windows_arm64.zip
|
|
8
|
+
* v1.2.3/my-cli_1.2.3_checksums.txt
|
|
9
|
+
* latest "v1.2.3"
|
|
10
|
+
*/
|
|
11
|
+
const osName: Record<Os, string> = { linux: "Linux", darwin: "Darwin", windows: "Windows" }
|
|
12
|
+
const archName: Record<Arch, string> = { amd64: "x86_64", arm64: "arm64" }
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
name: "my-cli",
|
|
16
|
+
baseUrl: "https://dl.example.com/my-cli",
|
|
17
|
+
assetPath: ({ tag, os, arch }) =>
|
|
18
|
+
`${tag}/my-cli_${osName[os]}_${archName[arch]}${os === "windows" ? ".zip" : ".tar.gz"}`,
|
|
19
|
+
checksumsPath: ({ tag, version }) => `${tag}/my-cli_${version}_checksums.txt`,
|
|
20
|
+
message: "Run `my-cli --help` to get started.",
|
|
21
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from "@workerstack/clients/installers"
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Raw binaries on your own host:
|
|
5
|
+
*
|
|
6
|
+
* 1.2.3/my-cli-linux-amd64
|
|
7
|
+
* 1.2.3/my-cli-windows-amd64.exe
|
|
8
|
+
* 1.2.3/checksums.txt sha256sum output for every binary
|
|
9
|
+
* latest "1.2.3"
|
|
10
|
+
*/
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
name: "my-cli",
|
|
13
|
+
baseUrl: "https://dl.example.com/my-cli",
|
|
14
|
+
assetPath: ({ version, os, arch }) => `${version}/my-cli-${os}-${arch}${os === "windows" ? ".exe" : ""}`,
|
|
15
|
+
checksumsPath: ({ version }) => `${version}/checksums.txt`,
|
|
16
|
+
tagPrefix: "",
|
|
17
|
+
})
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
param([string]$Version)
|
|
2
|
+
# Generated by installgen (https://github.com/workerstack/clients). Regenerate it with `installgen build`.
|
|
3
|
+
#
|
|
4
|
+
# powershell -c "irm <url> | iex" the latest version
|
|
5
|
+
# iex "& {$(irm <url>)} -Version 1.2.3" a specific version
|
|
6
|
+
#
|
|
7
|
+
# Environment: @@ENV_PREFIX@@_VERSION, @@ENV_PREFIX@@_INSTALL_DIR, @@ENV_PREFIX@@_NO_MODIFY_PATH=1,
|
|
8
|
+
# @@ENV_PREFIX@@_INSTALL_VERIFY=require, NO_COLOR.
|
|
9
|
+
# Windows PowerShell 5.1 and PowerShell 7+. Failures throw and leave the session open: under `irm | iex`,
|
|
10
|
+
# ending the script any other way would close the user's window.
|
|
11
|
+
|
|
12
|
+
& {
|
|
13
|
+
$ErrorActionPreference = 'Stop'
|
|
14
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
15
|
+
if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') {
|
|
16
|
+
throw "this installer needs PowerShell FullLanguage mode; this session runs in $($ExecutionContext.SessionState.LanguageMode) mode"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
$name = @@NAME@@
|
|
20
|
+
$baseUrl = @@BASE_URL@@
|
|
21
|
+
$latestUrl = @@LATEST_URL@@
|
|
22
|
+
$defaultVersion = @@DEFAULT_VERSION@@
|
|
23
|
+
$tagPrefix = @@TAG_PREFIX@@
|
|
24
|
+
$modifyPath = @@MODIFY_PATH@@
|
|
25
|
+
$message = @@MESSAGE@@
|
|
26
|
+
$shUrl = @@SH_URL@@
|
|
27
|
+
$ps1Url = @@PS1_URL@@
|
|
28
|
+
$platforms = @@PLATFORMS@@
|
|
29
|
+
|
|
30
|
+
$installDir = $env:@@ENV_PREFIX@@_INSTALL_DIR
|
|
31
|
+
if ($installDir) {
|
|
32
|
+
$dirShown = $installDir
|
|
33
|
+
} else {
|
|
34
|
+
$installDir = @@INSTALL_DIR@@
|
|
35
|
+
$dirShown = @@INSTALL_DIR_DISPLAY@@
|
|
36
|
+
}
|
|
37
|
+
if ($env:@@ENV_PREFIX@@_NO_MODIFY_PATH) { $modifyPath = $false }
|
|
38
|
+
$requested = if ($Version) { $Version } else { $env:@@ENV_PREFIX@@_VERSION }
|
|
39
|
+
|
|
40
|
+
# UI: color only on a real console; check glyphs only where the terminal renders them
|
|
41
|
+
$tty = ($Host.Name -eq 'ConsoleHost') -and (-not [Console]::IsOutputRedirected)
|
|
42
|
+
$useColor = $tty -and (-not $env:NO_COLOR)
|
|
43
|
+
$unicode = [bool]($env:WT_SESSION -or $env:TERM_PROGRAM)
|
|
44
|
+
$okGlyph = if ($unicode) { [string][char]0x2713 } else { '+' }
|
|
45
|
+
$downGlyph = if ($unicode) { [string][char]0x2193 } else { 'v' }
|
|
46
|
+
|
|
47
|
+
function Write-Row([string]$Glyph, [string]$Tint, [string]$Label, [string]$Value) {
|
|
48
|
+
if ($useColor) { Write-Host -NoNewline -ForegroundColor $Tint $Glyph } else { Write-Host -NoNewline $Glyph }
|
|
49
|
+
Write-Host (' {0,-10} {1}' -f $Label, $Value)
|
|
50
|
+
}
|
|
51
|
+
function Write-Ok([string]$Label, [string]$Value) { Write-Row -Glyph $okGlyph -Tint 'Green' -Label $Label -Value $Value }
|
|
52
|
+
function Write-WarnRow([string]$Label, [string]$Value) { Write-Row -Glyph '!' -Tint 'Yellow' -Label $Label -Value $Value }
|
|
53
|
+
function Write-Warn([string]$Text) {
|
|
54
|
+
if ($useColor) { Write-Host -ForegroundColor Yellow "warning: $Text" } else { Write-Host "warning: $Text" }
|
|
55
|
+
}
|
|
56
|
+
function Fail([string]$Text) { throw "$name install failed: $Text" }
|
|
57
|
+
|
|
58
|
+
# installgen:begin Assert-HttpsKept
|
|
59
|
+
# .NET Framework (Windows PowerShell 5.1) follows an https to http redirect. Refuse one: over http a man in the
|
|
60
|
+
# middle could swap the binary and its checksum, which comes from the same host.
|
|
61
|
+
function Assert-HttpsKept([string]$Requested, [Uri]$Final) {
|
|
62
|
+
if ($Requested -match '^https://' -and $Final.Scheme -ne 'https') {
|
|
63
|
+
throw "refusing ${Requested}: redirected from https to $Final"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
# installgen:end Assert-HttpsKept
|
|
67
|
+
|
|
68
|
+
function Save-WithProgress([string]$Url, [string]$Path, [string]$Label) {
|
|
69
|
+
# a pty without a size reports 0 columns
|
|
70
|
+
$width = 80
|
|
71
|
+
try {
|
|
72
|
+
$columns = [Console]::WindowWidth
|
|
73
|
+
if ($columns -ge 20) { $width = $columns }
|
|
74
|
+
} catch {
|
|
75
|
+
Write-Verbose 'no console width; using 80 columns'
|
|
76
|
+
}
|
|
77
|
+
$request = [Net.HttpWebRequest]::Create($Url)
|
|
78
|
+
if ($request.Proxy) { $request.Proxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials }
|
|
79
|
+
$response = $request.GetResponse()
|
|
80
|
+
try {
|
|
81
|
+
Assert-HttpsKept -Requested $Url -Final $response.ResponseUri
|
|
82
|
+
$total = $response.ContentLength
|
|
83
|
+
$in = $response.GetResponseStream()
|
|
84
|
+
$out = [IO.File]::Create($Path)
|
|
85
|
+
try {
|
|
86
|
+
$buffer = New-Object byte[] 65536
|
|
87
|
+
$done = 0
|
|
88
|
+
$last = [DateTime]::MinValue
|
|
89
|
+
while ($true) {
|
|
90
|
+
$read = $in.Read($buffer, 0, $buffer.Length)
|
|
91
|
+
$now = [DateTime]::UtcNow
|
|
92
|
+
if ($read -gt 0) {
|
|
93
|
+
$out.Write($buffer, 0, $read)
|
|
94
|
+
$done += $read
|
|
95
|
+
}
|
|
96
|
+
if ($read -le 0 -or ($now - $last).TotalMilliseconds -ge 100) {
|
|
97
|
+
$last = $now
|
|
98
|
+
if ($total -gt 0) {
|
|
99
|
+
$bar = [Math]::Max(10, $width - $Label.Length - 12)
|
|
100
|
+
$filled = [int][Math]::Floor($bar * $done / $total)
|
|
101
|
+
$line = '{0} {1} [{2}{3}] {4,3}%' -f $downGlyph, $Label, ('#' * $filled), (' ' * ($bar - $filled)), [int](100 * $done / $total)
|
|
102
|
+
} else {
|
|
103
|
+
$line = '{0} {1} {2:N1} MB' -f $downGlyph, $Label, ($done / 1MB)
|
|
104
|
+
}
|
|
105
|
+
[Console]::Write("`r" + $line.PadRight($width - 1).Substring(0, $width - 1))
|
|
106
|
+
}
|
|
107
|
+
if ($read -le 0) { break }
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
$out.Dispose()
|
|
111
|
+
$in.Dispose()
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
$response.Close()
|
|
115
|
+
[Console]::Write("`r" + (' ' * ($width - 1)) + "`r")
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function Save-Url([string]$Url, [string]$Path, [string]$Label) {
|
|
120
|
+
if ($Label -and $tty -and $useColor) {
|
|
121
|
+
try {
|
|
122
|
+
Save-WithProgress -Url $Url -Path $Path -Label $Label
|
|
123
|
+
return
|
|
124
|
+
} catch {
|
|
125
|
+
Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
|
|
126
|
+
# a refused downgrade is final; anything else falls back to Invoke-WebRequest
|
|
127
|
+
if ($_.Exception.Message -like 'refusing *') { throw }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
$result = Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Path -PassThru
|
|
131
|
+
# the final URI: HttpWebResponse on 5.1, HttpResponseMessage on 7 (which refuses the downgrade itself)
|
|
132
|
+
$final = if ($result.BaseResponse.ResponseUri) { $result.BaseResponse.ResponseUri } else { $result.BaseResponse.RequestMessage.RequestUri }
|
|
133
|
+
try {
|
|
134
|
+
Assert-HttpsKept -Requested $Url -Final $final
|
|
135
|
+
} catch {
|
|
136
|
+
Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
|
|
137
|
+
throw
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
Write-Host "$name installer"
|
|
142
|
+
|
|
143
|
+
# Platform: the registry knows the real CPU, even from an emulated x64 PowerShell on ARM64
|
|
144
|
+
$onWindows = ($PSVersionTable.PSEdition -ne 'Core') -or $IsWindows
|
|
145
|
+
if ($onWindows) {
|
|
146
|
+
$cpu = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name PROCESSOR_ARCHITECTURE).PROCESSOR_ARCHITECTURE
|
|
147
|
+
} else {
|
|
148
|
+
# test seam: pwsh on Linux or macOS installs the Windows build into the home directory
|
|
149
|
+
$cpu = [string][System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
|
|
150
|
+
}
|
|
151
|
+
if ($cpu -match '^(AMD64|X64)$') {
|
|
152
|
+
$arch = 'amd64'
|
|
153
|
+
} elseif ($cpu -match '^ARM64$') {
|
|
154
|
+
$arch = 'arm64'
|
|
155
|
+
} else {
|
|
156
|
+
Fail "unsupported architecture: $cpu"
|
|
157
|
+
}
|
|
158
|
+
$platform = "windows/$arch"
|
|
159
|
+
if ($platforms -notcontains $platform) {
|
|
160
|
+
if ($arch -eq 'arm64' -and $platforms -contains 'windows/amd64') {
|
|
161
|
+
Write-Warn "no native ARM64 build of $name; installing the x64 build, which runs under emulation"
|
|
162
|
+
$platform = 'windows/amd64'
|
|
163
|
+
} else {
|
|
164
|
+
Fail "no $name build for $platform"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
Write-Ok 'Detected' $platform
|
|
168
|
+
|
|
169
|
+
# The platform's paths; run once without a version for the format and the checksums setting
|
|
170
|
+
$ver = ''
|
|
171
|
+
$tag = ''
|
|
172
|
+
$assetPath = ''
|
|
173
|
+
$format = ''
|
|
174
|
+
$checksumsPath = ''
|
|
175
|
+
$bundlePath = ''
|
|
176
|
+
$identity = ''
|
|
177
|
+
$issuer = ''
|
|
178
|
+
$binaryInArchive = ''
|
|
179
|
+
switch ($platform) {
|
|
180
|
+
@@PLATFORM_CASES@@
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# Signature: cosign checks the checksums file when it is on PATH; <PREFIX>_INSTALL_VERIFY=require refuses without it
|
|
184
|
+
$verify = $env:@@ENV_PREFIX@@_INSTALL_VERIFY
|
|
185
|
+
if ($verify -and $verify -cne 'require') { Fail "@@ENV_PREFIX@@_INSTALL_VERIFY ${verify}: want require, or unset" }
|
|
186
|
+
$cosign = $null
|
|
187
|
+
if ($bundlePath) { $cosign = Get-Command cosign -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 }
|
|
188
|
+
if ($verify) {
|
|
189
|
+
if (-not $bundlePath) { Fail '@@ENV_PREFIX@@_INSTALL_VERIFY=require: no signature is published for this release' }
|
|
190
|
+
if (-not $cosign) { Fail "@@ENV_PREFIX@@_INSTALL_VERIFY=require: cosign is not installed to verify the checksums' signature" }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
195
|
+
} catch {
|
|
196
|
+
Write-Verbose 'TLS 1.2 could not be enabled; using the defaults'
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("$name-install-" + [Guid]::NewGuid().ToString('N'))
|
|
200
|
+
New-Item -ItemType Directory -Path $tmp | Out-Null
|
|
201
|
+
try {
|
|
202
|
+
# Version: -Version, then <PREFIX>_VERSION, then the baked default, then the latest file
|
|
203
|
+
$raw = $requested
|
|
204
|
+
if (-not $raw) { $raw = $defaultVersion }
|
|
205
|
+
$fromLatest = ''
|
|
206
|
+
if ((-not $raw) -or $raw -eq 'latest') {
|
|
207
|
+
$latestFile = Join-Path $tmp 'latest'
|
|
208
|
+
try {
|
|
209
|
+
Save-Url -Url $latestUrl -Path $latestFile -Label ''
|
|
210
|
+
} catch {
|
|
211
|
+
Fail "could not resolve the latest version from ${latestUrl}: $($_.Exception.Message)"
|
|
212
|
+
}
|
|
213
|
+
$raw = [IO.File]::ReadAllText($latestFile)
|
|
214
|
+
$fromLatest = ' (latest)'
|
|
215
|
+
}
|
|
216
|
+
$ver = $raw -replace '\s', ''
|
|
217
|
+
if ($tagPrefix -and $ver.StartsWith($tagPrefix, [StringComparison]::Ordinal)) { $ver = $ver.Substring($tagPrefix.Length) }
|
|
218
|
+
if ($ver -cnotmatch '^[A-Za-z0-9._+-]+$') { Fail "invalid version: '$ver'" }
|
|
219
|
+
$tag = $tagPrefix + $ver
|
|
220
|
+
Write-Verbose "release tag ${tag}"
|
|
221
|
+
switch ($platform) {
|
|
222
|
+
@@PLATFORM_CASES@@
|
|
223
|
+
}
|
|
224
|
+
Write-Ok 'Version' "$ver$fromLatest"
|
|
225
|
+
|
|
226
|
+
# Download
|
|
227
|
+
$assetUrl = "$baseUrl/$assetPath"
|
|
228
|
+
$assetFile = $assetPath.Substring($assetPath.LastIndexOf('/') + 1)
|
|
229
|
+
$download = Join-Path $tmp $assetFile
|
|
230
|
+
try {
|
|
231
|
+
Save-Url -Url $assetUrl -Path $download -Label $assetFile
|
|
232
|
+
} catch {
|
|
233
|
+
Fail "download failed: $assetUrl ($($_.Exception.Message))"
|
|
234
|
+
}
|
|
235
|
+
Write-Ok 'Download' $assetFile
|
|
236
|
+
|
|
237
|
+
# Verify: `hash file`, `hash *file`, BSD `SHA256 (file) = hash`, or a file holding one bare hash
|
|
238
|
+
if ($checksumsPath) {
|
|
239
|
+
$checksumsUrl = "$baseUrl/$checksumsPath"
|
|
240
|
+
$sumsFile = Join-Path $tmp 'checksums'
|
|
241
|
+
try {
|
|
242
|
+
Save-Url -Url $checksumsUrl -Path $sumsFile -Label ''
|
|
243
|
+
} catch {
|
|
244
|
+
Fail "download failed: $checksumsUrl ($($_.Exception.Message))"
|
|
245
|
+
}
|
|
246
|
+
if ($cosign) {
|
|
247
|
+
$bundleUrl = "$baseUrl/$bundlePath"
|
|
248
|
+
$bundleFile = Join-Path $tmp 'bundle'
|
|
249
|
+
try {
|
|
250
|
+
Save-Url -Url $bundleUrl -Path $bundleFile -Label ''
|
|
251
|
+
} catch {
|
|
252
|
+
Fail "download failed: $bundleUrl ($($_.Exception.Message))"
|
|
253
|
+
}
|
|
254
|
+
# Windows PowerShell 5.1 turns a native command's stderr into an error record, which 'Stop' makes
|
|
255
|
+
# terminating even when redirected; 'Continue' in a child scope leaves $LASTEXITCODE as the only verdict
|
|
256
|
+
$null = & {
|
|
257
|
+
$ErrorActionPreference = 'Continue'
|
|
258
|
+
& $cosign.Source verify-blob --bundle $bundleFile --certificate-identity $identity --certificate-oidc-issuer $issuer $sumsFile 2>&1
|
|
259
|
+
}
|
|
260
|
+
if ($LASTEXITCODE -ne 0) {
|
|
261
|
+
Fail "$($checksumsPath.Substring($checksumsPath.LastIndexOf('/') + 1)): cosign could not verify it as signed by $identity"
|
|
262
|
+
}
|
|
263
|
+
Write-Ok 'Signed' 'cosign'
|
|
264
|
+
} elseif ($bundlePath) {
|
|
265
|
+
Write-WarnRow 'Signed' 'skipped: cosign not installed'
|
|
266
|
+
}
|
|
267
|
+
$lines = @([IO.File]::ReadAllLines($sumsFile) | Where-Object { $_.Trim() })
|
|
268
|
+
$expected = ''
|
|
269
|
+
foreach ($line in $lines) {
|
|
270
|
+
$fields = @($line.Trim() -split '\s+')
|
|
271
|
+
if ($fields.Count -ge 4 -and $fields[0] -ceq 'SHA256' -and $fields[1] -ceq "($assetFile)" -and $fields[2] -eq '=') {
|
|
272
|
+
$expected = $fields[3]
|
|
273
|
+
break
|
|
274
|
+
}
|
|
275
|
+
if ($fields.Count -ge 2 -and ($fields[1] -replace '^\*', '') -ceq $assetFile) {
|
|
276
|
+
$expected = $fields[0]
|
|
277
|
+
break
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (-not $expected -and $lines.Count -eq 1 -and @($lines[0].Trim() -split '\s+').Count -eq 1) {
|
|
281
|
+
$expected = $lines[0].Trim()
|
|
282
|
+
}
|
|
283
|
+
if (-not $expected) { Fail "no checksum for $assetFile in $checksumsUrl" }
|
|
284
|
+
$expected = $expected.ToLowerInvariant()
|
|
285
|
+
if ($expected -cnotmatch '^[0-9a-f]{64}$') { Fail "malformed checksum for $assetFile in $checksumsUrl" }
|
|
286
|
+
# hash in .NET: 5.1 defines its hash cmdlet in a script module, which a PSModulePath inherited from pwsh hides
|
|
287
|
+
$sha = [Security.Cryptography.SHA256]::Create()
|
|
288
|
+
$stream = [IO.File]::OpenRead($download)
|
|
289
|
+
try {
|
|
290
|
+
$actual = [BitConverter]::ToString($sha.ComputeHash($stream)).Replace('-', '').ToLowerInvariant()
|
|
291
|
+
} finally {
|
|
292
|
+
$stream.Dispose()
|
|
293
|
+
$sha.Dispose()
|
|
294
|
+
}
|
|
295
|
+
if ($actual -ne $expected) { Fail "checksum mismatch for ${assetFile}: expected $expected, got $actual" }
|
|
296
|
+
Write-Ok 'Verified' 'sha256'
|
|
297
|
+
} else {
|
|
298
|
+
Write-WarnRow 'Verified' 'skipped: no checksums published'
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# Extract: tar.gz and zip both through bsdtar, which Windows ships as System32\tar.exe
|
|
302
|
+
$exe = "$name.exe"
|
|
303
|
+
$extracted = Join-Path $tmp 'x'
|
|
304
|
+
if ($format -ne 'raw') {
|
|
305
|
+
New-Item -ItemType Directory -Path $extracted | Out-Null
|
|
306
|
+
$extractOk = $true
|
|
307
|
+
if ($onWindows) {
|
|
308
|
+
& (Join-Path $env:SystemRoot 'System32\tar.exe') -xf $download -C $extracted
|
|
309
|
+
$extractOk = $LASTEXITCODE -eq 0
|
|
310
|
+
} elseif ($format -eq 'zip') {
|
|
311
|
+
# test seam: GNU tar cannot read zip. Expand-Archive is a script module, so it reads the global
|
|
312
|
+
# preference, not this scope's.
|
|
313
|
+
$savedProgress = $global:ProgressPreference
|
|
314
|
+
$global:ProgressPreference = 'SilentlyContinue'
|
|
315
|
+
try {
|
|
316
|
+
Expand-Archive -LiteralPath $download -DestinationPath $extracted
|
|
317
|
+
} finally {
|
|
318
|
+
$global:ProgressPreference = $savedProgress
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
& tar -xzf $download -C $extracted
|
|
322
|
+
$extractOk = $LASTEXITCODE -eq 0
|
|
323
|
+
}
|
|
324
|
+
if (-not $extractOk) { Fail "could not extract $assetFile" }
|
|
325
|
+
}
|
|
326
|
+
if ($format -eq 'raw') {
|
|
327
|
+
$bin = $download
|
|
328
|
+
} elseif ($binaryInArchive) {
|
|
329
|
+
$bin = Join-Path $extracted $binaryInArchive
|
|
330
|
+
} else {
|
|
331
|
+
# exactly one match: a mispacked archive with two must not install whichever comes first
|
|
332
|
+
$hits = @(Get-ChildItem -LiteralPath $extracted -Recurse -File | Where-Object { $_.Name -eq $exe })
|
|
333
|
+
if ($hits.Count -gt 1) { Fail "$assetFile holds $($hits.Count) files named $exe; set binaryInArchive" }
|
|
334
|
+
$bin = if ($hits.Count -eq 1) { $hits[0].FullName } else { '' }
|
|
335
|
+
}
|
|
336
|
+
if ((-not $bin) -or -not (Test-Path -LiteralPath $bin -PathType Leaf)) { Fail "$exe not found in $assetFile" }
|
|
337
|
+
|
|
338
|
+
# Install. A running exe cannot be overwritten or deleted, but it can be renamed: move it aside first.
|
|
339
|
+
$found = Get-Command -CommandType Application -Name $exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
340
|
+
$target = Join-Path $installDir $exe
|
|
341
|
+
$verb = if (Test-Path -LiteralPath $target) { 'Updated' } else { 'Installed' }
|
|
342
|
+
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
|
|
343
|
+
if ($verb -eq 'Updated') {
|
|
344
|
+
$old = "$target.old"
|
|
345
|
+
if (Test-Path -LiteralPath $old) {
|
|
346
|
+
try { Remove-Item -LiteralPath $old -Force } catch { $old = "$target.old-$PID" }
|
|
347
|
+
}
|
|
348
|
+
Move-Item -LiteralPath $target -Destination $old -Force
|
|
349
|
+
try {
|
|
350
|
+
Copy-Item -LiteralPath $bin -Destination $target
|
|
351
|
+
} catch {
|
|
352
|
+
Move-Item -LiteralPath $old -Destination $target -Force
|
|
353
|
+
Fail "could not write ${target}: $($_.Exception.Message)"
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
Remove-Item -LiteralPath $old -Force
|
|
357
|
+
} catch {
|
|
358
|
+
Write-Verbose "$old is still in use; it goes on the next update"
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
try {
|
|
362
|
+
Copy-Item -LiteralPath $bin -Destination $target
|
|
363
|
+
} catch {
|
|
364
|
+
Fail "could not write ${target}: $($_.Exception.Message)"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
$targetShown = if ($dirShown -eq $installDir) { $target } else { "$dirShown\$exe" }
|
|
368
|
+
Write-Ok $verb $targetShown
|
|
369
|
+
} finally {
|
|
370
|
+
Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
# PATH: the user PATH in the registry, read unexpanded and written back as REG_EXPAND_SZ
|
|
374
|
+
$sep = [IO.Path]::PathSeparator
|
|
375
|
+
$trim = [char[]]@('\', '/')
|
|
376
|
+
$sameDir = { param($a, $b) $a.TrimEnd($trim) -eq $b.TrimEnd($trim) }
|
|
377
|
+
$onPath = @($env:PATH -split [regex]::Escape([string]$sep) | Where-Object { $_ -and (& $sameDir $_ $installDir) }).Count -gt 0
|
|
378
|
+
$pathChanged = $false
|
|
379
|
+
if ($onPath) {
|
|
380
|
+
Write-Ok 'PATH' 'already set'
|
|
381
|
+
} elseif (-not $modifyPath) {
|
|
382
|
+
Write-WarnRow 'PATH' "not changed; add $dirShown to PATH"
|
|
383
|
+
} elseif (-not $onWindows) {
|
|
384
|
+
Write-WarnRow 'PATH' 'not changed: the user PATH lives in the Windows registry'
|
|
385
|
+
} else {
|
|
386
|
+
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true)
|
|
387
|
+
try {
|
|
388
|
+
$userPath = [string]$key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
|
|
389
|
+
$entries = @($userPath -split ';' | Where-Object { $_ })
|
|
390
|
+
if (@($entries | Where-Object { & $sameDir $_ $installDir }).Count -eq 0) {
|
|
391
|
+
$key.SetValue('Path', ((@($installDir) + $entries) -join ';'), [Microsoft.Win32.RegistryValueKind]::ExpandString)
|
|
392
|
+
# a throwaway User variable set and cleared through .NET broadcasts WM_SETTINGCHANGE to Explorer
|
|
393
|
+
[Environment]::SetEnvironmentVariable('INSTALLGEN_REFRESH', '1', 'User')
|
|
394
|
+
[Environment]::SetEnvironmentVariable('INSTALLGEN_REFRESH', $null, 'User')
|
|
395
|
+
Write-Ok 'PATH' 'added to the user PATH'
|
|
396
|
+
} else {
|
|
397
|
+
Write-Ok 'PATH' 'already in the user PATH'
|
|
398
|
+
}
|
|
399
|
+
} finally {
|
|
400
|
+
$key.Close()
|
|
401
|
+
}
|
|
402
|
+
$env:PATH = "$installDir$sep$env:PATH"
|
|
403
|
+
$pathChanged = $true
|
|
404
|
+
}
|
|
405
|
+
if ($modifyPath -and -not $onPath -and $env:GITHUB_PATH) {
|
|
406
|
+
Add-Content -LiteralPath $env:GITHUB_PATH -Value $installDir
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
# Another copy shadows this one in new shells unless the user PATH now puts the install dir first. Windows
|
|
410
|
+
# puts the machine PATH before the user PATH, so a copy there still wins.
|
|
411
|
+
if ($found -and -not (& $sameDir $found.Path $target)) {
|
|
412
|
+
$foundDir = Split-Path -Parent $found.Path
|
|
413
|
+
$machine = @([string][Environment]::GetEnvironmentVariable('Path', 'Machine') -split ';' | Where-Object { $_ })
|
|
414
|
+
if ((-not $pathChanged) -or @($machine | Where-Object { & $sameDir $_ $foundDir }).Count -gt 0) {
|
|
415
|
+
Write-Warn "$($found.Path) comes first on PATH and shadows the new $name"
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
Write-Host ''
|
|
420
|
+
Write-Host "$name $ver $($verb.ToLowerInvariant())."
|
|
421
|
+
if ($message) { Write-Host $message }
|
|
422
|
+
if ($pathChanged) { Write-Host "Open a new terminal to use $name everywhere; this one is ready now." }
|
|
423
|
+
Write-Host "To uninstall: Remove-Item '$($targetShown -replace "'", "''")'"
|
|
424
|
+
Write-Host "To update: irm $ps1Url | iex"
|
|
425
|
+
if ((-not $onWindows) -and $shUrl) { Write-Host "On Linux and macOS the native installer is: curl -fsSL $shUrl | sh" }
|
|
426
|
+
}
|