Files
PiepmatzandBahex 9883c113af Update CI artifact uploading (#19106)
<!--
Thanks for contributing to Nushell!

Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md

This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->

## Description
<!--
Explain what this PR does and why.

This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant

Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."

Write as much or as little as needed for reviewers to understand your
changes.
-->
This PR changes how the CI uploads its artifacts to further testing and
for download via the toolkit. In fact this PR is a complete rewrite of
our `ci.yml` to be hopefully more straightforward.

I also fixed the `toolkit run pr` command on windows. And the binaries
built by ci include in their `version` command a `build_pr` field that
references the pr that caused this binary to build.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->
n/a

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2026-10-04 22:01:04 +02:00

76 lines
2.6 KiB
Nu

export use api.nu *
use unzip.nu
# these are the currently provided platforms in our ci
const platforms = ["linux-x86_64", "macos-aarch64", "windows-x86_64"]
const this_platform = $"($nu.os-info.name)-($nu.os-info.arch)"
# Download a Nushell binary from a pull request CI artifact.
@category "toolkit"
@search-terms download pr artifact binary ci gh
@example "Download the binary from PR #1234" { toolkit download pr 1234 }
@example "Download for a specific platform" { toolkit download pr 1234 --platform macos-aarch64 }
export def "download pr" [
# The PR number to download the Nushell binary from
number: int
# Use specific commit from branch
--commit: string
# OS and architecture to download for (defaults to the current platform)
--platform: string@$platforms = $this_platform
# For internal use only
--head: oneof<>
]: nothing -> binary {
let span = (metadata $head).span
let number = { item: $number, span: (metadata $number).span }
let artifacts = get-artifacts $number $platform $span --commit=$commit | first
let filename = if $platform starts-with "windows-" { "nu.exe" } else { "nu" }
^gh api $artifacts.archive_download_url | unzip $filename $span
}
# Run Nushell by downloading a CI artifact from a pull request.
@category "toolkit"
@search-terms run pr artifact binary ci gh try
@example "Run the binary from PR #1234" { toolkit run pr 1234 }
@example "Run a specific commit and pass arguments" { toolkit run pr 1234 --commit abcdef -- --version }
export def --wrapped "run pr" [
# The PR number to download the Nushell binary from
number: int
# Use specific commit from branch
--commit: string
# Arguments to pass to Nushell
...$rest
# For internal use only
--head: oneof<>
]: nothing -> nothing {
let span = (metadata $head).span
let number = { item: $number, span: (metadata $number).span }
let dir = $nu.temp-dir | path join "nushell-run-pr"
mkdir $dir
let platform = $"($nu.os-info.name)-($nu.os-info.arch)"
let artifact = get-artifacts $number $platform $span --commit=$commit | first
let workflow_id = $artifact.workflow_run.id
let extension = if $nu.os-info.name == "windows" { ".exe" } else { "" }
let filename = $"nu($extension)"
let binfile = $dir | path join $"nu-($number.item)-($workflow_id)-($platform)($extension)"
if ($binfile | path exists) {
print $"Using previously downloaded binary from workflow run ($workflow_id)"
} else {
print $"Downloading binary from workflow run ($workflow_id)..."
^gh api $artifact.archive_download_url
| unzip $filename $span
| save -p $binfile
}
if $nu.os-info.family == "unix" {
chmod +x $binfile
}
^$binfile ...$rest
}