Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ name: release
# read caches of main but not of another tag, and GitHub drops a cache unused
# for 7 days, hence twice a week.
#
# After the release, the Windows build goes to winget: job `winget` submits
# the manifests of packaging/winget/ as a pull request to
# microsoft/winget-pkgs (a dry run only renders and checks them).
#
# Actions are pinned by commit SHA (the comment names the release);
# Dependabot (.github/dependabot.yml) proposes updates.

Expand All @@ -23,6 +27,7 @@ on:
- '.github/workflows/release.yml'
- 'install.ps1'
- 'install.sh'
- 'packaging/winget/**'
workflow_dispatch:
schedule:
- cron: '17 3 * * 1,4'
Expand Down Expand Up @@ -163,3 +168,71 @@ jobs:
run: |
gh release create "$GITHUB_REF_NAME" dist/* --verify-tag \
--title "devstack ${GITHUB_REF_NAME#v}" --generate-notes

winget:
# The manifests of packaging/winget/ with this release's version and the
# checksum of the archive just built, checked, and on a tag submitted to
# microsoft/winget-pkgs by wingetcreate (Microsoft, MIT; pinned by
# version and checksum). Its review takes days; `winget upgrade` offers
# the release once it is merged. The pull request comes from the fork of
# winget-pkgs of the account whose token is the secret WINGET_TOKEN (a
# classic token with `public_repo`); without the secret the job says so
# and ends.
needs: [build, publish]
if: ${{ !cancelled() && needs.build.result == 'success' && needs.publish.result != 'failure' }}
runs-on: windows-latest
env:
WINGETCREATE_VERSION: 1.12.13.0
WINGETCREATE_SHA256: 24042BD37915805615E6CF969AC57C6439124C3FE85823327F5F3FB24BD9FFEA
HAS_TOKEN: ${{ secrets.WINGET_TOKEN != '' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: x86_64-pc-windows-msvc
path: dist
- name: manifests
shell: pwsh
run: |
$version = if ($env:GITHUB_REF -like 'refs/tags/v*') { $env:GITHUB_REF_NAME.Substring(1) } else { (Select-String -Path Cargo.toml -Pattern '^version = "(.+)"' | Select-Object -First 1).Matches[0].Groups[1].Value }
$sha = (Get-FileHash dist/devstack-x86_64-pc-windows-msvc.zip -Algorithm SHA256).Hash
$date = (Get-Date).ToUniversalTime().ToString('yyyy-MM-dd')
$out = "winget/$version"
New-Item -ItemType Directory -Force $out | Out-Null
foreach ($f in Get-ChildItem packaging/winget -Filter *.yaml) {
$text = [IO.File]::ReadAllText($f.FullName) -replace '\{\{version\}\}', $version -replace '\{\{sha256\}\}', $sha -replace '\{\{date\}\}', $date
if ($text -match '\{\{') { throw "$($f.Name): a placeholder is left" }
[IO.File]::WriteAllText((Join-Path $out $f.Name), $text, [Text.UTF8Encoding]::new($false))
}
# The archive holds what the manifest names.
Expand-Archive dist/devstack-x86_64-pc-windows-msvc.zip -DestinationPath unpacked
if (-not (Test-Path unpacked/devstack.exe)) { throw 'devstack.exe is not at the root of the archive' }
"MANIFESTS=$out" >> $env:GITHUB_ENV
Get-Content "$out/nuetzliches.devstack.installer.yaml"
- name: validate
shell: pwsh
run: |
if (Get-Command winget -ErrorAction SilentlyContinue) {
"winget $(winget --version)"
# An older winget on the runner warns about a newer schema in the
# header comment, and exits non-zero for that too: only a failed
# validation fails the job.
$out = winget validate --manifest $env:MANIFESTS --disable-interactivity 2>&1 | Out-String
$out
if ($LASTEXITCODE -ne 0 -and $out -notmatch 'succeeded with warnings') { exit 1 }
exit 0 # the step would end with winget's exit code otherwise
} else {
"::notice::no winget on this runner; wingetcreate checks the manifests when it submits them"
}
- name: submit
if: startsWith(github.ref, 'refs/tags/v')
shell: pwsh
env:
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
run: |
if ($env:HAS_TOKEN -ne 'true') { "::warning::no WINGET_TOKEN: not submitted to winget"; exit 0 }
Invoke-WebRequest "https://github.com/microsoft/winget-create/releases/download/v$env:WINGETCREATE_VERSION/wingetcreate.exe" -OutFile wingetcreate.exe
$hash = (Get-FileHash wingetcreate.exe -Algorithm SHA256).Hash
if ($hash -ne $env:WINGETCREATE_SHA256) { throw "wingetcreate.exe: checksum $hash, expected $env:WINGETCREATE_SHA256" }
./wingetcreate.exe submit --no-open --prtitle "New version: nuetzliches.devstack version $($env:GITHUB_REF_NAME.Substring(1))" $env:MANIFESTS
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ and listed with their assets on the

### Added

- **winget**: `winget install nuetzliches.devstack` (once winget's catalogue
has the release). Each release submits its manifests
(`packaging/winget/`) to `microsoft/winget-pkgs`; the release workflow
needs the secret `WINGET_TOKEN` for it. `devstack update` (and the
dashboard's update) on a devstack winget installed runs `winget upgrade`,
moving the running binary out of winget's way first, since winget cannot
replace a file that runs; `devstack self uninstall` leaves that binary to
`winget uninstall`.
- **Desktop notifications** ([ADR-0045](docs/adr/0045-the-hub-notifies-the-desktop.md), #156):
the hub follows every running stack and each of its started lanes (on a
node too) and tells the desktop when a build failed, a candidate is held
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ irm https://github.com/nuetzliches/devstack/releases/latest/download/install.ps1
curl -fsSL https://github.com/nuetzliches/devstack/releases/latest/download/install.sh | sh
```

On Windows, `winget install nuetzliches.devstack` installs the same build
(releases after 0.15.0, once winget's catalogue has them, usually a few days
after the release); `devstack update` then updates it through winget, and
the first `devstack up` registers the hub as the installer would.

The scripts and `devstack update` check the download against the release's
`SHA256SUMS`: that proves the archive is the one the release lists (not
damaged or swapped on the way), not who built it, since both come from the
Expand Down
6 changes: 6 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ A pool is a group of machines that trust each other to a stated degree
--signer-workflow nuetzliches/devstack/.github/workflows/release.yml`) and
stop if it fails, showing gh's reason; you can run the same command
yourself.
- The winget package `nuetzliches.devstack` names the release's archive on
GitHub and its SHA-256, taken by the release workflow from the archive it
built and published; winget checks the download against it. Its manifests
(`packaging/winget/`) go through the review of `microsoft/winget-pkgs`
before winget offers a release. A devstack winget installed is updated
through winget, never replaced behind its back.
- `devstack update`, and a server node an admin updates
([ADR-0039](docs/adr/0039-an-admin-can-update-a-server-node.md)), check
only `SHA256SUMS`: the trust is GitHub's TLS and control of this
Expand Down
13 changes: 13 additions & 0 deletions crates/devstack/src/selfcmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub fn uninstall(yes: bool, with_coordinator: bool) -> Result<()> {

let exe = std::env::current_exe()?;
let ours = install_dir().is_some_and(|d| exe.parent() == Some(d.as_path()));
let winget = crate::update::is_winget_install(&exe);
println!("devstack self uninstall removes:");
println!(" - the dashboard hub, its start at logon and the devstack:// link");
println!(" - {} (token, list of stacks, hub log)", root.display());
Expand All @@ -162,6 +163,12 @@ pub fn uninstall(yes: bool, with_coordinator: bool) -> Result<()> {
}
if ours {
println!(" - {} and its PATH entry", exe.display());
} else if winget {
println!(
" (not {}: winget installed it, `winget uninstall {}` removes it)",
exe.display(),
crate::update::WINGET_ID
);
} else {
println!(
" (not {}: it is not where the installer puts devstack)",
Expand Down Expand Up @@ -209,6 +216,12 @@ pub fn uninstall(yes: bool, with_coordinator: bool) -> Result<()> {
exe.parent().unwrap().display()
);
}
if winget {
println!(
"The binary stays: `winget uninstall {}` removes it.",
crate::update::WINGET_ID
);
}
Ok(())
}

Expand Down
122 changes: 115 additions & 7 deletions crates/devstack/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//! shell environment: Windows PowerShell 5.1 started from PowerShell 7 finds
//! the wrong modules and has no `Get-FileHash` (#12).
//!
//! A devstack winget installed is updated by winget (`winget_upgrade`), so
//! its record of the version stays true.
//!
//! Running stacks keep their daemon (and its version) until they restart; the
//! dashboard offers that ("Restart stack"), the CLI says it.

Expand Down Expand Up @@ -66,13 +69,17 @@ pub fn run(check_only: bool, version: Option<&str>) -> Result<()> {
);
}
println!("installing devstack {target} ...");
// Where the installers put devstack, or the running copy if it lives
// elsewhere.
let into = crate::selfcmd::install_dir()
.map(|d| d.join(EXE))
.filter(|p| p.is_file())
.unwrap_or_else(|| exe.clone());
let installed = install(&target, &into)?;
let installed = if is_winget_install(&exe) {
winget_upgrade(&exe, version.map(|_| target.as_str()))?
} else {
// Where the installers put devstack, or the running copy if it lives
// elsewhere.
let into = crate::selfcmd::install_dir()
.map(|d| d.join(EXE))
.filter(|p| p.is_file())
.unwrap_or_else(|| exe.clone());
install(&target, &into)?
};

// The hub runs the old binary: stop it, start the new one.
let _ = crate::hubcmd::stop();
Expand Down Expand Up @@ -261,6 +268,83 @@ fn is_cargo_install(exe: &Path) -> bool {
&& parts.next().is_some_and(|c| c.as_os_str() == ".cargo")
}

/// The package winget installs devstack as (`packaging/winget/`).
pub(crate) const WINGET_ID: &str = "nuetzliches.devstack";

/// winget keeps a portable package in `...\WinGet\Packages\<id>_<source>\`
/// and puts a link to it in `...\WinGet\Links\` (per user under
/// `%LOCALAPPDATA%\Microsoft`, for the machine under `%ProgramFiles%`).
/// Replacing that binary behind winget's back leaves winget with the old
/// version on record.
pub(crate) fn is_winget_install(exe: &Path) -> bool {
let path = exe
.to_string_lossy()
.replace('/', "\\")
.to_ascii_lowercase();
path.contains(r"\winget\packages\") || path.contains(r"\winget\links\")
}

/// Update a devstack winget installed, through winget, so winget keeps the
/// version on record. winget cannot replace a binary that runs (the hub,
/// every stack's daemon): `remove_all: Access is denied`, measured with
/// winget 1.29. So the running file moves out of winget's directory first,
/// as `replace` does for the installers' copy (a running executable can be
/// moved on its volume, not overwritten), and back again when winget did
/// not put a new one there. Returns the path of the new binary.
fn winget_upgrade(exe: &Path, version: Option<&str>) -> Result<PathBuf> {
// The file itself, not winget's link to it.
let real = plain(std::fs::canonicalize(exe)?);
let aside_dir = devstack_daemon::token::token_path()
.parent()
.expect("token path has a parent")
.join("replaced");
std::fs::create_dir_all(&aside_dir)?;
for e in std::fs::read_dir(&aside_dir)?.flatten() {
let _ = std::fs::remove_file(e.path()); // still running: next time
}
let stamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_nanos());
let aside = aside_dir.join(format!("devstack-{stamp}.exe"));
if let Err(e) = std::fs::rename(&real, &aside) {
bail!(
"cannot move the running {} out of winget's way ({e}); stop the hub (`devstack hub stop`) \
and every stack (`devstack down`), then run `winget upgrade {WINGET_ID}`",
real.display()
);
}
let mut cmd = std::process::Command::new("winget");
cmd.args(["upgrade", "--id", WINGET_ID, "--exact", "--silent"])
.args(["--accept-package-agreements", "--accept-source-agreements"])
.arg("--disable-interactivity");
if let Some(v) = version {
cmd.args(["--version", v]);
}
let ran = cmd.status();
if ran.as_ref().is_ok_and(|s| s.success()) && real.is_file() {
return Ok(real);
}
if !real.exists() {
let _ = std::fs::rename(&aside, &real);
}
match ran {
Err(e) => bail!("cannot run winget ({e}); devstack is unchanged"),
Ok(_) => bail!(
"winget did not upgrade devstack (see above); it is unchanged. A release reaches winget's \
catalogue a few days after GitHub: `winget upgrade {WINGET_ID}` later picks it up"
),
}
}

/// `\\?\C:\...` (what `canonicalize` gives on Windows) as `C:\...`, which
/// every program understands.
fn plain(p: PathBuf) -> PathBuf {
match p.to_str().and_then(|s| s.strip_prefix(r"\\?\")) {
Some(rest) if !rest.starts_with("UNC\\") => PathBuf::from(rest),
_ => p,
}
}

/// Write `binary` to `path` and make sure it is on disk before it is used.
fn write_synced(path: &Path, binary: &[u8]) -> std::io::Result<()> {
use std::io::Write;
Expand Down Expand Up @@ -375,6 +459,30 @@ mod tests {
assert!(!is_cargo_install(Path::new("/home/u/.local/bin/devstack")));
}

#[test]
fn a_winget_install_is_recognised() {
for winget in [
r"C:\Users\u\AppData\Local\Microsoft\WinGet\Packages\nuetzliches.devstack_Microsoft.Winget.Source_8wekyb3d8bbwe\devstack.exe",
r"C:\Users\u\AppData\Local\Microsoft\WinGet\Links\devstack.exe",
r"C:\Program Files\WinGet\Packages\nuetzliches.devstack_Microsoft.Winget.Source_8wekyb3d8bbwe\devstack.exe",
] {
assert!(is_winget_install(Path::new(winget)), "{winget}");
}
for not in [
r"C:\Users\u\AppData\Local\Programs\devstack\devstack.exe",
r"C:\src\winget-packages\devstack.exe",
"/home/u/.local/bin/devstack",
] {
assert!(!is_winget_install(Path::new(not)), "{not}");
}
assert_eq!(
plain(PathBuf::from(r"\\?\C:\Users\u\devstack.exe")),
PathBuf::from(r"C:\Users\u\devstack.exe")
);
let unc = PathBuf::from(r"\\?\UNC\host\share\devstack.exe");
assert_eq!(plain(unc.clone()), unc);
}

#[test]
fn a_replaced_running_binary_is_found_at_its_path() {
let gone = PathBuf::from("/usr/local/bin/devstack (deleted)");
Expand Down
20 changes: 20 additions & 0 deletions packaging/winget/nuetzliches.devstack.installer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.12.0.schema.json
# Template: the release workflow fills in {{version}}, {{date}} and {{sha256}}
# (from the release's SHA256SUMS) and submits it (release.yml, job winget).

PackageIdentifier: nuetzliches.devstack
PackageVersion: {{version}}
InstallerType: zip
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: devstack.exe
PortableCommandAlias: devstack
Commands:
- devstack
ReleaseDate: {{date}}
Installers:
- Architecture: x64
InstallerUrl: https://github.com/nuetzliches/devstack/releases/download/v{{version}}/devstack-x86_64-pc-windows-msvc.zip
InstallerSha256: {{sha256}}
ManifestType: installer
ManifestVersion: 1.12.0
39 changes: 39 additions & 0 deletions packaging/winget/nuetzliches.devstack.locale.en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.12.0.schema.json
# Template: the release workflow fills in {{version}} and submits it (release.yml, job winget).

PackageIdentifier: nuetzliches.devstack
PackageVersion: {{version}}
PackageLocale: en-US
Publisher: nuetzliches
PublisherUrl: https://github.com/nuetzliches
PublisherSupportUrl: https://github.com/nuetzliches/devstack/issues
PackageName: devstack
PackageUrl: https://github.com/nuetzliches/devstack
License: MIT OR Apache-2.0
LicenseUrl: https://github.com/nuetzliches/devstack/blob/main/LICENSE-MIT
ShortDescription: Local development orchestrator for a whole stack, its worktrees and its containers
Description: |-
devstack runs a repository's whole stack on a developer machine: native
services, their Compose infrastructure and every git worktree beside it,
each from a build that compiled and passed its health check, so the running
stack never breaks on a broken save. One CLI, one dashboard in the browser
and one MCP server for coding agents; lanes can run on a team's server.
Moniker: devstack
Tags:
- cli
- compose
- developer-tools
- docker
- git-worktree
- mcp
- orchestrator
InstallationNotes: |-
`devstack doctor` checks the machine; `devstack init` drafts a devstack.toml
in a repository, `devstack up` starts it. `devstack update` updates through
winget.
ReleaseNotesUrl: https://github.com/nuetzliches/devstack/releases/tag/v{{version}}
Documentations:
- DocumentLabel: Stack file reference
DocumentUrl: https://github.com/nuetzliches/devstack/blob/main/docs/stack-file.md
ManifestType: defaultLocale
ManifestVersion: 1.12.0
8 changes: 8 additions & 0 deletions packaging/winget/nuetzliches.devstack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.12.0.schema.json
# Template: the release workflow fills in {{version}} and submits it (release.yml, job winget).

PackageIdentifier: nuetzliches.devstack
PackageVersion: {{version}}
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.12.0
1 change: 1 addition & 0 deletions skills/devstack/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install it yourself.
```powershell
# Windows
irm https://github.com/nuetzliches/devstack/releases/latest/download/install.ps1 | iex
# or, once winget has the release: winget install nuetzliches.devstack
```

```bash
Expand Down