Update check-urls.yml

This commit is contained in:
8man
2025-09-23 15:58:00 +05:30
committed by GitHub
parent cd66160d9b
commit 0a8eb75a4e

View File

@@ -28,20 +28,22 @@ jobs:
- name: Run URL checker - name: Run URL checker
id: url_checker id: url_checker
run: | run: |
# Run the checker and save output to a file # Run the checker and capture its output
node .github/scripts/url-checker.js > url_changes.txt node .github/scripts/url-checker.js > url_changes.txt
# Check if the script generated any output about changes # Check if the script generated any output about changes
if [ -s url_changes.txt ]; then if [ -s url_changes.txt ]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
echo "changes_content<<EOF" >> $GITHUB_OUTPUT # Read file content into a variable with proper escaping
cat url_changes.txt >> $GITHUB_OUTPUT CHANGES_CONTENT=$(cat url_changes.txt)
echo "EOF" >> $GITHUB_OUTPUT # Use environment file for multiline content
echo 'CHANGES_CONTENT<<EOF' >> $GITHUB_ENV
echo "$CHANGES_CONTENT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
else else
echo "changes_detected=false" >> $GITHUB_OUTPUT echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
fi fi
# Better approach using git status
- name: Commit changes if any - name: Commit changes if any
id: commit_changes id: commit_changes
run: | run: |
@@ -49,35 +51,50 @@ jobs:
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
git add modflix.json git add modflix.json
# Check if there are changes using git status (more reliable) # Check if there are changes using git status
if [[ $(git status --porcelain modflix.json) ]]; then if [[ $(git status --porcelain modflix.json) ]]; then
echo "Found changes in modflix.json, committing..." echo "Found changes in modflix.json, committing..."
git commit -m "Update provider URLs [skip ci]" git commit -m "Update provider URLs [skip ci]"
git push git push
echo "changes_made=true" >> $GITHUB_OUTPUT echo "CHANGES_MADE=true" >> $GITHUB_ENV
else else
echo "No changes detected in modflix.json" echo "No changes detected in modflix.json"
echo "changes_made=false" >> $GITHUB_OUTPUT echo "CHANGES_MADE=false" >> $GITHUB_ENV
fi fi
- name: Send Discord notification - name: Send Discord notification
if: steps.commit_changes.outputs.changes_made == 'true' if: env.CHANGES_MADE == 'true' && env.CHANGES_DETECTED == 'true'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: | run: |
CHANGES="${{ steps.url_checker.outputs.changes_content }}" # Verify webhook URL is available
if [ -z "$DISCORD_WEBHOOK" ]; then
if [ -z "$CHANGES" ]; then echo "Error: DISCORD_WEBHOOK secret is not set. Skipping notification."
CHANGES="Provider URLs have been updated but no specific details are available." exit 0
fi fi
curl -H "Content-Type: application/json" \ # Create a temporary JSON file for the payload
-d '{ cat > discord_payload.json << EOL
"embeds": [{ {
"embeds": [
{
"title": "Provider URLs Updated", "title": "Provider URLs Updated",
"description": "'"${CHANGES}"'", "description": "${{ env.CHANGES_CONTENT }}",
"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")"
} }
}] }
}' \ ]
${{ secrets.DISCORD_WEBHOOK }} }
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