-
Notifications
You must be signed in to change notification settings - Fork 1
217 lines (188 loc) · 7.46 KB
/
build.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Build & Test
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: 1 0 * * * # Daily at 1am UTC
jobs:
# First we need to compile the mmdbmeld project so we can build the DBs
build-tools:
runs-on: ubuntu-latest
env:
GO_VERSION: 1.21.8
MMDBMELD_TAG: v0.3.0
steps:
- name: Check for Cached Tools Build
uses: actions/cache@v4
id: tools-cache
with:
path: ./tools
key: go-v${{ env.GO_VERSION }}-mmdbmeld-${{ env.MMDBMELD_TAG }}
- name: Set up Go
uses: actions/setup-go@v5
if: steps.tools-cache.outputs.cache-hit != 'true'
with:
go-version: ${{ env.GO_VERSION }}
- name: Clone mmdbmeld
if: steps.tools-cache.outputs.cache-hit != 'true'
run: git clone -b ${{ env.MMDBMELD_TAG }} https://github.com/safing/mmdbmeld.git
- name: Build mmdbmeld
if: steps.tools-cache.outputs.cache-hit != 'true'
working-directory: ./mmdbmeld
run: |
go build -C cmd/mmdbmeld
go build -C cmd/mmdbcheck
go build -C cmd/mmdbquery
- name: Move the Tools
if: steps.tools-cache.outputs.cache-hit != 'true'
run: |
mkdir ./tools
cp ./mmdbmeld/cmd/mmdbmeld/mmdbmeld ./mmdbmeld/cmd/mmdbcheck/mmdbcheck ./mmdbmeld/cmd/mmdbquery/mmdbquery ./tools
- name: Upload Tools To Artifacts
uses: actions/upload-artifact@v4
with:
name: tools
path: ./tools
# Now we can fetch the DBs and build them
build-database:
runs-on: ubuntu-latest
needs: [build-tools]
steps:
- uses: actions/checkout@v4
- name: Download Tools
uses: actions/download-artifact@v4
with:
name: tools
- run: |
mkdir DBs
mkdir build
chmod +x mmdbmeld
echo "NOW=$(date '+%D')" >> ${GITHUB_ENV}
# Cache key is valid for 1 day & is to make repeat tests more efficient
- name: Cache DBs
uses: actions/cache@v4
with:
key: DBs-${{ env.NOW }}
path: ./DBs
# TODO: Can we do a better job of caching this?
- name: Download DBs
working-directory: ./DBs
run: |
curl --show-error \
--etag-save geo-whois-asn-country-ipv4.csv.etag \
--etag-compare geo-whois-asn-country-ipv4.csv.etag \
--output geo-whois-asn-country-ipv4.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country/geo-whois-asn-country-ipv4.csv"
curl --show-error \
--etag-save geo-whois-asn-country-ipv6.csv.etag \
--etag-compare geo-whois-asn-country-ipv6.csv.etag \
--output geo-whois-asn-country-ipv6.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country/geo-whois-asn-country-ipv6.csv"
curl --show-error \
--etag-save iptoasn-asn-ipv4.csv.etag \
--etag-compare iptoasn-asn-ipv4.csv.etag \
--output iptoasn-asn-ipv4.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-asn/iptoasn-asn-ipv4.csv"
curl --show-error \
--etag-save iptoasn-asn-ipv6.csv.etag \
--etag-compare iptoasn-asn-ipv6.csv.etag \
--output iptoasn-asn-ipv6.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-asn/iptoasn-asn-ipv6.csv"
curl --show-error \
--etag-save iptoasn-country-ipv4.csv.etag \
--etag-compare iptoasn-country-ipv4.csv.etag \
--output iptoasn-country-ipv4.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-country/iptoasn-country-ipv4.csv"
curl --show-error \
--etag-save iptoasn-country-ipv6.csv.etag \
--etag-compare iptoasn-country-ipv6.csv.etag \
--output iptoasn-country-ipv6.csv \
"https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-country/iptoasn-country-ipv6.csv"
- name: Build DBs
run: ./mmdbmeld build-config.yml
- name: Upload Build To Artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: ./build
run-tests:
runs-on: ubuntu-latest
needs: build-database
steps:
- name: Download Databases
uses: actions/download-artifact@v4
with:
name: build
- name: Download Tools
uses: actions/download-artifact@v4
with:
name: tools
- run: |
chmod +x mmdbcheck
- name: Perform mmdbcheck
run: |
find . -type f -name "*.mmdb" -print | while read -r file; do
./mmdbcheck all $file
done
# This test pulls in the Pingdom probe server data which includes their IP addresses and location and utilizes that to validate the results of the databases.
run-use-test-data:
runs-on: ubuntu-latest
needs: build-database
steps:
- uses: actions/checkout@v4
- name: Download Databases
uses: actions/download-artifact@v4
with:
name: build
- name: Download Tools
uses: actions/download-artifact@v4
with:
name: tools
- run: |
chmod +x mmdbcheck
echo "NOW=$(date '+%D')" >> ${GITHUB_ENV}
echo "RELEASE_DATE=$(date '+%D %T')" >> ${GITHUB_ENV}
mkdir data
- name: Start the results file
run: |
echo -e "# Built on: ${{ env.RELEASE_DATE }}\n" > results.md
echo -e "Releases will not be retained and should not be directly linked to within an application.\n" >> results.md
echo -e "Check the project's [readme](https://github.com/HostByBelle/IP-Geolocation-DB#variants) for information about the variants available & the correct download links to use.\n" >> results.md
echo -e "## Testing Results\n" >> results.md
- name: Download Testing Data
working-directory: ./tests
run: |
curl --show-error --output IPv4.json --location "https://github.com/HostByBelle/ip-db-test-data/releases/latest/download/IPv4.json"
curl --show-error --output IPv6.json --location "https://github.com/HostByBelle/ip-db-test-data/releases/latest/download/IPv6.json"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python Requirements
working-directory: ./tests
run: pip install -r requirements.txt
- name: Test IPv4 DBs
run: |
echo -e "### IPv4 Geolocation (Country) Tests\n" >> results.md
echo -e "| Database | Result |" >> results.md
echo -e "|----------|--------|" >> results.md
find . -type f -name "*v4*.mmdb" -print | while read -r file; do
result=$(python ./tests/geolocation-test.py ./tests/IPv4.json $file)
echo "| \`$file\` | $result |" >> results.md
done
- name: Test IPv6 DBs
run: |
echo -e "\n### IPv6 Geolocation (Country) Tests\n" >> results.md
echo -e "| Database | Result |" >> results.md
echo -e "|----------|--------|" >> results.md
find . -type f -name "*v6*.mmdb" -print | while read -r file; do
result=$(python ./tests/geolocation-test.py ./tests/IPv6.json $file)
echo "| \`$file\` | $result |" >> results.md
done
- name: Upload Results
uses: actions/upload-artifact@v4
with:
name: results
path: ./results.md