diff --git a/notify-slack/action.yml b/notify-slack/action.yml new file mode 100644 index 0000000..29b9f8b --- /dev/null +++ b/notify-slack/action.yml @@ -0,0 +1,53 @@ +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_ID: ${{ gitea.run_id }} + SHA: ${{ gitea.sha }} + run: | + set -eu + SHORT_SHA="${SHA:0:7}" + STATUS_URL="https://status.gitea.sample.com/${REPO}/actions/runs/${RUN_ID}" + COMMIT_MSG="$(git log -1 --pretty=format:%s 2>/dev/null || echo '(no message)')" + HEADER_TEXT="🚀 배포 시작 — ${REPO}" + + PAYLOAD=$(jq -n \ + --arg header "$HEADER_TEXT" \ + --arg branch "$BRANCH" \ + --arg sha "$SHORT_SHA" \ + --arg actor "$ACTOR" \ + --arg msg "$COMMIT_MSG" \ + --arg sturl "$STATUS_URL" \ + '{ + text: $header, + blocks: [ + {type:"header", text:{type:"plain_text", text:$header, emoji:true}}, + {type:"section", fields:[ + {type:"mrkdwn", text:("*브랜치*\n`" + $branch + "`")}, + {type:"mrkdwn", text:("*커밋*\n`" + $sha + "` " + $msg)}, + {type:"mrkdwn", text:("*실행자*\n" + $actor)} + ]}, + {type:"actions", elements:[ + {type:"button", + text:{type:"plain_text", text:"📊 배포 상태 보기", emoji:true}, + url:$sturl, + style:"primary"} + ]} + ] + }') + + echo "$PAYLOAD" | curl -sS --fail-with-body \ + -X POST \ + -H 'Content-Type: application/json; charset=utf-8' \ + --data @- \ + "$WEBHOOK_URL" \ No newline at end of file