forked from lord-alfred/ipranges
-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (61 loc) · 2.19 KB
/
update.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
name: "Update"
on:
workflow_dispatch:
schedule:
- cron: '8 3 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare packages
run: sudo apt-get install -y whois jq ipcalc ripgrep gawk parallel
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('utils/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies
run: |
pip install -r utils/requirements.txt
- name: Download IPs
run: |
set -euo pipefail
set -x
find . -name downloader.sh| sort -h | awk '{print "Executing "$1"...";system("bash "$1)}'
- name: Merge ipv4 Ranges
run: |
set -euo pipefail
set -x
find . -name ipv4.txt| sort -h | parallel --will-cite -j 1 echo "Merging '{}'"';'python utils/merge.py --source={} '|' sort -h '>' {.}_merged.txt
- name: Merge ipv6 Ranges
run: |
set -euo pipefail
set -x
find . -name ipv6.txt| sort -h | parallel --will-cite -j 1 echo "Merging '{}'"';'python utils/merge.py --source={} '|' sort -h '>' {.}_merged.txt
- name: Commit files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git remote add github "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git pull github ${GITHUB_REF} --ff-only
# Get name & email from 1st commit
git config --local user.email "$(git log --format='%ae' --reverse | head -1)"
git config --local user.name "$(git log --format='%an' --reverse | head -1)"
# try commit
git add .
if [ -z "$(git status --porcelain)" ]; then
echo 'No changes'
exit 0
fi
git commit -m "Auto-update ip ranges"
# push changes
git push github HEAD:${GITHUB_REF}