this repo has no description
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(deploy): separate build and deploy webhook messages, refactor a lil

dusk 6384f20d f555033b

+34 -7
+34 -7
deploy.nu
··· 25 25 http post --content-type application/json $"https://discord.com/api/webhooks/($env.WEBHOOK_ID)/($env.WEBHOOK_TOKEN)" $msg 26 26 } 27 27 28 + def upload-paste [content: any] { 29 + let paste_url = http post --content-type multipart/form-data "https://0x0.st" {file: ($content | to text | into binary), secret: true} 30 + return $paste_url 31 + } 32 + 33 + def time-block [block] { 34 + let start = date now 35 + let result = do $block 36 + let end = date now 37 + return {result: $result, elapsed: ($end - $start)} 38 + } 39 + 28 40 def deploy [hostname: string] { 29 - log info $"trying to deploy host ($hostname)" 41 + log info $"start deploy host ($hostname)" 30 42 let hooktitle = $"/($hostname)/deploy" 31 43 32 - let start = date now 33 - webhook $hooktitle $"=== deploying ($hostname): started ===\n\n(sys disks | to text)\n\n(sys mem | to text)" 44 + webhook $hooktitle $"=== deploy for ($hostname): started ===\n\n(sys disks | to text)\n\n(sys mem | to text)" 45 + 46 + log info $"build host ($hostname)" 47 + webhook $"($hooktitle)/build" $"=== building ($hostname) ===" 48 + let build_result = time-block { nh os build -H $hostname -- -L --show-trace | complete } 49 + let build_failed = $build_result.result.exit_code != 0 50 + webhook $"($hooktitle)/build" $"=== built ($hostname) ===\n\ntook ($build_result.elapsed)\n\nlog: (upload-paste $build_result.result)" $build_result.result.exit_code $build_failed 34 51 35 - let result = nix run $".#apps.nixinate.($hostname)" -L --show-trace | complete 36 - let end = date now 52 + if $build_failed { 53 + return 54 + } 37 55 38 - let paste_url = http post --content-type multipart/form-data "https://0x0.st" {file: ($result | to text | into binary), secret: true} 39 - webhook $hooktitle $"=== deployed ($hostname): finished ===\n\ntook ($end - $start)\n\nlog: ($paste_url)" $result.exit_code true 56 + log info $"deploy host ($hostname)" 57 + webhook $"($hooktitle)/build" $"=== deploying ($hostname) ===" 58 + let deploy_result = time-block { nix run $".#apps.nixinate.($hostname)" -L --show-trace | complete } 59 + let deploy_failed = $deploy_result.result.exit_code != 0 60 + webhook $"($hooktitle)/build" $"=== deployed ($hostname) ===\n\ntook ($deploy_result.elapsed)\n\nlog: (upload-paste $deploy_result.result)" $deploy_result.result.exit_code $deploy_failed 61 + 62 + if $deploy_failed { 63 + return 64 + } 65 + 66 + webhook $hooktitle $"=== deploy for ($hostname): finished ===" 0 true 40 67 } 41 68 42 69 def update-input [input: string] {