Skip to content

Sync ads.txt nightly #225

Sync ads.txt nightly

Sync ads.txt nightly #225

Workflow file for this run

name: Sync ads.txt nightly
on:
schedule:
- cron: '0 0 * * *' # Runs nightly at midnight UTC
workflow_dispatch: # Allows manual trigger
jobs:
update-ads:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Fetch Monumetric and Applixir ads.txt
run: |
# Fetch Monumetric ads.txt
curl -sS -o /tmp/remote_ads.txt "https://monu.delivery/adstxt/e/4/500442-526a-41af-9981-22db9286cd37.txt"
# Remove only the first comment line (timestamp) from remote_ads.txt
awk 'NR==1 && /^#/ {next} {print}' /tmp/remote_ads.txt > /tmp/cleaned_ads.txt
# Add our own timestamp header
timestamp=$(date +"%Y/%m/%d %H:%M:%S.%6N")
{
echo "# Ads.txt last updated on: $timestamp by MONUMETRIC/CCPorted"
cat /tmp/cleaned_ads.txt
} > /tmp/final_ads.txt
# Fetch Applixir ads.txt and append below Monumetric lines
curl -sS "https://cdn.applixir.com/ads.txt" >> /tmp/final_ads.txt
# Append additional lines from additional_lines.txt if it exists
if [ -f additional_lines.txt ]; then
cat additional_lines.txt >> /tmp/final_ads.txt
fi
# Compare the file (excluding the timestamp line) with existing ads.txt
if [ -f static/ads.txt ]; then
tail -n +2 /tmp/final_ads.txt > /tmp/new_body.txt
tail -n +2 static/ads.txt > /tmp/existing_body.txt
if ! cmp -s /tmp/new_body.txt /tmp/existing_body.txt; then
cp /tmp/final_ads.txt static/ads.txt
echo "UPDATED=true" >> $GITHUB_ENV
fi
else
cp /tmp/final_ads.txt static/ads.txt
echo "UPDATED=true" >> $GITHUB_ENV
fi
- name: Commit and push changes
if: env.UPDATED == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add static/ads.txt
git commit -m "update ads.txt"
git push https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git main