ravsamhq / notify-slack-action

🔔 Send a Slack Notification from Github Actions regarding failure, warnings, or even success.
https://ravsam.in/blog/send-slack-notification-when-github-actions-fails/
MIT License
173 stars 57 forks source link

Action is incorrectly detecting success and not sending notification #111

Open ylhan opened 1 year ago

ylhan commented 1 year ago

Screenshot 2023-07-20 at 4 16 26 PM

You can see here that the previous steps failed however notify-slack-action's status is set to success which causes it not to alert since I have notify-when failure set.

Here's my custom action:

name: "Safe Amazon ECS Deploy Task Definition"
description: 'Deploy an Amazon ECS task definition "safely" (verify that the deployment was not rolled back)'
inputs:
  service-name:
    description: "The name of the service being deployed"
    required: true
    type: string
  task-definition:
    description: "The task definition to deploy"
    required: true
    type: string
  cluster:
    description: "The cluster to deploy to"
    required: true
    type: string

runs:
  using: "composite"
  steps:
    - name: Deploy Amazon ECS task definition
      uses: aws-actions/amazon-ecs-deploy-task-definition@v1
      id: ecs-deploy
      with:
        task-definition: ${{ inputs.task-definition }}
        service: ${{ inputs.service-name }}
        cluster: ${{ inputs.cluster }}
        wait-for-service-stability: true
    - name: Check if deployment was successful
      id: check-deployment
      if: always()
      run: |
        CURRENT_TASK_DEF_ARN=$(aws ecs describe-services --cluster ${{ inputs.cluster }} --services ${{ inputs.service-name }} --query services[0].deployments[0].taskDefinition | jq -r ".")
        NEW_TASK_DEF_ARN=${{ steps.ecs-deploy.outputs.task-definition-arn }}
        echo "Current task arn: $CURRENT_TASK_DEF_ARN"
        echo "New task arn: $NEW_TASK_DEF_ARN"
        if [ "$CURRENT_TASK_DEF_ARN" != "$NEW_TASK_DEF_ARN" ]; then
          echo "Deployment failed."
          exit 1
        fi
      shell: bash
    - name: Report Status
      if: always()
      uses: ravsamhq/notify-slack-action@v1
      with:
        status: ${{ job.status }}
        notification_title: "{workflow} has {status_message}"
        message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> | <{run_url}|View Run>"
        footer: "Linked Repo <{repo_url}|{repo}>"
        # Only alert on failure to prevent spamming the channel
        notify_when: "failure"
ravsam-bot[bot] commented 1 year ago

Hello and welcome to RavSam :purple_heart:. Thanks for opening your first issue. I will assign one of our team members to take a look at the problem you have raised. Make sure to include as much information as possible to help our team diagnose the issue and solve it quickly.

If the problem is related to a security concern, then please delete this issue and send us an email at info@ravsam.in.