@@ -12,30 +12,34 @@ jobs:
1212 - name : Checkout repository
1313 uses : actions/checkout@v4
1414 with :
15- persist-credentials : false # Use the same token for pushing
15+ persist-credentials : false
1616
1717 - name : Fetch latest ads.txt
1818 run : |
1919 curl -sS -o /tmp/remote_ads.txt "https://monu.delivery/adstxt/e/4/500442-526a-41af-9981-22db9286cd37.txt"
2020
21- - name : Remove comments and process ads.txt
21+ - name : Remove first comment and add custom timestamp
2222 run : |
23- # Create a cleaned version with comments removed
24- grep -v "^#" /tmp/remote_ads.txt > /tmp/cleaned_ads.txt
25-
26- # Compare the cleaned file with existing ads.txt
23+ # Remove only the first comment line (timestamp) from remote_ads.txt
24+ awk 'NR==1 && /^#/ {next} {print}' /tmp/remote_ads.txt > /tmp/cleaned_ads.txt
25+
26+ # Add our own timestamp header
27+ timestamp=$(date +"%Y/%m/%d %H:%M:%S.%6N")
28+ {
29+ echo "# Ads.txt last updated on: $timestamp by MONUMETRIC/CCPorted"
30+ cat /tmp/cleaned_ads.txt
31+ } > /tmp/final_ads.txt
32+
33+ # Compare the file (excluding the timestamp line) with existing ads.txt
2734 if [ -f static/ads.txt ]; then
28- # Create a cleaned version of the existing file for comparison
29- grep -v "^#" static/ads.txt > /tmp/existing_cleaned.txt
30-
31- if ! cmp -s /tmp/cleaned_ads.txt /tmp/existing_cleaned.txt; then
32- # Only copy the cleaned version (without comments)
33- cp /tmp/cleaned_ads.txt static/ads.txt
35+ tail -n +2 /tmp/final_ads.txt > /tmp/new_body.txt
36+ tail -n +2 static/ads.txt > /tmp/existing_body.txt
37+ if ! cmp -s /tmp/new_body.txt /tmp/existing_body.txt; then
38+ cp /tmp/final_ads.txt static/ads.txt
3439 echo "UPDATED=true" >> $GITHUB_ENV
3540 fi
3641 else
37- # If ads.txt doesn't exist yet, create it from the cleaned version
38- cp /tmp/cleaned_ads.txt static/ads.txt
42+ cp /tmp/final_ads.txt static/ads.txt
3943 echo "UPDATED=true" >> $GITHUB_ENV
4044 fi
4145
0 commit comments