-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (64 loc) · 2.37 KB
/
update.yml
File metadata and controls
77 lines (64 loc) · 2.37 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
name: Get and Save GitHub IPs
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
permissions:
contents: write
jobs:
get_and_commit_ips:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Fetch and Filter GitHub Meta IPs
shell: bash
run: |
# 1. Create a Python script to handle subnet collapsing
# This script removes IPs that are already contained in larger networks (e.g. removing /32 if inside a /20)
cat << 'EOF' > collapse_ips.py
import sys
import ipaddress
# Read all lines from stdin
input_data = sys.stdin.read().split()
# Parse valid IPv4 networks
networks = []
for line in input_data:
try:
networks.append(ipaddress.IPv4Network(line.strip()))
except ValueError:
continue # Skip invalid entries
# collapse_addresses deduplicates, removes contained subnets, and merges adjacent ones
collapsed = ipaddress.collapse_addresses(networks)
# Print the result
for net in collapsed:
print(str(net))
EOF
# 2. Fetch data, process with jq, and pipe to the Python script
curl -fsSL "https://api.github.com/meta" | jq -r '
. |
{
hooks: .hooks,
web: .web,
api: .api,
git: .git,
github_enterprise_importer: .github_enterprise_importer,
packages: .packages,
pages: .pages,
importer: .importer
} |
flatten |
map(select(. | test("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(\\/\\d{1,2})?$"))) |
unique |
.[]
' | python3 collapse_ips.py > github_ip_list.txt
# 3. Clean up script
rm collapse_ips.py
# Debug output to verify content length in logs
echo "Generated IP list with $(wc -l < github_ip_list.txt) entries."
- name: Commit and Push Changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Automated update of GitHub IP list
file_pattern: github_ip_list.txt
# The action automatically handles "No changes to commit" scenarios