-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (125 loc) · 4.97 KB
/
iplist-ir.yml
File metadata and controls
143 lines (125 loc) · 4.97 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Update Iran IP list from v2fly/geoip
on:
schedule:
- cron: '0 0 */30 * *'
workflow_dispatch: {}
permissions:
contents: write
jobs:
update-geoip:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest v2fly/geoip release tag
id: get_release
run: |
TAG=$(curl -s https://api.github.com/repos/v2fly/geoip/releases/latest | python3 -c "import sys,json; j=json.load(sys.stdin); print(j.get('tag_name',''))")
if [ -z "$TAG" ]; then
echo "tag=" >> $GITHUB_OUTPUT
else
echo "tag=$TAG" >> $GITHUB_OUTPUT
fi
- name: Read last processed tag
id: read_last
run: |
if [ -f .github/geoip_latest.txt ]; then
LAST=$(cat .github/geoip_latest.txt | tr -d '\n')
else
LAST=""
fi
echo "last=$LAST" >> $GITHUB_OUTPUT
- name: Skip if release already processed
if: ${{ steps.get_release.outputs.tag == steps.read_last.outputs.last }}
run: |
echo "No new release. Current latest tag is '${{ steps.get_release.outputs.tag }}'. Exiting."
- name: Setup Go
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
uses: actions/setup-go@v4
with:
go-version: '1.24.2'
- name: Ensure git installed (runner already has it, this is defensive)
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: sudo apt-get update && sudo apt-get install -y git curl
- name: Clone v2fly/geoip
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: git clone https://github.com/v2fly/geoip.git
- name: Create config.json in geoip repo
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: |
cat <<'EOF' > geoip/config.json
{
"input": [
{
"type": "v2rayGeoIPDat",
"action": "add",
"args": {
"uri": "./geoip.dat"
}
}
],
"output": [
{
"type": "text",
"action": "output",
"args": {
"outputDir": "./",
"oneFilePerList": true,
"wantedList": ["ir"],
"onlyIPType": "ipv4"
}
}
]
}
EOF
- name: Download latest geoip.dat
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: |
# direct download path for the asset (GitHub supports /latest/download/<name>)
curl -L -o geoip/geoip.dat "https://github.com/v2fly/geoip/releases/latest/download/geoip.dat"
ls -l geoip/geoip.dat
- name: Build dependencies and run generator
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
working-directory: geoip
run: |
go mod download
# run generator with config.json
go run ./ -c config.json
- name: Prepare one-line IR list and update target file
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: |
# geoip generator should have produced ./ir.txt in geoip/
if [ ! -f geoip/ir.txt ]; then
echo "geoip/ir.txt not found! Exiting with error." >&2
ls -la geoip
exit 2
fi
# convert newlines to spaces (keep it a single-line list)
tr '\r\n' ' ' < geoip/ir.txt | sed 's/ */ /g' > /tmp/ir_one_line.txt
# ensure trailing newline
sed -n '1p' /tmp/ir_one_line.txt > /tmp/ir_one_line_with_nl.txt
printf "\n" >> /tmp/ir_one_line_with_nl.txt
# create resources dir if missing (defensive)
mkdir -p resources
# move to repo file
mv /tmp/ir_one_line_with_nl.txt resources/pbr-iplist-iran-v4
echo "Updated resources/pbr-iplist-iran-v4 with new data."
- name: Commit & push only if changed
if: ${{ steps.get_release.outputs.tag != steps.read_last.outputs.last }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# record new processed tag
echo "${{ steps.get_release.outputs.tag }}" > .github/geoip_latest.txt
git add resources/pbr-iplist-iran-v4 .github/geoip_latest.txt
# check if any changes staged
if git diff --cached --quiet; then
echo "No changes to commit."
exit 0
fi
git commit -m "Update pbr-iplist-iran-v4 from v2fly/geoip release ${{ steps.get_release.outputs.tag }}"
git push origin HEAD:main