mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Refactor toolkit.nu (#791)
Closes #789 🍻 - Runs without first generating a script - Returns error (file) count - Requires `--and-exit` to exit with error code - Enables alternative report with env `STUB_IDE_CHECK=true` - Expands documentation - All subcommands share same file querying - Prepares for nupm test integration
This commit is contained in:
parent
191636af9c
commit
878bfc615c
3 changed files with 108 additions and 71 deletions
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
|
@ -1,5 +1,5 @@
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NUSHELL_CARGO_PROFILE: ci
|
NUSHELL_CARGO_PROFILE: ci
|
||||||
|
@ -11,19 +11,17 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: 'Fetch main branch'
|
- name: "Fetch main branch"
|
||||||
run: |
|
run: |
|
||||||
git fetch origin main --depth 1
|
git fetch origin main --depth 1
|
||||||
- uses: hustcer/setup-nu@v3.9
|
- uses: hustcer/setup-nu@v3.9
|
||||||
with:
|
with:
|
||||||
version: '*'
|
version: "*"
|
||||||
check-latest: true
|
check-latest: true
|
||||||
features: full # dataframe and extra included
|
features: full # dataframe and extra included
|
||||||
- name: toolkit check pr
|
- name: toolkit check pr
|
||||||
shell: nu {0}
|
shell: nu {0}
|
||||||
|
# nix STUB_IDE_CHECK when nushell/nushell#12208 fixed
|
||||||
run: |
|
run: |
|
||||||
nu -c "use toolkit.nu *; check pr"
|
use ${{ github.workspace }}/toolkit.nu *
|
||||||
- name: run nu-check on modified files
|
STUB_IDE_CHECK=true check pr --and-exit
|
||||||
shell: nu {0}
|
|
||||||
run: |
|
|
||||||
nu ./check-files.nu
|
|
||||||
|
|
24
.github/workflows/daily.yml
vendored
24
.github/workflows/daily.yml
vendored
|
@ -1,9 +1,9 @@
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 0 * * *' # every day at 00:30 AM UTC
|
- cron: "30 0 * * *" # every day at 00:30 AM UTC
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NUSHELL_CARGO_PROFILE: ci
|
NUSHELL_CARGO_PROFILE: ci
|
||||||
|
@ -15,19 +15,17 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: 'Fetch main branch'
|
- name: "Fetch main branch"
|
||||||
run: |
|
run: |
|
||||||
git fetch origin main --depth 1
|
git fetch origin main --depth 1
|
||||||
- uses: hustcer/setup-nu@v3.9
|
- uses: hustcer/setup-nu@v3.9
|
||||||
with:
|
with:
|
||||||
version: '*'
|
version: "*"
|
||||||
check-latest: true
|
check-latest: true
|
||||||
features: full # dataframe and extra included
|
features: full # dataframe and extra included
|
||||||
- name: toolkit generate-file-list --full
|
- name: toolkit check pr --full
|
||||||
shell: nu {0}
|
shell: nu {0}
|
||||||
|
# nix STUB_IDE_CHECK when nushell/nushell#12208 fixed
|
||||||
run: |
|
run: |
|
||||||
nu -c "use toolkit.nu *; generate-file-list --full"
|
use ${{ github.workspace }}/toolkit.nu *
|
||||||
- name: run nu-check on all files
|
STUB_IDE_CHECK=true check pr --full --and-exit
|
||||||
shell: nu {0}
|
|
||||||
run: |
|
|
||||||
nu ./check-files.nu
|
|
||||||
|
|
135
toolkit.nu
135
toolkit.nu
|
@ -4,61 +4,102 @@
|
||||||
# the main purpose of `toolkit` is to offer an easy to use interface for the
|
# the main purpose of `toolkit` is to offer an easy to use interface for the
|
||||||
# developer during a PR cycle.
|
# developer during a PR cycle.
|
||||||
|
|
||||||
|
# Check that all the tests pass.
|
||||||
# check that all the tests pass
|
#
|
||||||
|
# Input:
|
||||||
|
# Optional file paths to check or infer them from Git
|
||||||
export def test [
|
export def test [
|
||||||
] {
|
--full # Check all files instead of input
|
||||||
print "toolkit test: not implemented!"
|
--and-exit # Exit with error count
|
||||||
|
]: [list<path> -> int, nothing -> int] {
|
||||||
|
with files --full=$full --and-exit=$and_exit { |files|
|
||||||
|
print "test: not implemented!"
|
||||||
|
[0] # success code
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# run all the necessary checks and tests to submit a perfect PR
|
# Run all the necessary checks and tests to submit a perfect PR.
|
||||||
|
#
|
||||||
|
# Input:
|
||||||
|
# Optional file paths to check or infer them from Git
|
||||||
export def "check pr" [
|
export def "check pr" [
|
||||||
] {
|
--full # Check all files instead of input
|
||||||
generate-file-list
|
--and-exit # Exit with error count
|
||||||
test
|
]: [list<path> -> int, nothing -> int] {
|
||||||
|
with files --full=$full --and-exit=$and_exit { |files|
|
||||||
|
[
|
||||||
|
{ lint }
|
||||||
|
{ test }
|
||||||
|
] | par-each { |task| $files | do $task } # TODO: buffer output
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export def main [] { help toolkit }
|
# View subcommands.
|
||||||
|
export def main []: nothing -> nothing {
|
||||||
|
help toolkit
|
||||||
|
}
|
||||||
|
|
||||||
export def generate-file-list [ --full ] {
|
# Wrap file lookup and exit codes.
|
||||||
let start = "let files = ["
|
def "with files" [
|
||||||
|
task: closure
|
||||||
mut files = [""]
|
--full
|
||||||
|
--and-exit
|
||||||
if $full {
|
]: [list<path> -> int, nothing -> int] {
|
||||||
# all the *.nu files in the repo
|
let files = match [$in, $full] {
|
||||||
# exept for `before_v0.60`
|
[_ true] => (glob **/*.nu --exclude [before_v0.60/**])
|
||||||
print "checking all files..."
|
[null _] => (git diff --name-only origin/main | lines)
|
||||||
mut $files = glob **/*.nu --exclude [before_v0.60/**]
|
[$files _] => $files
|
||||||
|
} | where $it ends-with .nu and ($it | path exists)
|
||||||
|
let error_count = if ($files | length) == 0 {
|
||||||
|
print 'warning: no .nu files found!'
|
||||||
|
0
|
||||||
} else {
|
} else {
|
||||||
# only the *.nu files changed in comparison with origin/main
|
$files
|
||||||
$files = (git diff --name-only origin/main | lines | filter { str ends-with '.nu'} | each { path expand })
|
| each { path expand }
|
||||||
|
| do $task $files # run the closure with both input and param
|
||||||
|
| math sum # it MUST return a non-empty list of ints
|
||||||
}
|
}
|
||||||
|
if $and_exit {
|
||||||
|
exit $error_count
|
||||||
let new_list = $files | str join ",\n" | append "]"
|
} else {
|
||||||
|
$error_count
|
||||||
let final = "
|
}
|
||||||
|
}
|
||||||
mut exit_code = 0
|
|
||||||
for file in $files {
|
# Check the input file with nu --ide-check.
|
||||||
let diagnostics_table = nu --ide-check 10 $file | to text | ['[', $in, ']'] | str join | from json
|
export def "lint ide-check" []: path -> int {
|
||||||
let result = $diagnostics_table | where type == \"diagnostic\" | is-empty
|
let file = $in
|
||||||
if $result {
|
let stub = $env.STUB_IDE_CHECK? | default false | into bool
|
||||||
print $\"✔ ($file) is ok\"
|
let diagnostics = if $stub {
|
||||||
} else {
|
do { nu --no-config-file --commands $"use '($file)'" }
|
||||||
print $\"❌ ($file) has errors:\"
|
| complete
|
||||||
print ($diagnostics_table | where type == \"diagnostic\" | reject span)
|
| [[severity message]; [$in.exit_code $in.stderr]]
|
||||||
$exit_code = 1
|
| where severity != 0
|
||||||
}
|
} else {
|
||||||
|
nu --ide-check 10 $file
|
||||||
|
| $"[($in)]"
|
||||||
|
| from nuon
|
||||||
|
| where type == diagnostic
|
||||||
|
| select severity message
|
||||||
|
}
|
||||||
|
let error_count = $diagnostics | length
|
||||||
|
if $error_count == 0 {
|
||||||
|
print $"lint: ✔ ($file) is ok"
|
||||||
|
} else {
|
||||||
|
print $"lint: ❌ ($file) has errors:\n($diagnostics | table)"
|
||||||
|
}
|
||||||
|
$error_count
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check that all the files parse.
|
||||||
|
#
|
||||||
|
# Input:
|
||||||
|
# Optional file paths to check or infer them from Git
|
||||||
|
export def lint [
|
||||||
|
--full # Check all files instead of input
|
||||||
|
--and-exit # Exit with error count
|
||||||
|
]: [list<path> -> int, nothing -> int] {
|
||||||
|
with files --full=$full --and-exit=$and_exit {
|
||||||
|
par-each { lint ide-check }
|
||||||
}
|
}
|
||||||
print $\"💚 All files checked!\"
|
|
||||||
|
|
||||||
exit $exit_code
|
|
||||||
"
|
|
||||||
|
|
||||||
$start
|
|
||||||
| append $new_list
|
|
||||||
| append $final
|
|
||||||
| save "check-files.nu" --force
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue