fix(guide-ci): Slack notify must not fail the deploy #9
@@ -86,6 +86,7 @@ jobs:
|
|||||||
# org secret; if unset the step no-ops so forks/dry-runs don't error.
|
# org secret; if unset the step no-ops so forks/dry-runs don't error.
|
||||||
- name: Notify Slack (#hiveops-dev-deploy)
|
- name: Notify Slack (#hiveops-dev-deploy)
|
||||||
if: always()
|
if: always()
|
||||||
|
continue-on-error: true # a notification must NEVER fail the deploy
|
||||||
env:
|
env:
|
||||||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||||
JOB_STATUS: ${{ job.status }}
|
JOB_STATUS: ${{ job.status }}
|
||||||
@@ -98,7 +99,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
[ -z "$SLACK_WEBHOOK_URL" ] && { echo "no SLACK_WEBHOOK_URL secret — skipping"; exit 0; }
|
[ -z "$SLACK_WEBHOOK_URL" ] && { echo "no SLACK_WEBHOOK_URL secret — skipping"; exit 0; }
|
||||||
SHORT="${SHA:0:8}"
|
SHORT="${SHA:0:8}"
|
||||||
SUBJECT="$(printf '%s' "$COMMIT_MSG" | head -n1 | tr -d '"\\' | cut -c1-100)"
|
FIRST="${COMMIT_MSG%%$'\n'*}" # first line via param-expansion (no pipe)
|
||||||
|
SUBJECT="$(printf '%s' "$FIRST" | tr -d '"\\' | cut -c1-100)"
|
||||||
if [ "$JOB_STATUS" = "success" ]; then
|
if [ "$JOB_STATUS" = "success" ]; then
|
||||||
COLOR="#2eb67d"; TITLE=":white_check_mark: guide → bcos.dev deployed"
|
COLOR="#2eb67d"; TITLE=":white_check_mark: guide → bcos.dev deployed"
|
||||||
else
|
else
|
||||||
@@ -106,4 +108,6 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
PAYLOAD=$(printf '{"attachments":[{"color":"%s","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"*%s*"}},{"type":"section","fields":[{"type":"mrkdwn","text":"*Commit*\\n`%s` %s"},{"type":"mrkdwn","text":"*Branch*\\n%s"},{"type":"mrkdwn","text":"*By*\\n%s"},{"type":"mrkdwn","text":"*Run*\\n#%s"}]},{"type":"actions","elements":[{"type":"button","text":{"type":"plain_text","text":"View run"},"url":"%s"}]}]}]}' \
|
PAYLOAD=$(printf '{"attachments":[{"color":"%s","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"*%s*"}},{"type":"section","fields":[{"type":"mrkdwn","text":"*Commit*\\n`%s` %s"},{"type":"mrkdwn","text":"*Branch*\\n%s"},{"type":"mrkdwn","text":"*By*\\n%s"},{"type":"mrkdwn","text":"*Run*\\n#%s"}]},{"type":"actions","elements":[{"type":"button","text":{"type":"plain_text","text":"View run"},"url":"%s"}]}]}]}' \
|
||||||
"$COLOR" "$TITLE" "$SHORT" "$SUBJECT" "$REF_NAME" "$ACTOR" "$RUN_NUMBER" "$RUN_URL")
|
"$COLOR" "$TITLE" "$SHORT" "$SUBJECT" "$REF_NAME" "$ACTOR" "$RUN_NUMBER" "$RUN_URL")
|
||||||
curl -s -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$SLACK_WEBHOOK_URL"
|
# Non-fatal: capture the HTTP code, never let curl's exit fail the step.
|
||||||
|
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$SLACK_WEBHOOK_URL" || echo "curl-error")
|
||||||
|
echo "slack notify HTTP: $code (200 = card posted; anything else = runner could not reach Slack)"
|
||||||
|
|||||||
Reference in New Issue
Block a user