Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slack url check #7

Open
eonist opened this issue Jan 19, 2025 · 0 comments
Open

Add slack url check #7

eonist opened this issue Jan 19, 2025 · 0 comments

Comments

@eonist
Copy link
Owner

eonist commented Jan 19, 2025

name: Notify Slack

on:
workflow_call:
inputs:
num_of_languages:
description: 'Number of languages translated'
required: true
type: string
tokens_count_used:
description: 'Number of OpenAI tokens used in translation'
required: true
type: string
unit_test_success:
description: 'Unit test success flag'
required: true
type: boolean

jobs:
send_slack_notification:
runs-on: ubuntu-latest
steps:
## 1. Validate SLACK_WEBHOOK_URL by sending a test message
- name: Validate SLACK_WEBHOOK_URL
run: |
response=$(curl -X POST -H 'Content-type: application/json'
--data '{"text":":white_check_mark: Slack webhook URL validation test."}'
-o /dev/null -s -w "%{http_code}" "$SLACK_WEBHOOK_URL")
if [ "$response" -ne 200 ]; then
echo "::error::Invalid SLACK_WEBHOOK_URL. Received HTTP status code $response."
exit 1
else
echo "SLACK_WEBHOOK_URL is valid."
fi
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

  ## 2. Send notification to Slack
  - name: Send Slack notification
    uses: 8398a7/[email protected]
    with:
      status: ${{ job.status }}
      text: |
        Babel translation complete.
        Number of languages translated: ${{ inputs.num_of_languages }}
        Tokens used: ${{ inputs.tokens_count_used }} OpenAI tokens
        Testing completed: ${{ inputs.unit_test_success }}
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    if: always() # Ensure the notification is sent even if the job fails or is canceled.

send slack-channel a notification

get num_of_languages count from init params

get tokens_count_used in translation from init params

get unit_test_success bool flag from init params

send payload to slack with:

"Babel translation complete. num_of_languages was translated. tokens_count_used openAI tokens was used. Testing completed: unit_test_success"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant