Sync ads.txt nightly #176
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 | |
| - 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 first comment and add custom timestamp | |
| run: | | |
| # 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 | |
| # 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 |