name: SlackNotify
description: 'Notifies slack of the success or failure of the suite'
inputs:
  cluster_name:
    description: "Name of the cluster"
    required: false
  suite:
    description: "Suite that's running"
    required: true
  url:
    description: "Webhook URL to send the Slack notification to"
    required: true
  git_ref:
    description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release"
  workflow_trigger:
    description: "Workflow trigger for this run"
runs:
  using: "composite"
  steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      with:
        ref: ${{ inputs.git_ref }}
    - id: get-run-name
      shell: bash
      env:
        SUITE: ${{ inputs.suite }}
        WORKFLOW: ${{ inputs.workflow_trigger }}
      run: |
        if [[ ${{ github.event_name }} == "schedule" && "$WORKFLOW" == 'private_cluster' ]]; then
          RUN_NAME="privateCluster-periodic"
        elif [[ ${{ github.event_name }} == "schedule" && "$WORKFLOW" == 'soak' ]]; then
          RUN_NAME="soak-periodic"
        elif [[ ${{ github.event_name }} == "schedule" ]]; then
          RUN_NAME="$SUITE-periodic"
        else
          RUN_NAME="$SUITE-${GITHUB_SHA::7}"
        fi

        # Convert the RUN_NAME to all lowercase
        echo RUN_NAME=${RUN_NAME,,} >> $GITHUB_OUTPUT
    - uses: ./.github/actions/e2e/slack/send-message
      if: ${{ job.status == 'success' }}
      with:
        url: ${{ inputs.url }}
        message: ":white_check_mark: ${{ steps.get-run-name.outputs.RUN_NAME }} (https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
    - uses: ./.github/actions/e2e/slack/send-message
      if: ${{ job.status == 'failure' }}
      with:
        url: ${{ inputs.url }}
        message: ":x: ${{ steps.get-run-name.outputs.RUN_NAME }} (https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
