Skip to content

Commit

Permalink
adding script to print msg to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
fluong6 committed Apr 19, 2024
1 parent c5004fa commit 32c76eb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .yamato/_triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pull_request_trigger:
# Android
- .yamato/mobile-build-and-run.yml#mobile_test_android_{{ project.name }}_{{ project.test_editors.first }}
{% endfor -%}
- .yamato/print_message_slack_channel.yml
triggers:
cancel_old_ci: true
pull_requests:
Expand Down
27 changes: 27 additions & 0 deletions .yamato/print_message_slack_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
import json

def send_slack_message(webhook_url, message):
# Define the payload to be sent to Slack
payload = {
"text": message
}

# Convert the payload to JSON
payload_json = json.dumps(payload)

# Send the HTTP POST request to Slack webhook URL
response = requests.post(webhook_url, data=payload_json)

# Check if the request was successful
if response.status_code == 200:
print("Message sent successfully to Slack channel!")
else:
print(f"Failed to send message to Slack. Status code: {response.status_code}")

# Set your Slack webhook URL and message
slack_webhook_url = "https://app.slack.com/client/E016WLPF0G6/C070FP6HJ2C?_gl=1*177f49f*_gcl_au*MTU2MTM4OTc3OC4xNzEzMTg3MTQx"
message_to_send = "Hello from Python script!"

# Call the function to send the message
send_slack_message(slack_webhook_url, message_to_send)
30 changes: 30 additions & 0 deletions .yamato/print_message_slack_channel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
print_slack_message:
name: ⚡ Print Slack Message ⚡
agent:
type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.large
commands:
- command: |-
sudo apt install -y python3-pip
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt -y update
sudo apt -y install gh
timeout: 5
retries: 5
- command: pip install unity-downloader-cli --upgrade --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
- command: npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- command: unity-downloader-cli -u trunk -c editor --wait --fast
- command: upm-ci package test -u .Editor --enable-code-coverage --code-coverage-options "generateAdditionalMetrics;generateHtmlReport;assemblyFilters:{% for assembly in code_coverage_assemblies -%}+{{ assembly }},{% endfor -%};" --extra-utr-arg=--coverage-results-path=$YAMATO_SOURCE_DIR/upm-ci~/test-results/CoverageResults
timeout: 5
retries: 5
- command: |-
echo # Print Slack Message
python .yamato/print_message_slack_channel.py
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/package-pack.yml#pack

0 comments on commit 32c76eb

Please sign in to comment.