Files
commonDeploy/notify-slack/action.yml
2026-05-12 14:32:35 +09:00

58 lines
1.9 KiB
YAML

name: Slack 배포 시작 알림
description: 배포 시작을 Slack으로 전송하는 스크립트
inputs:
webhook-url:
required: true
runs:
using: composite
steps:
- shell: bash
env:
WEBHOOK_URL: ${{ inputs.webhook-url }}
REPO: ${{ gitea.repository }}
BRANCH: ${{ gitea.ref_name }}
ACTOR: ${{ gitea.actor }}
RUN_NUMBER: ${{ gitea.run_number }}
SHA: ${{ gitea.sha }}
COMMIT_MSG: ${{ gitea.event.head_commit.message }}
run: |
set -eu
SHORT_SHA="${SHA:0:7}"
STATUS_URL="https://status.gitea.pitap.at/${REPO}/actions/runs/${RUN_NUMBER}"
# 이벤트에서 못 받았으면 (수동 trigger 등) git에서 시도, 그것도 실패하면 fallback
if [ -z "${COMMIT_MSG:-}" ]; then
COMMIT_MSG="$(git log -1 --pretty=format:%s 2>/dev/null || echo '(no message)')"
fi
# 멀티라인 커밋 메시지면 첫 줄만
COMMIT_MSG="$(printf '%s' "$COMMIT_MSG" | head -n1)"
HEADER_TEXT="배포 시작 — ${REPO}"
PAYLOAD=$(jq -n \
--arg repo "$REPO" \
--arg branch "$BRANCH" \
--arg msg "$COMMIT_MSG" \
--arg actor "$ACTOR" \
--arg sturl "$STATUS_URL" \
'{
text: ($repo + " 배포 시작"),
blocks: [
{type:"section", text:{type:"mrkdwn",
text: ("*" + $repo + "* 배포 시작")}},
{type:"section", text:{type:"mrkdwn",
text: ("```" + $msg + "```")}},
{type:"context", elements:[
{type:"mrkdwn",
text: ($branch + " · " + $actor + " <" + $sturl + "|상태 보기 →>")}
]}
]
}')
echo "$PAYLOAD" | curl -sS --fail-with-body \
-X POST \
-H 'Content-Type: application/json; charset=utf-8' \
--data @- \
"$WEBHOOK_URL"