-
Notifications
You must be signed in to change notification settings - Fork 19
107 lines (97 loc) · 4.73 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: PR Validation and Notifications
on:
pull_request:
types: [opened, ready_for_review, review_requested, reopened, closed, synchronize]
pull_request_review:
types: [submitted]
jobs:
log_info:
runs-on: ubuntu-latest
steps:
- name: Log PR Info
run: |
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
echo "PR Number: ${{ github.event.pull_request.number }}"
echo "Action: ${{ github.event.review.state }}"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
echo "PR Number: ${{ github.event.number }}"
echo "Action: ${{ github.event.action }}"
else
echo "Unhandled event type: ${{ github.event_name }}"
validate_and_notify:
runs-on: ubuntu-latest
name: Validate JSON and Notify on Telegram
steps:
- uses: actions/checkout@v4
name: Checkout Code
- name: Check Required Files in Subfolders
id: check_files
run: |
missing_files=false
error_message="Missing required files: "
# Check each subfolder for info.json, logo.png, and metadata.json
for dir in tokens/psp22/*; do
if [ ! -d "$dir" ]; then continue; fi # Skip if not a directory
echo "Checking directory: $dir"
if [ ! -f "$dir/info.json" ]; then
missing_files=true
error_message="${error_message}info.json is missing in $dir "
fi
if [ ! -f "$dir/logo.png" ]; then
missing_files=true
error_message="${error_message}logo.png is missing in $dir "
fi
if [ ! -f "$dir/metadata.json" ]; then
missing_files=true
error_message="${error_message}metadata.json is missing in $dir "
fi
done
if [ "$missing_files" = true ]; then
echo "$error_message"
exit 1
fi
- name: JSON/YAML Validation
uses: GrantBirki/json-yaml-validate@v2.7.1
with:
comment: "true" # This will post a comment if the validation fails
- name: Prepare Notification Message
if: success() # This will proceed only if the previous validation step was successful
run: |
message=""
pr_link="${{ github.event.pull_request.html_url }}"
if [ "${{ github.event_name }}" == "pull_request" ]; then
if [ "${{ github.event.action }}" == "opened" ]; then
message="🚀 New PR created: #${{ github.event.pull_request.number }} by ${{ github.event.pull_request.user.login }} - $pr_link"
elif [ "${{ github.event.action }}" == "ready_for_review" ]; then
message="📝 PR is ready for review: #${{ github.event.pull_request.number }} - $pr_link"
elif [ "${{ github.event.action }}" == "reopened" ]; then
message="🔄 PR reopened: #${{ github.event.pull_request.number }} - $pr_link"
elif [ "${{ github.event.action }}" == "closed" ] && [ "${{ github.event.pull_request.merged }}" == "true" ]; then
message="✅ PR merged: #${{ github.event.pull_request.number }} - $pr_link"
elif [ "${{ github.event.action }}" == "closed" ] && [ "${{ github.event.pull_request.merged }}" == "false" ]; then
message="❌ PR closed without merging: #${{ github.event.pull_request.number }} - $pr_link"
fi
elif [ "${{ github.event_name }}" == "pull_request_review" ] && [ "${{ github.event.review.state }}" == "approved" ]; then
message="👍 PR approved by ${{ github.event.review.user.login }}: #${{ github.event.pull_request.number }} - $pr_link"
fi
if [ -z "$message" ]; then
echo "No relevant action taken, skipping notification."
exit 0
fi
echo "TG_SENDER_PAYLOAD_MESSAGE=$message" >> $GITHUB_ENV
- name: Send Notification to Telegram
if: env.TG_SENDER_PAYLOAD_MESSAGE != '' && success()
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.BOTTOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.CHATID }}
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"chat_id\": \"$TELEGRAM_CHAT_ID\", \"text\": \"${{ env.TG_SENDER_PAYLOAD_MESSAGE }}\"}" \
"https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage"
# if: env.TG_SENDER_PAYLOAD_MESSAGE != '' && success()
# run: |
# curl -X POST \
# -H "Content-Type: application/json" \
# -d '{"chat_id": "${{ secrets.CHATID }}", "text": "${{ env.TG_SENDER_PAYLOAD_MESSAGE }}"}' \
# "https://api.telegram.org/bot${{ secrets.BotToken }}/sendMessage"