mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 04:19:19 -08:00
fix: CI notifications w/ ntfy
This commit is contained in:
parent
8a0fa4d5d1
commit
3c3a07aa9e
2 changed files with 34 additions and 28 deletions
|
|
@ -1,22 +1,23 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""}
|
CI_NOTIFY_LINK="${CI_NOTIFY_LINK:-""}"
|
||||||
|
CI_NOTIFY_TOKEN="${CI_NOTIFY_TOKEN:-""}"
|
||||||
SYSTEM_LINK=${1:-""}
|
SYSTEM_LINK=${1:-""}
|
||||||
ALIAS=${2:-""}
|
ALIAS=${2:-""}
|
||||||
SYSTEM_TYPE=${3:-""}
|
SYSTEM_TYPE=${3:-""}
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
send_discord_message() {
|
send_notification() {
|
||||||
local message="$1"
|
local priority="$1"
|
||||||
if [[ -n "$DISCORD_WEBHOOK_LINK" ]]; then
|
local tag="$2"
|
||||||
local escaped_message
|
local message="$3"
|
||||||
escaped_message=$(printf '%s' "$message" | jq -R -s '.')
|
curl -s -X POST \
|
||||||
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
|
-H "Authorization: Bearer ${CI_NOTIFY_TOKEN}" \
|
||||||
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
|
-H "prio:${priority}" \
|
||||||
else
|
-H "tags:${tag}" \
|
||||||
echo "Discord message (not sent): $message"
|
-d "$message" \
|
||||||
fi
|
"${CI_NOTIFY_LINK}"
|
||||||
}
|
}
|
||||||
|
|
||||||
init_nfargs() {
|
init_nfargs() {
|
||||||
|
|
@ -40,7 +41,7 @@ init_nfargs() {
|
||||||
perform_cachix_push() {
|
perform_cachix_push() {
|
||||||
local nflinksuffix="-L"
|
local nflinksuffix="-L"
|
||||||
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
|
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"*/
|
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*/
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +60,7 @@ if [[ -z "$SYSTEM_LINK" || -z "$ALIAS" || -z "$SYSTEM_TYPE" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then
|
||||||
export NF_UPDATE_CACHIX_PUSH=1
|
export NF_UPDATE_CACHIX_PUSH=1
|
||||||
|
|
@ -98,14 +99,14 @@ else
|
||||||
|
|
||||||
if ! nix build "$nfinstallable" "${nfargs[@]}"; then
|
if ! nix build "$nfinstallable" "${nfargs[@]}"; then
|
||||||
if [[ -n $nfwarn ]]; 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
|
echo "Build failure allowed for ${nfsystem}, ignoring..." >&2
|
||||||
else
|
else
|
||||||
send_discord_message "Build failure for ${nfsystem}, problem!"
|
send_notification "default" "warning" "Build failure for ${nfsystem}, problem!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
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_cachix_push
|
||||||
perform_garbage_collection
|
perform_garbage_collection
|
||||||
fi
|
fi
|
||||||
|
|
@ -117,7 +118,7 @@ if [[ -n ${NF_ACTIONS_TEST_ASYNC-} ]]; then
|
||||||
perform_cachix_push
|
perform_cachix_push
|
||||||
perform_garbage_collection
|
perform_garbage_collection
|
||||||
else
|
else
|
||||||
send_discord_message "Async build failure for ${nfsystem}, problem!"
|
send_notification "default" "warning" "Async build failure for ${nfsystem}, problem!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,20 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""}
|
CI_NOTIFY_LINK="${CI_NOTIFY_LINK:-""}"
|
||||||
|
CI_NOTIFY_TOKEN="${CI_NOTIFY_TOKEN:-""}"
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
send_discord_message() {
|
send_notification() {
|
||||||
local message="$1"
|
local priority="$1"
|
||||||
local escaped_message
|
local tag="$2"
|
||||||
escaped_message=$(printf '%s' "$message" | jq -R -s '.')
|
local message="$3"
|
||||||
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
|
curl -s -X POST \
|
||||||
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
|
-H "Authorization: Bearer ${CI_NOTIFY_TOKEN}" \
|
||||||
|
-H "prio:${priority}" \
|
||||||
|
-H "tags:${tag}" \
|
||||||
|
-d "$message" \
|
||||||
|
"${CI_NOTIFY_LINK}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then
|
if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then
|
||||||
|
|
@ -18,7 +23,7 @@ fi
|
||||||
|
|
||||||
cd "$NF_CONFIG_ROOT"
|
cd "$NF_CONFIG_ROOT"
|
||||||
|
|
||||||
send_discord_message "Beginning flake update cron job"
|
send_notification "low" "gear" "Beginning flake update cron job"
|
||||||
|
|
||||||
nix flake update "$@"
|
nix flake update "$@"
|
||||||
|
|
||||||
|
|
@ -34,7 +39,7 @@ if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
|
||||||
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
|
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
|
||||||
fi
|
fi
|
||||||
if [[ -z ${NF_UPDATE_SKIP-} ]]; then
|
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
|
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
|
||||||
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
|
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
|
||||||
fi
|
fi
|
||||||
|
|
@ -42,7 +47,7 @@ if [[ -z ${NF_UPDATE_SKIP-} ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} && -v NF_ACTIONS_TEST_OUTLINK ]]; then
|
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 kittywitch "./${NF_ACTIONS_TEST_OUTLINK}"*/ &
|
||||||
CACHIX_PUSH=$!
|
CACHIX_PUSH=$!
|
||||||
fi
|
fi
|
||||||
|
|
@ -65,7 +70,7 @@ env \
|
||||||
|
|
||||||
if [[ ${GITHUB_REF-} = refs/heads/${NF_UPDATE_BRANCH-main} ]]; then
|
if [[ ${GITHUB_REF-} = refs/heads/${NF_UPDATE_BRANCH-main} ]]; then
|
||||||
git push origin "HEAD:${NF_UPDATE_BRANCH-main}"
|
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
|
fi
|
||||||
|
|
||||||
wait "${CACHIX_PUSH-}"
|
wait "${CACHIX_PUSH-}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue