|
| 1 | +name: Build adblock rules files |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: 0 */6 * * * |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Setup Go 1.x |
| 13 | + uses: actions/setup-go@v3 |
| 14 | + with: |
| 15 | + go-version: "^1.14" |
| 16 | + |
| 17 | + - name: Set $GOPATH and more variables |
| 18 | + run: | |
| 19 | + echo "RELEASE_NAME=Released on $(date -d "8 hour" -u +%Y%m%d%H%M)" >> $GITHUB_ENV |
| 20 | + echo "TAG_NAME=$(date -d "8 hour" -u +%Y%m%d%H%M)" >> $GITHUB_ENV |
| 21 | + echo "MODIFIED_TIME=$(date -d "8 hour" -u "+%Y年%m月%d日 %H:%M")" >> $GITHUB_ENV |
| 22 | + echo "EASYLIST_URL=https://easylist-downloads.adblockplus.org/easylist.txt" >> $GITHUB_ENV |
| 23 | + echo "EASYLISTCHINA_URL=https://easylist-downloads.adblockplus.org/easylistchina.txt" >> $GITHUB_ENV |
| 24 | + echo "EASYPRIVACY_URL=https://easylist-downloads.adblockplus.org/easyprivacy.txt" >> $GITHUB_ENV |
| 25 | + echo "CJXLIST_URL=https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt" >> $GITHUB_ENV |
| 26 | + echo "CJX_ANNOYANCE_URL=https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjx-annoyance.txt" >> $GITHUB_ENV |
| 27 | + echo "ANTI_ADBLOCK_KILLER_FILTERS_URL=https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt" >> $GITHUB_ENV |
| 28 | + echo "ANTIADBLOCKFILTERS_URL=https://easylist-downloads.adblockplus.org/antiadblockfilters.txt" >> $GITHUB_ENV |
| 29 | + echo "ABP_FILTERS_ANTI_CV_URL=https://easylist-downloads.adblockplus.org/abp-filters-anti-cv.txt" >> $GITHUB_ENV |
| 30 | + echo "XINGGSF_MV_URL=https://raw.githubusercontent.com/xinggsf/Adblock-Plus-Rule/master/mv.txt" >> $GITHUB_ENV |
| 31 | + echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV |
| 32 | + echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH |
| 33 | + shell: bash |
| 34 | + |
| 35 | + - name: Initialize Git |
| 36 | + run: | |
| 37 | + git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 38 | + git config --global user.name github-actions[bot] |
| 39 | + |
| 40 | + - name: Checkout the "master" branch |
| 41 | + uses: actions/checkout@v3 |
| 42 | + with: |
| 43 | + ref: master |
| 44 | + |
| 45 | + - name: Get every files |
| 46 | + id: download |
| 47 | + run: | |
| 48 | + mkdir -p ./download/ |
| 49 | + cd ./download |
| 50 | + curl -sSL $EASYLIST_URL | sed -e '/^! /d' -e '1c ! EasyList' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./easylist.txt |
| 51 | + curl -sSL $EASYLISTCHINA_URL | sed -e '/^! /d' -e '1c ! EasyList China' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./easylistchina.txt |
| 52 | + curl -sSL $EASYPRIVACY_URL | sed -e '/^! /d' -e '1c ! EasyPrivacy' -e '/^!$/d' > ./easyprivacy.txt |
| 53 | + curl -sSL $CJXLIST_URL | sed -e '/^! /d' -e '1c ! EasyList Lite' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./cjxlist.txt |
| 54 | + curl -sSL $CJX_ANNOYANCE_URL | sed -e '/^! /d' -e "1c ! CJX's Annoyance List" -e '/^!$/d' -e '/The End/d' -e '/^$/d' | sed '/热门话题/,+1d' > ./cjx-annoyance.txt |
| 55 | + sed -i '/!#include cjx-ublock.txt/c !#include https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjx-ublock.txt' ./cjx-annoyance.txt |
| 56 | + curl -sSL $XINGGSF_MV_URL | sed '/禁止站内新开窗/,+2d' | sed -e '/^! /d' -e '1c ! 乘风 视频广告过滤规则' -e '/^!$/d' -e '/^$/d' > ./xinggsf-mv.txt |
| 57 | + curl -sSL $ANTIADBLOCKFILTERS_URL | sed -e '1c ! Adblock Warning Removal List' -e '/^! Checksum/,/! Please check our guidelines/d' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./antiadblockfilters.txt |
| 58 | + curl -sSL $ABP_FILTERS_ANTI_CV_URL | sed -e '1c ! abp-filters-anti-cv' -e '/^! Checksum/,/adblockplus.org/d' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./abp-filters-anti-cv.txt |
| 59 | + curl -sSL $ANTI_ADBLOCK_KILLER_FILTERS_URL | sed -e '1c ! AakList (Anti-Adblock Killer)' -e '/^! Title/,/^! RegExpVisualizer/d' -e '/^!$/d' -e '/The End/d' -e '/^$/d' > ./anti-adblock-killer-filters.txt |
| 60 | + for i in $(ls *.txt); do |
| 61 | + if [[ `cat $i |wc -l` -eq 0 ]]; then |
| 62 | + echo "status=failed">> $GITHUB_OUTPUT |
| 63 | + break |
| 64 | + else |
| 65 | + echo "status=success">> $GITHUB_OUTPUT |
| 66 | + echo "" >> $i |
| 67 | + fi |
| 68 | + done |
| 69 | +
|
| 70 | + - name: Generate adblock files |
| 71 | + if: steps.download.outputs.status == 'success' |
| 72 | + run: | |
| 73 | + mkdir -p ./new/ |
| 74 | + cd ./download |
| 75 | + cat ../mod/GeneralBlock.txt ../mod/TiebaBlock.txt easylist.txt easylistchina.txt easyprivacy.txt cjx-annoyance.txt xinggsf-mv.txt > ../new/ad-pc.txt |
| 76 | + cat ../mod/GeneralBlock.txt easylist.txt easylistchina.txt easyprivacy.txt cjx-annoyance.txt > ../new/ad-mo.txt |
| 77 | + cat ../mod/GeneralBlock.txt ../mod/TiebaBlock.txt xinggsf-mv.txt easylistchina.txt cjxlist.txt cjx-annoyance.txt > ../new/ad.txt |
| 78 | + cat xinggsf-mv.txt easylistchina.txt cjxlist.txt cjx-annoyance.txt > ../new/ad2.txt |
| 79 | + cat xinggsf-mv.txt easylistchina.txt cjxlist.txt cjx-annoyance.txt easyprivacy.txt > ../new/ad3.txt |
| 80 | + cat antiadblockfilters.txt abp-filters-anti-cv.txt anti-adblock-killer-filters.txt > ../new/ad-edentw.txt |
| 81 | + for i in $(ls ../new/*.txt); do |
| 82 | + sed -i '/^$/d' $i |
| 83 | + done |
| 84 | +
|
| 85 | + - name: Diff and addChecksum |
| 86 | + id: diffResult |
| 87 | + if: steps.download.outputs.status == 'success' |
| 88 | + run: | |
| 89 | + mkdir -p ./old_no_title/ |
| 90 | + chmod +x ./mod/addChecksum.pl |
| 91 | + for i in $(ls ad*.txt); do |
| 92 | + sed '1,/^!$/d' $i > ./old_no_title/$i |
| 93 | + done |
| 94 | + diffFile="$(diff -q new/ old_no_title/ |grep -o '[a-zA-Z0-9-]\+.txt' |sort -u)" |
| 95 | + if [ -n "$diffFile" ]; then |
| 96 | + for i in $diffFile ; do |
| 97 | + titleName=$(echo "$i" |sed 's#.txt#-title.txt#') |
| 98 | + cat ./mod/$titleName ./new/$i > ./$i |
| 99 | + sed -i -e "s#201412030951#$TAG_NAME#" -e "s#201412030952#$MODIFIED_TIME#" ./$i |
| 100 | + perl ./mod/addChecksum.pl ./$i |
| 101 | + echo "status=success">> $GITHUB_OUTPUT |
| 102 | + done |
| 103 | + else |
| 104 | + echo "status=failed">> $GITHUB_OUTPUT |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Deliver download Dir |
| 108 | + uses: actions/upload-artifact@v3 |
| 109 | + if: steps.download.outputs.status == 'failed' |
| 110 | + with: |
| 111 | + name: AllFiles |
| 112 | + path: | |
| 113 | + ./download/ |
| 114 | +
|
| 115 | + - name: Deliver new and old_no_title Di |
| 116 | + uses: actions/upload-artifact@v3 |
| 117 | + if: steps.diffResult.outputs.status == 'failed' |
| 118 | + with: |
| 119 | + name: AllFiles |
| 120 | + path: | |
| 121 | + * |
| 122 | + !./.git/ |
| 123 | +
|
| 124 | + - name: Git push assets to github & coding |
| 125 | + if: steps.diffResult.outputs.status == 'success' |
| 126 | + run: | |
| 127 | + rm -rf .git/ download/ new/ old_no_title/ |
| 128 | + git init |
| 129 | + git checkout -b master |
| 130 | + git add --all |
| 131 | + git commit -m "${{ env.RELEASE_NAME }}" |
| 132 | + git remote add origin "https://${{ github.actor }}:${{ secrets.WORKFLOW_TOKEN }}@github.com/${{ github.repository }}" |
| 133 | + #git remote set-url --add origin "https://${{ secrets.CODING_ACCOUNT }}:${{ secrets.CODING_PASSWORD }}@e.coding.net/${{ secrets.CODING_NAME }}/list.git" |
| 134 | + git push -u -f origin master |
| 135 | +
|
| 136 | + - name: Release and Upload Assets |
| 137 | + if: steps.diffResult.outputs.status == 'success' |
| 138 | + uses: ncipollo/release-action@v1 |
| 139 | + with: |
| 140 | + name: adblock |
| 141 | + body: ${{ env.RELEASE_NAME }} |
| 142 | + tag: adblock |
| 143 | + makeLatest: true |
| 144 | + allowUpdates: true |
| 145 | + removeArtifacts: true |
| 146 | + artifacts: | |
| 147 | + *.txt |
0 commit comments