Files
providers/.github/workflows/check-urls.yml
8man 90f9593159 Enhance URL checker workflow with better logging
Refactor URL checker workflow to improve logging and notification formatting.
2025-09-23 16:22:09 +05:30

107 lines
3.5 KiB
YAML

name: Check Provider URLs
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
workflow_dispatch: # Allow manual triggering
# Set explicit permissions for the GITHUB_TOKEN
permissions:
contents: write
jobs:
check-urls:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install axios
- name: Run URL checker
id: url_checker
run: |
# Run the URL checker and save output
node .github/scripts/url-checker.js > checker_output.log 2>&1
# Check if there are updated providers
if grep -q "### UPDATED_PROVIDERS_START ###" checker_output.log; then
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
# Extract only the updated provider lines between the markers
sed -n '/### UPDATED_PROVIDERS_START ###/,/### UPDATED_PROVIDERS_END ###/p' checker_output.log |
grep -v "###" > updated_providers.txt
else
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
fi
- name: Commit changes if any
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add modflix.json
# Check if there are changes using git status
if [[ $(git status --porcelain modflix.json) ]]; then
echo "Found changes in modflix.json, committing..."
git commit -m "Update provider URLs [skip ci]"
git push
echo "CHANGES_MADE=true" >> $GITHUB_ENV
else
echo "No changes detected in modflix.json"
echo "CHANGES_MADE=false" >> $GITHUB_ENV
fi
- name: Send Discord notification
if: env.CHANGES_MADE == 'true' && env.CHANGES_DETECTED == 'true'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
if [ -z "$DISCORD_WEBHOOK" ]; then
echo "Error: DISCORD_WEBHOOK secret is not set. Skipping notification."
exit 0
fi
# Count updated providers
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": [
{
"title": "Provider URLs Updated",
"description": $(echo -n "$DESCRIPTION" | jq -Rs .),
"color": 3066993,
"footer": {
"text": "Updated on $(date +"%Y-%m-%d %H:%M:%S UTC")"
}
}
]
}
EOF
)
# Send the webhook
curl -s -X POST \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$DISCORD_WEBHOOK"