From 3c3a07aa9e51609127f921f6d4d74f196a62b5d2 Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Mon, 13 Oct 2025 13:21:15 -0700 Subject: [PATCH] fix: CI notifications w/ ntfy --- packages/nf-build-system/build-system.sh | 35 ++++++++++++------------ packages/nf-update/update.sh | 27 ++++++++++-------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/packages/nf-build-system/build-system.sh b/packages/nf-build-system/build-system.sh index b817a377..d6a1d096 100755 --- a/packages/nf-build-system/build-system.sh +++ b/packages/nf-build-system/build-system.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash set -euo pipefail -DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""} +CI_NOTIFY_LINK="${CI_NOTIFY_LINK:-""}" +CI_NOTIFY_TOKEN="${CI_NOTIFY_TOKEN:-""}" SYSTEM_LINK=${1:-""} ALIAS=${2:-""} SYSTEM_TYPE=${3:-""} # Helper functions -send_discord_message() { - local message="$1" - if [[ -n "$DISCORD_WEBHOOK_LINK" ]]; then - local escaped_message - escaped_message=$(printf '%s' "$message" | jq -R -s '.') - curl -s -H "Accept: application/json" -H "Content-Type: application/json" \ - -X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK" - else - echo "Discord message (not sent): $message" - fi +send_notification() { + local priority="$1" + local tag="$2" + local message="$3" + curl -s -X POST \ + -H "Authorization: Bearer ${CI_NOTIFY_TOKEN}" \ + -H "prio:${priority}" \ + -H "tags:${tag}" \ + -d "$message" \ + "${CI_NOTIFY_LINK}" } init_nfargs() { @@ -40,7 +41,7 @@ init_nfargs() { perform_cachix_push() { local nflinksuffix="-L" if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then - send_discord_message "Cachix pushing ${SYSTEM_TYPE} system build for ${ALIAS}" + send_notification "low" "floppy_disk" "Cachix pushing ${SYSTEM_TYPE} system build for ${ALIAS}" cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*/ fi } @@ -59,7 +60,7 @@ if [[ -z "$SYSTEM_LINK" || -z "$ALIAS" || -z "$SYSTEM_TYPE" ]]; then exit 1 fi -send_discord_message "Starting ${SYSTEM_TYPE} system build for ${ALIAS}" +send_notification "low" "gear" "Starting ${SYSTEM_TYPE} system build for ${ALIAS}" if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then export NF_UPDATE_CACHIX_PUSH=1 @@ -98,14 +99,14 @@ else if ! nix build "$nfinstallable" "${nfargs[@]}"; then if [[ -n $nfwarn ]]; then - send_discord_message "Build failure allowed for ${nfsystem}, ignoring..." + send_notification "default" "warning" "Build failure allowed for ${nfsystem}, ignoring..." echo "Build failure allowed for ${nfsystem}, ignoring..." >&2 else - send_discord_message "Build failure for ${nfsystem}, problem!" + send_notification "default" "warning" "Build failure for ${nfsystem}, problem!" exit 1 fi else - send_discord_message "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!" + send_notification "low" "white_check_mark" "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!" perform_cachix_push perform_garbage_collection fi @@ -117,7 +118,7 @@ if [[ -n ${NF_ACTIONS_TEST_ASYNC-} ]]; then perform_cachix_push perform_garbage_collection else - send_discord_message "Async build failure for ${nfsystem}, problem!" + send_notification "default" "warning" "Async build failure for ${nfsystem}, problem!" exit 1 fi fi diff --git a/packages/nf-update/update.sh b/packages/nf-update/update.sh index 9396ff7c..4b171e5d 100644 --- a/packages/nf-update/update.sh +++ b/packages/nf-update/update.sh @@ -1,15 +1,20 @@ #!/usr/bin/env bash set -eu -DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""} +CI_NOTIFY_LINK="${CI_NOTIFY_LINK:-""}" +CI_NOTIFY_TOKEN="${CI_NOTIFY_TOKEN:-""}" # Helper functions -send_discord_message() { - local message="$1" - local escaped_message - escaped_message=$(printf '%s' "$message" | jq -R -s '.') - curl -s -H "Accept: application/json" -H "Content-Type: application/json" \ - -X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK" +send_notification() { + local priority="$1" + local tag="$2" + local message="$3" + curl -s -X POST \ + -H "Authorization: Bearer ${CI_NOTIFY_TOKEN}" \ + -H "prio:${priority}" \ + -H "tags:${tag}" \ + -d "$message" \ + "${CI_NOTIFY_LINK}" } if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then @@ -18,7 +23,7 @@ fi cd "$NF_CONFIG_ROOT" -send_discord_message "Beginning flake update cron job" +send_notification "low" "gear" "Beginning flake update cron job" nix flake update "$@" @@ -34,7 +39,7 @@ if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result} fi if [[ -z ${NF_UPDATE_SKIP-} ]]; then - send_discord_message "checking that nodes still build..." + send_notification "low" "information_source" "Checking that nodes still build..." if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result} fi @@ -42,7 +47,7 @@ if [[ -z ${NF_UPDATE_SKIP-} ]]; then fi if [[ -n ${NF_UPDATE_CACHIX_PUSH-} && -v NF_ACTIONS_TEST_OUTLINK ]]; then - send_discord_message "Cachix pushing" + send_notification "low" "floppy_disk" "Cachix pushing" cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK}"*/ & CACHIX_PUSH=$! fi @@ -65,7 +70,7 @@ env \ if [[ ${GITHUB_REF-} = refs/heads/${NF_UPDATE_BRANCH-main} ]]; then git push origin "HEAD:${NF_UPDATE_BRANCH-main}" - send_discord_message "Pushed a new commit!" + send_notification "low" "white_check_mark" "Pushed a new commit!" fi wait "${CACHIX_PUSH-}"