-
Notifications
You must be signed in to change notification settings - Fork 1.2k
105 lines (90 loc) · 3.73 KB
/
updategeoip-cn.yaml
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
name: Update China IP list and generate BypassCN.rules and BypassCN_someip.rules
on:
workflow_dispatch:
schedule:
- cron: '0 2 */3 * *'
jobs:
build:
name: Generate BypassCN.rule
runs-on: ubuntu-latest
steps:
- name: Check out code into directory
uses: actions/checkout@v4
- name: Git config
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git fetch
shell: bash
- name: Get CIDR (Source someip) field
run: |
echo "#BypassCNandLan,绕过大陆和局域网someip,1,1,1,0,0,0," >> BypassCNandLan_someip.rules
curl https://raw.githubusercontent.com/0x2E/someip/build/cidr.txt >> BypassCNandLan_someip.rules
sed -i '2{/^$/d;}' BypassCNandLan_someip.rules # 删除源文件内第二行的空行
echo 10.0.0.0/8 >> BypassCNandLan_someip.rules
echo 172.16.0.0/12 >> BypassCNandLan_someip.rules
echo 192.168.0.0/16 >> BypassCNandLan_someip.rules
shell: bash
- name: Get CIDR field
run: |
echo "#BypassCNandLan,绕过大陆和局域网,1,1,1,0,0,0," >> BypassCNandLan.rules
curl https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt >> BypassCNandLan.rules
sed -i '2{/^$/d;}' BypassCNandLan.rules # 删除源文件内第二行的空行
echo 10.0.0.0/8 >> BypassCNandLan.rules
echo 172.16.0.0/12 >> BypassCNandLan.rules
echo 192.168.0.0/16 >> BypassCNandLan.rules
shell: bash
- name: Compare New file and Old file (Source someip)
run: |
hash1=$(sha256sum "./BypassCNandLan_someip.rules" | awk '{print $1}')
hash2=$(sha256sum "./rules/BypassCNandLan_someip.rules" | awk '{print $1}')
echo -e "hash1=$hash1\nhash2=$hash2"
if [ "$hash1" == "$hash2" ]; then
echo "Hashes match. The files are identical."
echo "Upstream not updated"
echo "STATUS_1=1" >> $GITHUB_ENV
exit 0
else
echo "Hashes do not match. The files are different."
echo "Upstream updated."
echo "STATUS_1=0" >> $GITHUB_ENV
cp ./BypassCNandLan_someip.rules ./rules/BypassCNandLan_someip.rules
git add ./rules/BypassCNandLan_someip.rules
git commit -am "Updated at $(TZ='Asia/Shanghai' date)"
fi
shell: bash
- name: Compare New file and Old file
run: |
hash1=$(sha256sum "./BypassCNandLan.rules" | awk '{print $1}')
hash2=$(sha256sum "./rules/BypassCNandLan.rules" | awk '{print $1}')
echo -e "hash1=$hash1\nhash2=$hash2"
if [ "$hash1" == "$hash2" ]; then
echo "Hashes match. The files are identical."
echo "Upstream not updated"
echo "STATUS_2=1" >> $GITHUB_ENV
exit 0
else
echo "Hashes do not match. The files are different."
echo "Upstream updated."
echo "STATUS_2=0" >> $GITHUB_ENV
cp ./BypassCNandLan.rules ./rules/BypassCNandLan.rules
git add ./rules/BypassCNandLan.rules
git commit -am "Updated at $(TZ='Asia/Shanghai' date)"
fi
shell: bash
- name: Check GitHub Environment Variable and judgment wheather a Github Push is Needed
run: |
if [[ "${{ env.STATUS_1 }}" == "0" ]] || [[ "${{ env.STATUS_2 }}" == "0" ]] ; then
echo "NeedUpdate=true" >> $GITHUB_ENV
else
echo "NeedUpdate=false" >> $GITHUB_ENV
fi
echo ${{ env.NeedUpdate }}
shell: bash
- name: GitHub Push
uses: ad-m/[email protected]
if: env.NeedUpdate == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master
force: true