You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.4 KiB
Plaintext
74 lines
1.4 KiB
Plaintext
# notify when the latest ci pipeline completes
|
|
export def notify [] {
|
|
while (info | get status) in ["running", "queued"] {
|
|
sleep 1sec;
|
|
};
|
|
let name = ($env.PWD | path basename)
|
|
notify-send $"CI ($name)" "Job completed"
|
|
}
|
|
|
|
|
|
export def watch [] {
|
|
loop {
|
|
while (info | get status) != "running" {
|
|
sleep 10sec;
|
|
}
|
|
notify
|
|
}
|
|
}
|
|
|
|
export def info [] {
|
|
if (get-ci) == "gitlab" {
|
|
glab ci get -F json | from json
|
|
} else {
|
|
(gh run list --json conclusion,name,startedAt,status | from json | first
|
|
| {
|
|
name: $in.name,
|
|
conclusion: $in.conclusion,
|
|
status: (match $in.status {
|
|
"in_progress" => {"running"},
|
|
_ => $in.status
|
|
}),
|
|
})
|
|
}
|
|
}
|
|
|
|
# notify in background
|
|
export def notify-bg [] {
|
|
use task.nu
|
|
task spawn -i -l "ci-notify" -g (task-group) {
|
|
ci notify
|
|
}
|
|
}
|
|
|
|
export def watch-bg [] {
|
|
use task.nu
|
|
task spawn -l "ci-watch" -g (task-group) {
|
|
while (ci info | get status) != "running" {
|
|
sleep 10sec;
|
|
}
|
|
ci notify
|
|
ci watch-bg
|
|
}
|
|
}
|
|
|
|
export def get-ci [] {
|
|
let remote = (git remote get-url --all origin)
|
|
if ($remote | str contains gitlab) {
|
|
"gitlab"
|
|
} else if ($remote | str contains github.com) {
|
|
"github"
|
|
}
|
|
}
|
|
|
|
def task-group [] {
|
|
let name = ($env.PWD | path basename)
|
|
let groupname = $"ci-($name)"
|
|
|
|
if not ($groupname in ...(task group | columns)) {
|
|
task group add $groupname -p 4
|
|
}
|
|
|
|
$groupname
|
|
}
|