Files
providers/.github/workflows/check-urls.yml
2025-09-23 15:58:00 +05:30

101 lines
3.2 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 checker and capture its output
node .github/scripts/url-checker.js > url_changes.txt
# Check if the script generated any output about changes
if [ -s url_changes.txt ]; then
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
# Read file content into a variable with proper escaping
CHANGES_CONTENT=$(cat url_changes.txt)
# Use environment file for multiline content
echo 'CHANGES_CONTENT<<EOF' >> $GITHUB_ENV
echo "$CHANGES_CONTENT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
else
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
fi
- name: Commit changes if any
id: commit_changes
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: |
# Verify webhook URL is available
if [ -z "$DISCORD_WEBHOOK" ]; then
echo "Error: DISCORD_WEBHOOK secret is not set. Skipping notification."
exit 0
fi
# Create a temporary JSON file for the payload
cat > discord_payload.json << EOL
{
"embeds": [
{
"title": "Provider URLs Updated",
"description": "${{ env.CHANGES_CONTENT }}",
"color": 3066993,
"footer": {
"text": "Updated on $(date +"%Y-%m-%d %H:%M:%S UTC")"
}
}
]
}
EOL
# Send the webhook
curl -s -H "Content-Type: application/json" -d @discord_payload.json "$DISCORD_WEBHOOK"
# Check curl status
if [ $? -eq 0 ]; then
echo "Discord notification sent successfully!"
else
echo "Failed to send Discord notification."
fi