Sync ads.txt nightly #147
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 # Use the same token for pushing | |
- name: Fetch latest ads.txt | |
run: | | |
curl -sS -o /tmp/remote_ads.txt "https://monu.delivery/adstxt/e/4/500442-526a-41af-9981-22db9286cd37.txt" | |
- name: Remove comments and process ads.txt | |
run: | | |
# Create a cleaned version with comments removed | |
grep -v "^#" /tmp/remote_ads.txt > /tmp/cleaned_ads.txt | |
# Compare the cleaned file with existing ads.txt | |
if [ -f static/ads.txt ]; then | |
# Create a cleaned version of the existing file for comparison | |
grep -v "^#" static/ads.txt > /tmp/existing_cleaned.txt | |
if ! cmp -s /tmp/cleaned_ads.txt /tmp/existing_cleaned.txt; then | |
# Only copy the cleaned version (without comments) | |
cp /tmp/cleaned_ads.txt static/ads.txt | |
echo "UPDATED=true" >> $GITHUB_ENV | |
fi | |
else | |
# If ads.txt doesn't exist yet, create it from the cleaned version | |
cp /tmp/cleaned_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 |