From 044c83cd228b6e44ec900313a6573a3d2927f821 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:50:25 +0800 Subject: [PATCH] ci: bark notification on build success / failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds scripts/bark-notify.sh (deployment detail, hardcoded device_key + endpoint — per the script header it's a deployment constant, not a secret) and a final workflow step that pushes a ✅/❌ notification on every job result. The notify step: - runs unconditionally (if: always()) so failures also notify - is a side-effect — if Bark itself is unreachable, the curl failure is swallowed so CI does not turn red on a notification outage - uses portable context vars (github.repository / ref_name / sha / actor / job.status) which work on Gitea Actions Co-Authored-By: Claude --- .github/workflows/build.yml | 15 +++++++++++++++ scripts/bark-notify.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 scripts/bark-notify.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9dcae6..fbd507f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,3 +30,18 @@ jobs: name: snapshot-dist path: dist/snapshot-* if-no-files-found: error + + # Always run, regardless of job status. The script is a side-effect; + # if the notification itself fails we swallow the error so CI does + # not turn red on a Bark outage. + - name: Notify Bark + if: always() + run: | + if [ "${{ job.status }}" = "success" ]; then + TITLE="✅ CI: ${{ github.repository }}@${{ github.ref_name }}" + BODY="Build OK for ${{ github.sha }} by ${{ github.actor }}" + else + TITLE="❌ CI: ${{ github.repository }}@${{ github.ref_name }}" + BODY="Build FAILED for ${{ github.sha }} by ${{ github.actor }}" + fi + ./scripts/bark-notify.sh "$TITLE" "$BODY" || echo "Bark notify failed (non-fatal)" diff --git a/scripts/bark-notify.sh b/scripts/bark-notify.sh new file mode 100755 index 0000000..e1013ee --- /dev/null +++ b/scripts/bark-notify.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# bark-notify.sh — push a notification to the local Bark server. +# +# Usage: bark-notify.sh <body> +# +# The Bark endpoint, device_key, and group are pinned in this script +# (it is a deployment detail, not a secret). The group is "Gitea" — +# change it here if you want to sort notifications by category. + +set -euo pipefail + +if [ "$#" -ne 2 ]; then + echo "usage: $0 <title> <body>" >&2 + exit 1 +fi + +TITLE="$1" +BODY="$2" + +PAYLOAD=$(cat <<EOF +{ + "device_key": "6ZFVsxM95cuAjYoNLWSWaN", + "title": "${TITLE}", + "body": "${BODY}", + "group": "Gitea", + "isArchive": 1, + "ttl": 3600 +} +EOF +) + +curl -s \ + -X POST http://101.43.40.124:81/push \ + -H "Content-Type: application/json; charset=utf-8" \ + -d "${PAYLOAD}" + +echo "bark notified: ${TITLE}"