-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (104 loc) · 4.54 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Update CDN assets
on:
# https://unix.stackexchange.com/questions/519538/how-to-set-cron-job-for-every-5-hours
schedule:
- cron: '11 */1 * * *'
workflow_dispatch:
jobs:
publish:
name: Update assets
runs-on: ubuntu-latest
steps:
- name: Repo check
run: |
if [[ "$GITHUB_REPOSITORY_OWNER" != "dimisa-RUAdList" ]]; then
echo "This GitHub Action is meant to deliver filter lists for RUAdList."
echo "You shouldn't need to run this GitHub Action in your fork."
echo "If you do, please customize the cron expression above, and"
echo "the URLs below."
exit 1
fi
exit 0
- name: Clone RUAdListCDN
uses: actions/checkout@v3
- name: Build directory
run: |
BUILDDIR=$(mktemp -d)
echo "BUILDDIR=$BUILDDIR" >> $GITHUB_ENV
echo "Build directory is $BUILDDIR"
- name: Copy shell script from uAssets
run: |
TMPDIR="$(mktemp -d)"
git clone --depth=1 --single-branch --branch=master https://github.com/uBlockOrigin/uAssets.git "$TMPDIR"
cp -v "$TMPDIR"/tools/make-easylist.mjs ${{ env.BUILDDIR }}/
cp -v "$TMPDIR"/tools/need-patch.mjs ${{ env.BUILDDIR }}
cp -v "$TMPDIR"/tools/make-diffpatch.sh ${{ env.BUILDDIR }}
cp -v "$TMPDIR"/tools/update-diffpatches.sh ${{ env.BUILDDIR }}
- name: Time check
run: |
UPDATE_PERIOD_IN_HOURS=5
echo "CAN_DO=$(node ${{ env.BUILDDIR }}/need-patch.mjs delay="$UPDATE_PERIOD_IN_HOURS")" >> $GITHUB_ENV
- name: Generate version string
if: ${{ env.CAN_DO == 'yes' }}
run: |
TAGNAME=$(date -u "+%Y.%-m.%-d.")$(date -u "+%H*60+%M" | bc)
echo "TAGNAME=$TAGNAME" >> $GITHUB_ENV
echo "Version string is $TAGNAME"
- name: Fetch lists from easylist/ruadlist
if: ${{ env.CAN_DO == 'yes' }}
run: |
TMPDIR="$(mktemp -d)"
git clone --depth=1 --single-branch --branch=master https://github.com/easylist/ruadlist "$TMPDIR"
cp -v "$TMPDIR"/*.txt "${{ env.BUILDDIR }}"
cp -Rv "$TMPDIR"/advblock "${{ env.BUILDDIR }}"
- name: Generate ruadlist.ubo.min.txt from RuAdList-uBO.txt
if: ${{ env.CAN_DO == 'yes' }}
run: |
pushd ${{ env.BUILDDIR }}
: > ruadlist.template
echo "[uBlock Origin 1.0]" >> ruadlist.template
echo "! Title: RU AdList for uBO only" >> ruadlist.template
echo "! Expires: 4 days" >> ruadlist.template
echo "! Last modified: %timestamp%" >> ruadlist.template
echo "! Diff-Path: %diffpath%#ruadlist" >> ruadlist.template
echo "! Diff-Expires: 5 hours" >> ruadlist.template
echo "! License: https://github.com/dimisa-RUAdList/RUAdListCDN/blob/main/LICENSE" >> ruadlist.template
echo >> ruadlist.template
echo "%include ruadlist:RuAdList-uBO.txt%" >> ruadlist.template
node ./make-easylist.mjs in=ruadlist.template out=ruadlist.ubo.min.txt minify=1
popd
cp ${{ env.BUILDDIR }}/ruadlist.ubo.min.txt lists/
- name: Patch last-updated field
if: ${{ env.CAN_DO == 'yes' }}
run: |
DATE=$(date -Ru)
FILTER_LISTS=( "lists/ruadlist.ubo.min.txt" )
for FILE in "${FILTER_LISTS[@]}"; do
STAT=$(git diff --numstat $FILE | sed -r '/^1\s+1\s+/d')
if [[ -n $STAT ]]; then
sed -ir "0,/^! Last modified: /s/^\(! Last modified: \)%timestamp%/\\1$DATE/" $FILE
else
git checkout -q $FILE
fi
done
- name: Create new patch
if: ${{ env.CAN_DO == 'yes' }}
run: |
PATCHES_DIR="patches"
${{ env.BUILDDIR }}/make-diffpatch.sh "${{ env.TAGNAME }}" "$PATCHES_DIR"
- name: Update existing patches
if: ${{ env.CAN_DO == 'yes' }}
run: |
PATCHES_DIR="patches"
FILTER_FILES=$(git ls-files --exclude-standard -- lists/*.min.txt)
${{ env.BUILDDIR }}/update-diffpatches.sh "$GITHUB_REPOSITORY" "$PATCHES_DIR" "$FILTER_FILES"
- name: Commit changes, if any
if: ${{ env.CAN_DO == 'yes' }}
run: |
if [[ -z $(git diff --name-only --cached) ]]; then exit 0; fi
git config user.name "GitHub Actions: main"
git config user.email "<>"
git commit -m "Update modified CDN assets to ${{ env.TAGNAME }}"
git push origin main
git tag ${{ env.TAGNAME }}
git push origin ${{ env.TAGNAME }}