Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.0'
- '1.5'
- 'nightly'
os:
- ubuntu-latest
- macOS-latest
- windows-lates
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.3'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using GeoIP
DocMeta.setdocmeta!(GeoIP, :DocTestSetup, :(using GeoIP); recursive=true)
doctest(GeoIP)'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper"); Pkg.resolve()'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
15 changes: 15 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/Manifest.toml
/docs/Manifest.toml
/docs/build/
22 changes: 22 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = "GeoIP"
uuid = "abcde121-99a1-4d4f-92c5-2a3c6888d26a"
authors = ["Andrey Oskin", "Seth Bromberger", "contributors: https://github.com/JuliaWeb/GeoIP.jl/graphs/contributors"]
version = "0.4.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
IPNets = "66763231-799b-5fff-8662-389acfc33a85"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[compat]
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
7 changes: 0 additions & 7 deletions REQUIRE

This file was deleted.

3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
TimeZoneLookup = "7fc12173-ed04-4e20-9642-1f2134e2a757"
23 changes: 23 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using GeoIP
using Documenter

DocMeta.setdocmeta!(GeoIP, :DocTestSetup, :(using GeoIP); recursive=true)

makedocs(;
modules=[GeoIP],
authors = ["Andrey Oskin", "Seth Bromberger", "contributors: https://github.com/JuliaWeb/GeoIP.jl/graphs/contributors"],
repo="https://github.com/JuliaWeb/GeoIP.jl/blob/{commit}{path}#{line}",
sitename="GeoIP.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://JuliaWeb.github.io/GeoIP.jl",
assets=String[],
),
pages=[
"Home" => "index.md",
],
)

deploydocs(;
repo="github.com/JuliaWeb/GeoIP.jl",
)
12 changes: 12 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```@meta
CurrentModule = GeoIP
```

# GeoIP

```@index
```

```@autodocs
Modules = [GeoIP]
```
30 changes: 16 additions & 14 deletions src/GeoIP.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
__precompile__()

module GeoIP

using IPNets
using DataFrames
using ZipFile
using GZip
using IPNets
using DataFrames
using ZipFile
using GZip
using HTTP
using CSV
import Sockets: IPv4

export
# types
Location,
# methods
geolocate

export
# types
Location,
# methods
geolocate
include("data.jl")
include("geoip-module.jl")

include("data.jl")
include("geoip-module.jl")
end
end # module
8 changes: 2 additions & 6 deletions src/data.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import Requests
import CSV
import GZip

# Path to directory with data, can define GEOIP_DATADIR to override
# the default (useful for testing with a smaller test set)
const DATADIR = haskey(ENV, "GEOIP_DATADIR") ?
Expand Down Expand Up @@ -35,7 +31,7 @@ end

function getmd5()
try
r = Requests.get(CITYMD5URL)
r = HTTP.get(CITYMD5URL)
return string(r.data)
catch
error("Failed to download checksum file from MaxMind, check network connectivity")
Expand All @@ -46,7 +42,7 @@ updaterequired() = (readmd5() != getmd5())

function dldata(md5::String)
r = try
Requests.get(CITYDLURL)
HTTP.get(CITYDLURL)
catch
error("Failed to download file from MaxMind, check network connectivity")
end
Expand Down
26 changes: 26 additions & 0 deletions test/01_base.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module TestBase

using GeoIP
using Test

@testset "Known result" begin
ip1 = IPv4("1.2.3.4")
geoip1 = geolocate(ip1; noupdate=false)
@test geoip1[:country_iso_code] == "US"
@test geoip1[:metro_code] == 819
@test ceil(Int, geoip1[:location].x) == -122
end

@testset "Null results" begin
@test isempty(geolocate(ip"0.0.0.0"))
@test isempty(geolocate(ip"127.0.0.1"))
end

@testset "Array of ip's" begin
result = geolocate([ip"1.2.3.4", ip"8.8.8.8"])
@test length(Set(result)) == 2
@test !isempty(result[1])
@test !isempty(result[2])
end

end # module
38 changes: 22 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
using Base.Test
using GeoIP
module TestGeoIP

# Test known result
ip1 = IPv4("1.2.3.4")
geoip1 = geolocate(ip1; noupdate=false)
@test geoip1[:country_iso_code] == "US"
@test geoip1[:metro_code] == 819
@test ceil(Int, geoip1[:location].x) == -122
using Test

# Test null results
@test isempty(geolocate(ip"0.0.0.0"))
@test isempty(geolocate(ip"127.0.0.1"))
for file in sort([file for file in readdir(@__DIR__) if
occursin(r"^test[_0-9]+.*\.jl$", file)])
m = match(r"test([0-9]+)_(.*).jl", file)
filename = String(m[2])
testnum = string(parse(Int, m[1]))

# Test array of ip's
result = geolocate([ip"1.2.3.4", ip"8.8.8.8"])
@test length(Set(result)) == 2
@test !isempty(result[1])
@test !isempty(result[2])
# with this test one can run only specific tests, for example
# Pkg.test("Telegram", test_args = ["xxx"])
# or
# Pkg.test("Telegram", test_args = ["1"])
if isempty(ARGS) || (filename in ARGS) || (testnum in ARGS) || (m[1] in ARGS)
@testset "$filename" begin
# Here you can optionally exclude some test files
# VERSION < v"1.1" && file == "test_xxx.jl" && continue

include(file)
end
end
end

end # module