Skip to content

Conversation

@132ikl
Copy link
Member

@132ikl 132ikl commented Sep 10, 2025

This PR uploads the compiled Nushell binary as an artifact during the std-lib-and-python-virtualenv test. This makes it possible for reviewers to download the existing compiled binary from the CI rather than manually compiling it. A zip file containing the nushell binary is uploaded per platform, with this naming format: nu-<PR number or branch name>-platform.zip

I put the retention policy to 14 days. I'm not sure how much this will impact our storage usage (cc @sholderbach) (I don't think I have permissions to see that?). I think ideally we would only keep the latest artifact per PR, but there isn't really any way to do that out of the box. If we need to implement due to storage space that then I can look into it.

As a bonus, here's a little script to run the latest artifact from a PR (if you'd like to try it, change nushell/nushell to 132ikl/nushell and do run-pr 2:

def run-pr [number: int] {
  let platform = "ubuntu-22.04" # change as needed
  let url = (
    gh api /repos/nushell/nushell/actions/artifacts
    | from json
    | get artifacts
    | where name == $"nu-($number)-($platform)"
    | first 
    | get archive_download_url
  )
  let tmp = (mktemp -t -d)
  let zip = $tmp | path join artifact.zip
  gh api $url | save -p $zip
  unzip -d $tmp $zip 
  ^($tmp | path join nu)
}

Release notes summary - What our users need to know

N/A

@132ikl 132ikl requested a review from sholderbach September 10, 2025 23:08
@github-actions github-actions bot added the A:ci Related to one or more of the CI jobs label Sep 10, 2025
@sholderbach
Copy link
Member

That is clever and could be such an improvement for reviewing the functionality of things!

How will this keying scheme work when pushing a new commit causing the CI to rerun?

Seems like they are immutable: https://github.com/actions/upload-artifact#breaking-changes

@132ikl
Copy link
Member Author

132ikl commented Sep 10, 2025

How will this keying scheme work when pushing a new commit causing the CI to rerun?

the artifact namespace is unique per CI run, so the filename only needs to disambiguate between multiple artifact uploads within the same run (like how we have multiple jobs per platform within a single run)

Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with landing this 🚀 let's test it in practice. (still need to check your snippet, especially with multiple artifacts per PR)

@132ikl
Copy link
Member Author

132ikl commented Sep 11, 2025

yea that was a quick thing, im planning on polishing it a bit (and maybe adding it to toolkit.nu?)

@132ikl
Copy link
Member Author

132ikl commented Sep 11, 2025

i don't imagine anyone will object to this so i'll land it

@132ikl 132ikl merged commit 0716d90 into nushell:main Sep 11, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.108.0 milestone Sep 11, 2025
@fdncred
Copy link
Contributor

fdncred commented Sep 11, 2025

nice! it would be good to have the script in the toolkit.nu in the root of the repo.

132ikl added a commit that referenced this pull request Oct 7, 2025
This PR adds the `toolkit run pr` and `toolkit download pr` commands to
`toolkit`. This is a more fleshed out version of the snippet shared in
#16633, with robust error handling and cross-platform unzip support.
When using `toolkit run pr`, the script will also check if the most
recent binary for that PR has already been downloaded, and if so it will
run that instead.

I tried to make the error reporting as good as a built-in command to see
how difficult that would be, and with use of the `--head: oneof<>`
trick, it turned out pretty good. With access to the call span, the
workflow is very similar to when writing a built-in command. I also used
a `Spanned`-like record, which helped as well.

```nushell
toolkit run pr 16740
# => Error: nu::shell::error
# =>
# =>   × Command not found
# =>    ╭─[entry #4:1:26]
# =>  1 │ overlay use -pr toolkit; toolkit run pr 16740
# =>    ·                          ───────┬──────
# =>    ·                                 ╰── requires `gh`
# =>    ╰────
# =>   help: Please install the `gh` commandline tool
```

<details>
<summary>More error reporting notes</summary>
In an earlier version of the script, `run pr` called `download pr`
directly. I ended up changing the way this worked so that `run pr` could
use the workflow_id. Here's a couple snippets I thought were neat from
this older version.

&nbsp;
**Passing span via `--head`:**
```nushell
def download [--head: oneof<>] {
  let span = $head | default (metadata $head).span
  error make {msg: "a", label: {text: here, span: $span}}
}

def run [--head: oneof<>] { 
  let span = (metadata $head).span
  download --head=$span
}

download
# => Error: nu:🐚:error
# => 
# =>   × a
# =>    ╭─[entry #6:1:1]
# =>  1 │ download
# =>    · ────┬───
# =>    ·     ╰── here
# =>    ╰────

run
# => Error: nu:🐚:error
# => 
# =>   × a
# =>    ╭─[entry #7:1:1]
# =>  1 │ run
# =>    · ─┬─
# =>    ·  ╰── here
# =>    ╰────
```

**Using "spanned" number as CLI parameter and as internal caller
parameter**

```nushell
def download [number: oneof<int, record<item: int, span: record>>] {
  let number = match $number {
    {item: $_, span: $_} => $number,
    $val => {item: $number, span: (metadata $number).span}
  }

  error make {msg: "a", label: {text: here, span: $number.span}}
}

def run [number: int] {
  let number = {item: $number, span: (metadata $number).span}
  download $number
}

download 123
# => Error: nu:🐚:error
# => 
# =>   × a
# =>    ╭─[entry #9:1:10]
# =>  1 │ download 123
# =>    ·          ─┬─
# =>    ·           ╰── here
# =>    ╰────

run 123
# => Error: nu:🐚:error
# => 
# =>   × a
# =>    ╭─[entry #10:1:5]
# =>  1 │ run 123
# =>    ·     ─┬─
# =>    ·      ╰── here
# =>    ╰────
```

</details>

## Release notes summary - What our users need to know
The toolkit in the Nushell repository can now download and run PRs by
downloading artifacts from CI runs. It can be run like this:
```nushell
use toolkit
toolkit run pr <number>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:ci Related to one or more of the CI jobs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants