|
| 1 | +name: Slack Notification (Reusable) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + title: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + description: 'Notification title (e.g., "Package Release", "Release Tags Created")' |
| 10 | + status: |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + default: 'info' |
| 14 | + description: 'Notification status: success, failure, or info' |
| 15 | + version: |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + description: 'Version string to display (e.g., "supabase-v2.0.0")' |
| 19 | + package: |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + description: 'Package name (e.g., "gotrue", "postgrest")' |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + |
| 27 | +jobs: |
| 28 | + notify: |
| 29 | + name: Send Slack Notification |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 5 |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Send Slack notification |
| 35 | + run: | |
| 36 | + # Determine status emoji and color |
| 37 | + if [ "${{ inputs.status }}" == "success" ]; then |
| 38 | + STATUS_EMOJI="✅" |
| 39 | + COLOR="#36a64f" |
| 40 | + elif [ "${{ inputs.status }}" == "failure" ]; then |
| 41 | + STATUS_EMOJI="❌" |
| 42 | + COLOR="#ff0000" |
| 43 | + else |
| 44 | + STATUS_EMOJI="ℹ️" |
| 45 | + COLOR="#3498db" |
| 46 | + fi |
| 47 | +
|
| 48 | + # Build version text |
| 49 | + VERSION_TEXT="" |
| 50 | + if [ -n "${{ inputs.version }}" ]; then |
| 51 | + VERSION_TEXT="\n*Version:* \`${{ inputs.version }}\`" |
| 52 | + fi |
| 53 | +
|
| 54 | + # Build package text |
| 55 | + PACKAGE_TEXT="" |
| 56 | + if [ -n "${{ inputs.package }}" ]; then |
| 57 | + PACKAGE_TEXT="\n*Package:* \`${{ inputs.package }}\`" |
| 58 | + fi |
| 59 | +
|
| 60 | + # Build Slack message payload |
| 61 | + PAYLOAD=$(cat <<EOF |
| 62 | + { |
| 63 | + "blocks": [ |
| 64 | + { |
| 65 | + "type": "header", |
| 66 | + "text": { |
| 67 | + "type": "plain_text", |
| 68 | + "text": "${STATUS_EMOJI} ${{ inputs.title }} - ${{ inputs.status }}" |
| 69 | + } |
| 70 | + }, |
| 71 | + { |
| 72 | + "type": "section", |
| 73 | + "fields": [ |
| 74 | + { |
| 75 | + "type": "mrkdwn", |
| 76 | + "text": "*Repository:*\n<https://github.com/${{ github.repository }}|${{ github.repository }}>" |
| 77 | + }, |
| 78 | + { |
| 79 | + "type": "mrkdwn", |
| 80 | + "text": "*Workflow:*\n${{ github.workflow }}" |
| 81 | + }, |
| 82 | + { |
| 83 | + "type": "mrkdwn", |
| 84 | + "text": "*Branch:*\n\`${{ github.ref_name }}\`" |
| 85 | + }, |
| 86 | + { |
| 87 | + "type": "mrkdwn", |
| 88 | + "text": "*Triggered by:*\n${{ github.actor }}" |
| 89 | + } |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "type": "section", |
| 94 | + "text": { |
| 95 | + "type": "mrkdwn", |
| 96 | + "text": "*Commit:*\n<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|\`${GITHUB_SHA:0:7}\`> - ${{ github.event.head_commit.message }}${VERSION_TEXT}${PACKAGE_TEXT}" |
| 97 | + } |
| 98 | + }, |
| 99 | + { |
| 100 | + "type": "actions", |
| 101 | + "elements": [ |
| 102 | + { |
| 103 | + "type": "button", |
| 104 | + "text": { |
| 105 | + "type": "plain_text", |
| 106 | + "text": "View Workflow Run" |
| 107 | + }, |
| 108 | + "url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 109 | + }, |
| 110 | + { |
| 111 | + "type": "button", |
| 112 | + "text": { |
| 113 | + "type": "plain_text", |
| 114 | + "text": "View Commit" |
| 115 | + }, |
| 116 | + "url": "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" |
| 117 | + } |
| 118 | + ] |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | + EOF |
| 123 | + ) |
| 124 | +
|
| 125 | + # Send to Slack |
| 126 | + curl -X POST "${{ secrets.SLACK_CLIENT_LIBS_WEBHOOK }}" \ |
| 127 | + -H "Content-Type: application/json" \ |
| 128 | + -d "$PAYLOAD" |
| 129 | +
|
| 130 | + echo "Slack notification sent successfully" |
0 commit comments