-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nurfile
164 lines (138 loc) · 4.28 KB
/
nurfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Example, just for fun
# Just tell anybody or the "world" hello
def "nur hello" [
name: string = "world" # The name to say hello to
] {
print $"hello ($name)"
}
# Actual useful tasks
# Setup local environment and install deps
def "nur install" [] {
cargo fetch
init-pre-commit
}
# Update local dev environment
def "nur update" [] {
cargo fetch
}
# Run cargo
def --wrapped "nur cargo" [...args: string] {
cargo ...$args
}
# Run cargo build
def --wrapped "nur build" [...args: string] {
cargo "build" ...$args
}
# Run cargo run
def --wrapped "nur run" [...args: string] {
cargo "run" ...$args
}
# Run tests
def "nur test" [
--coverage
] {
if $coverage {
cargo tarpaulin --exclude-files _*
} else {
cargo test
}
}
# Run nur nuscript tests
def "nur test-nur" [] {
cd nur-tests
cargo run -- --quiet prepare
cargo run -- --quiet run-all
}
# Run one task for all enabled features to see those compile
def "nur test-features" [] {
open Cargo.toml | get features | transpose key value | get key | each {
|it|
print $"Running 'nur hello ($it)' to check feature ($it)"
cargo run -F $it -- --quiet hello $it
}
}
# Run linter (clippy)
def --wrapped "nur lint" [
...args
] {
cargo clippy ...$args
}
# Run all QA tasks
def "nur qa" [] {
print "Running rust tests"
nur test
print "Running nur tests"
nur test-nur
print "Running feature tests"
nur test-features
print "Running clippy linter"
nur lint
print "Running cargo check"
nur cargo check
print "Running cargo fmt"
nur cargo fmt
}
# Update version in Cargo.toml
def "nur version" [
version: string
] {
let parsed_version = $version | parse --regex '^(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9]+)(-rc(?P<rc>[0-9]+))?$'
if ($parsed_version | is-empty) {
error make { msg: "No valid version string provided" }
}
cargo set-version $version
}
# Publish to crates.io
def "nur publish" [] {
cargo publish
}
# Update version and release to crates.io
def "nur release" [
version: string
] {
print $"Updating to version (ansi purple)($version)(ansi reset)"
nur version $version
print ""
print $"Creating release commit and tag '(ansi purple)v($version)(ansi reset)'"
git add Cargo.toml Cargo.lock
git commit -m $"release: 🔖 v($version)"
git tag $"v($version)"
print ""
print "Publishing to crates.io"
nur publish
print ""
print $"(ansi yellow)Don't forget to push last commit + tags to github!(ansi reset)"
}
# Update nu dependencies to version
def "nur upgrade-nu" [
version: string
] {
print $"Updating all required nu packages to (ansi purple)($version)(ansi reset)"
open Cargo.toml | get dependencies | transpose key value | each {
|it| if ($it.key starts-with "nu-") and not ($it.key == "nu-ansi-term") {
try {
cargo add $"($it.key)@($version)" (if $it.value.optional {"--optional"})
} catch {
cargo add $"($it.key)@($version)"
}
}
}
print ""
print $"Storing version (ansi purple)($version)(ansi reset) in src/nu_version.rs as NU_VERSION constant"
$"pub\(crate) const NU_VERSION: &str = \"($version)\";\n" | save -f src/nu_version.rs
print ""
print $"(ansi yellow)IMPORTANT: Please ensure all other packages are also upgraded accordingly:(ansi reset)"
print $" -> (ansi cyan)nu-ansi-term(ansi reset): needs to be the same version as used in (ansi cyan)nu(ansi reset)"
print $" -> (ansi cyan)miette(ansi reset): needs to be the same version as used in (ansi cyan)nu(ansi reset)"
print $" -> (ansi cyan)openssl(ansi reset): needs to be the same version as used in (ansi cyan)nu(ansi reset)"
print $" -> See nushell/Cargo.toml in section (ansi cyan)[workspace.dependencies](ansi reset) for details on used versions"
print $" -> Also ensure (ansi cyan)rust-version(ansi reset) is set to the same version as used in (ansi cyan)nu(ansi reset)"
}
# Utility commands
def init-pre-commit [] {
if (which pre-commit | is-empty) {
print -e $"(ansi red)You don't have pre-commit installed locally, pre-commit hooks cannot be initialized(ansi reset)"
return null
}
pre-commit install --install-hooks
}