Skip to content

Build & Test

Build & Test #407

Workflow file for this run

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