-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-push-check.ps1
49 lines (40 loc) · 1.28 KB
/
pre-push-check.ps1
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
function Invoke-NativeCommand() {
# A handy way to run a command, and automatically throw an error if the
# exit code is non-zero.
if ($args.Count -eq 0) {
throw "Must supply some arguments."
}
$command = $args[0]
$commandArgs = @()
if ($args.Count -gt 1) {
$commandArgs = $args[1..($args.Count - 1)]
}
& $command $commandArgs
$result = $LASTEXITCODE
if ($result -ne 0) {
throw "$command $commandArgs exited with code $result."
}
}
# This is only for PowerShell exceptions. PowerShell does not consider nonzero exit codes to be errors.
# The helper function above takes care of those.
$ErrorActionPreference = "Stop"
# If changing any of these commands, make the same changes to the workflows in .github/workflows!
Invoke-NativeCommand cargo fmt
Invoke-NativeCommand cargo check --all-targets --all-features
Invoke-NativeCommand cargo test
Invoke-NativeCommand cargo clippy --all-targets --all-features
try {
Set-Location web
Invoke-NativeCommand npm install
Invoke-NativeCommand npx --no-install prettier --write .
Invoke-NativeCommand npm run build
Write-Output "All ok!"
}
catch {
Write-Host "An error occurred: $_"
exit 1
}
finally {
# Restore the original working directory
Set-Location ..
}