Enhance URL checker workflow with better logging

Refactor URL checker workflow to improve logging and notification formatting.
This commit is contained in:
8man
2025-09-23 16:22:09 +05:30
committed by GitHub
parent 08298632e6
commit 90f9593159

View File

@@ -28,24 +28,21 @@ jobs:
- name: Run URL checker - name: Run URL checker
id: url_checker id: url_checker
run: | run: |
# Run the checker and capture its output # Run the URL checker and save output
node .github/scripts/url-checker.js > url_changes.txt node .github/scripts/url-checker.js > checker_output.log 2>&1
# Check if the script generated any output about changes # Check if there are updated providers
if [ -s url_changes.txt ]; then if grep -q "### UPDATED_PROVIDERS_START ###" checker_output.log; then
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
# Read file content into a variable with proper escaping
CHANGES_CONTENT=$(cat url_changes.txt) # Extract only the updated provider lines between the markers
# Use environment file for multiline content sed -n '/### UPDATED_PROVIDERS_START ###/,/### UPDATED_PROVIDERS_END ###/p' checker_output.log |
echo 'CHANGES_CONTENT<<EOF' >> $GITHUB_ENV grep -v "###" > updated_providers.txt
echo "$CHANGES_CONTENT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
else else
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
fi fi
- name: Commit changes if any - name: Commit changes if any
id: commit_changes
run: | run: |
git config --global user.name "GitHub Actions" git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
@@ -67,19 +64,31 @@ jobs:
env: env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: | run: |
# Verify webhook URL is available
if [ -z "$DISCORD_WEBHOOK" ]; then if [ -z "$DISCORD_WEBHOOK" ]; then
echo "Error: DISCORD_WEBHOOK secret is not set. Skipping notification." echo "Error: DISCORD_WEBHOOK secret is not set. Skipping notification."
exit 0 exit 0
fi fi
# Create a temporary JSON file for the payload # Count updated providers
cat > discord_payload.json << EOL PROVIDER_COUNT=$(wc -l < updated_providers.txt)
# Build a clean description with updated providers
DESCRIPTION="## 🔄 Provider URLs Updated ($PROVIDER_COUNT)\n\n"
# Process each updated provider and format nicely
while IFS='|' read -r name oldUrl newUrl; do
DESCRIPTION="${DESCRIPTION}### ${name}\n"
DESCRIPTION="${DESCRIPTION}**Old:** \`${oldUrl}\`\n"
DESCRIPTION="${DESCRIPTION}**New:** \`${newUrl}\`\n\n"
done < updated_providers.txt
# Create JSON payload with proper escaping
PAYLOAD=$(cat <<EOF
{ {
"embeds": [ "embeds": [
{ {
"title": "Provider URLs Updated", "title": "Provider URLs Updated",
"description": "${{ env.CHANGES_CONTENT }}", "description": $(echo -n "$DESCRIPTION" | jq -Rs .),
"color": 3066993, "color": 3066993,
"footer": { "footer": {
"text": "Updated on $(date +"%Y-%m-%d %H:%M:%S UTC")" "text": "Updated on $(date +"%Y-%m-%d %H:%M:%S UTC")"
@@ -87,14 +96,11 @@ jobs:
} }
] ]
} }
EOL EOF
)
# Send the webhook # Send the webhook
curl -s -H "Content-Type: application/json" -d @discord_payload.json "$DISCORD_WEBHOOK" curl -s -X POST \
-H "Content-Type: application/json" \
# Check curl status -d "$PAYLOAD" \
if [ $? -eq 0 ]; then "$DISCORD_WEBHOOK"
echo "Discord notification sent successfully!"
else
echo "Failed to send Discord notification."
fi