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

125 lines
3.4 KiB
Nu

use std-rfc/iter only
use std/util null_device
# Get the workflow of the most recent commit with artifacts.
@category "toolkit"
@search-terms workflow run ci artifact commit check
@example "Get the workflow run ID for the most recent commit" { toolkit get-workflow-run ["abc123def456"] {start: 0, end: 10} }
export def get-workflow-run [commits: list<string>, span: record]: nothing -> int {
mut latest = true
for commit in ($commits | reverse) {
let checks = (
^gh api $"/repos/nushell/nushell/commits/($commit)/check-runs"
| from json
| get check_runs
# Native root jobs upload artifacts; the WASM root job only builds.
| where name ends-with ' / root'
| where name != 'WASM / root'
)
if ($checks | is-empty) {
$latest = false
continue
}
if not $latest {
let short = $commit | str substring 0..6
print $"(ansi yellow)Warning: using most recent commit with artifacts ($short), which is not the most recent on the PR(ansi reset)"
}
return (
$checks
| first
| get html_url
# parse workflow id from url to avoid another request
| parse "https://github.com/nushell/nushell/actions/runs/{workflow_id}/job/{job_id}"
| only workflow_id
| into int
)
}
error make {
msg: $"No artifacts"
label: {
text: $"no commits matching criteria have artifacts"
span: $span
}
help: "Note that artifacts are deleted after 14 days"
}
# BUG: Unreachable echo to appease parse-time type checking
echo
}
# Get artifacts associated with a PR.
#
# Uses the latest commit if not specified
@category "toolkit"
@search-terms get artifacts pr download ci gh api
@example "Get artifact metadata for PR #1234" { toolkit get-artifacts {item: 1234, span: {start: 0, end: 10}} "macos-aarch64" {start: 0, end: 10} }
export def get-artifacts [
number: record<item: int, span: record>
platform: string
span: record<start: int, end: int>
--commit: string
] {
# Make sure gh is available and has auth set up
if (which ^gh | is-empty) {
error make {
msg: "Command not found"
label: {
text: "requires `gh`"
span: $span
}
help: "Please install the `gh` commandline tool"
}
}
try {
^gh auth status --hostname github.com o> $null_device
} catch {
error make {
msg: "No authentication"
label: {
text: "requires GitHub authentication"
span: $span
}
help: "Please run `gh auth login`"
}
}
# Listing all artifacts requires pagination, which results in 8+ requests
# Instead, we can do PR -> commit -> check runs -> artifacts which always is 4 requests
# Get latest commit from PR (or use --commit)
let commits = (
^gh pr view $number.item -R nushell/nushell --json commits
| from json
| get commits.oid
| if $commit != null { where $it == $commit } else {}
)
let workflow_id = get-workflow-run $commits $number.span
let artifacts = (
^gh api $"/repos/nushell/nushell/actions/runs/($workflow_id)/artifacts"
| from json
| get artifacts
| into datetime created_at
| sort-by -r created_at
| where name == $"nu-($number.item)-($platform)"
)
if ($artifacts | is-empty) {
error make {
msg: $"No artifacts"
label: {
text: $"no artifacts for PR match criteria"
span: $span
}
help: "Note that artifacts are deleted after 14 days"
}
}
$artifacts
}