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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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-}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue