# Notify Slack Action

A GitHub Action that sends notifications to Slack when CI/CD workflows fail. This action automatically includes commit information, workflow details, and links back to the GitHub workflow run.

<img width="660" height="159" alt="Screenshot 2025-11-05 at 16 23 02" src="https://github.com/user-attachments/assets/3ec4f509-8a4a-4cec-9733-69bf3370b7d4" />

## Prerequisites

1. **Organization-level secrets** (already configured at `suno-ai` organization level):

   - `SUNO_CI_SLACK_BOT_TOKEN` - Slack bot OAuth token
   - `SUNO_CI_BOT_GH_TOKEN` - GitHub token for API access

2. **Slack channel setup**:

   - Invite `Suno CI Bot` to your Slack channel
   - Get the Slack channel ID
   - Right-click on the channel name
   - Select "Copy link"
   - The channel ID is the last part of the URL (e.g., `C01234ABCDE`)

3. **Repository configuration**:
   - Add repository variable `SLACK_CHANNEL_ID` with your channel ID

## Usage

Add this job to your workflow file to notify on failures:

```yaml
jobs:
  # Your existing jobs (lint, build, test, etc.)
  lint:
    runs-on: ubuntu-latest
    steps:
      # ... your lint steps

  build:
    runs-on: ubuntu-latest
    steps:
      # ... your build steps

  test:
    runs-on: ubuntu-latest
    steps:
      # ... your test steps

  # Notification job - runs if any previous job fails
  notify-failure:
    if: failure() && github.event_name == 'push' && github.ref_name == 'main'
    needs: [lint, build, test]
    runs-on: ubuntu-latest
    steps:
      - name: Report failure to Slack
        uses: suno-ai/ci/.github/actions/notify-slack@main
        with:
          slack_bot_token: ${{ secrets.SUNO_CI_SLACK_BOT_TOKEN }}
          slack_channel_id: ${{ vars.SLACK_CHANNEL_ID }}
          github_token: ${{ secrets.SUNO_CI_BOT_GH_TOKEN }}
```

### Customizing Notification Conditions

You can customize when notifications are sent by modifying the `if` condition:

```yaml
# Only notify on main branch pushes
if: failure() && github.event_name == 'push' && github.ref_name == 'main'

# Notify on any branch push
if: failure() && github.event_name == 'push'

# Notify on both pushes and pull requests
if: failure() && (github.event_name == 'push' || github.event_name == 'pull_request')

# Notify on specific branches
if: failure() && github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'develop')
```

### Multiple Notification Jobs

You can set up different notifications for different job groups:

```yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      # ... lint steps

  unit-tests:
    runs-on: ubuntu-latest
    steps:
      # ... unit test steps

  integration-tests:
    runs-on: ubuntu-latest
    steps:
      # ... integration test steps

  # Notify if lint or unit tests fail
  notify-quick-checks-failure:
    if: failure() && github.event_name == 'push' && github.ref_name == 'main'
    needs: [lint, unit-tests]
    runs-on: ubuntu-latest
    steps:
      - name: Report failure to Slack
        uses: suno-ai/ci/.github/actions/notify-slack@main
        with:
          slack_bot_token: ${{ secrets.SUNO_CI_SLACK_BOT_TOKEN }}
          slack_channel_id: ${{ vars.SLACK_CHANNEL_ID_QUICK_CHECKS }}
          github_token: ${{ secrets.SUNO_CI_BOT_GH_TOKEN }}

  # Notify if integration tests fail (different channel)
  notify-integration-failure:
    if: failure() && github.event_name == 'push' && github.ref_name == 'main'
    needs: [integration-tests]
    runs-on: ubuntu-latest
    steps:
      - name: Report failure to Slack
        uses: suno-ai/ci/.github/actions/notify-slack@main
        with:
          slack_bot_token: ${{ secrets.SUNO_CI_SLACK_BOT_TOKEN }}
          slack_channel_id: ${{ vars.SLACK_CHANNEL_ID_INTEGRATION }}
          github_token: ${{ secrets.SUNO_CI_BOT_GH_TOKEN }}
```

## Examples

### Basic Setup for Main Branch Only

```yaml
name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run tests
        run: npm test

  notify-failure:
    if: failure() && github.event_name == 'push' && github.ref_name == 'main'
    needs: [test]
    runs-on: ubuntu-latest
    steps:
      - name: Report failure to Slack
        uses: suno-ai/ci/.github/actions/notify-slack@main
        with:
          slack_bot_token: ${{ secrets.SUNO_CI_SLACK_BOT_TOKEN }}
          slack_channel_id: ${{ vars.SLACK_CHANNEL_ID }}
          github_token: ${{ secrets.SUNO_CI_BOT_GH_TOKEN }}
```

### Multi-Job Pipeline with Single Notification

```yaml
name: Full Pipeline

on:
  push:
    branches: [main, develop]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run build

  deploy:
    needs: [lint, test, build]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run deploy

  notify-failure:
    if: failure() && github.event_name == 'push'
    needs: [lint, test, build, deploy]
    runs-on: ubuntu-latest
    steps:
      - name: Report failure to Slack
        uses: suno-ai/ci/.github/actions/notify-slack@main
        with:
          slack_bot_token: ${{ secrets.SUNO_CI_SLACK_BOT_TOKEN }}
          slack_channel_id: ${{ vars.SLACK_CHANNEL_ID }}
          github_token: ${{ secrets.SUNO_CI_BOT_GH_TOKEN }}
```
