ci: add Slack commit notify #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Slack Commit Notify | |
| on: | |
| push: | |
| branches: ['*'] | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Post to Slack | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_DAILY_WEBHOOK }} | |
| run: | | |
| # Get commit info | |
| REPO_NAME="${GITHUB_REPOSITORY#*/}" | |
| COMMIT_MSG=$(echo '${{ github.event.head_commit.message }}' | head -1) | |
| COMMIT_HASH="${GITHUB_SHA:0:7}" | |
| BRANCH="${GITHUB_REF#refs/heads/}" | |
| AUTHOR="${{ github.event.head_commit.author.name }}" | |
| # Determine emoji based on commit type | |
| EMOJI="💻" | |
| if echo "$COMMIT_MSG" | grep -qiE "^feat"; then EMOJI="✨"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^fix"; then EMOJI="🐛"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^docs"; then EMOJI="📝"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^refactor"; then EMOJI="♻️"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^test"; then EMOJI="🧪"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^perf"; then EMOJI="⚡"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "^chore"; then EMOJI="🔧"; fi | |
| if echo "$COMMIT_MSG" | grep -qiE "release|bump.*version|v[0-9]"; then EMOJI="🚀"; fi | |
| # Clean commit message | |
| CLEAN_MSG=$(echo "$COMMIT_MSG" | sed 's/^[a-z]*[^:]*: //') | |
| # Escape for JSON | |
| CLEAN_MSG=$(echo "$CLEAN_MSG" | sed 's/"/\\"/g' | head -c 100) | |
| # Build and send message | |
| curl -s -X POST -H 'Content-type: application/json' \ | |
| --data "{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${EMOJI} *${CLEAN_MSG}*\n\\\`${REPO_NAME}\\\` on \\\`${BRANCH}\\\` • ${COMMIT_HASH} • by ${AUTHOR}\"}}]}" \ | |
| "$SLACK_WEBHOOK" |