Skip to content

PR Validation and Notifications #127

PR Validation and Notifications

PR Validation and Notifications #127

Workflow file for this run

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: |
echo "PR Number: ${{ github.event.number }}"
echo "Action: ${{ github.event.action }}"
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()
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"