mirror of
https://github.com/SagerNet/sing-geoip.git
synced 2025-08-03 04:27:35 +08:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ecd02c178a | ||
![]() |
186135050e | ||
![]() |
4be169b3d3 | ||
![]() |
d4fc531179 | ||
![]() |
de4795c76c | ||
![]() |
633722fccd | ||
![]() |
4c65c38f08 | ||
![]() |
9c34309458 | ||
![]() |
4062751566 | ||
![]() |
b1dc5b3c1d | ||
![]() |
5362d9eef9 |
15
.github/release-branch.sh
vendored
Executable file
15
.github/release-branch.sh
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
mkdir -p release
|
||||
cd release
|
||||
git init
|
||||
git config --local user.email "github-action@users.noreply.github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git remote add origin https://github-action:$GITHUB_TOKEN@github.com/SagerNet/sing-geoip.git
|
||||
git branch -M release
|
||||
cp ../*.db ../*.sha256sum .
|
||||
git add .
|
||||
git commit -m "Update release"
|
||||
git push -f origin release
|
13
.github/release-rule-set.sh
vendored
Executable file
13
.github/release-rule-set.sh
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
cd rule-set
|
||||
git init
|
||||
git config --local user.email "github-action@users.noreply.github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git remote add origin https://github-action:$GITHUB_TOKEN@github.com/SagerNet/sing-geoip.git
|
||||
git branch -M rule-set
|
||||
git add .
|
||||
git commit -m "Update rule-set"
|
||||
git push -f origin rule-set
|
22
.github/renovate.json
vendored
Normal file
22
.github/renovate.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"commitMessagePrefix": "[dependencies]",
|
||||
"extends": [
|
||||
"config:base",
|
||||
":disableRateLimiting"
|
||||
],
|
||||
"baseBranches": [
|
||||
"main"
|
||||
],
|
||||
"golang": {
|
||||
"enabled": false
|
||||
},
|
||||
"packageRules": [
|
||||
{
|
||||
"matchManagers": [
|
||||
"github-actions"
|
||||
],
|
||||
"groupName": "github-actions"
|
||||
}
|
||||
]
|
||||
}
|
6
.github/update_dependencies.sh
vendored
Executable file
6
.github/update_dependencies.sh
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PROJECTS=$(dirname "$0")/../..
|
||||
|
||||
go get -x github.com/sagernet/sing-box@$(git -C $PROJECTS/sing-box rev-parse HEAD)
|
||||
go mod tidy
|
20
.github/workflows/build.yaml
vendored
20
.github/workflows/build.yaml
vendored
@ -9,29 +9,19 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get latest go version
|
||||
id: version
|
||||
run: |
|
||||
echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ steps.version.outputs.go_version }}
|
||||
go-version: ^1.22
|
||||
- name: Build geoip
|
||||
id: build
|
||||
env:
|
||||
NO_SKIP: true
|
||||
run: go run -v .
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: geoip.db
|
||||
path: geoip.db
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: geoip-cn.db
|
||||
path: geoip-cn.db
|
||||
path: geoip.db
|
81
.github/workflows/release.yaml
vendored
81
.github/workflows/release.yaml
vendored
@ -1,6 +1,9 @@
|
||||
name: Release
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "The tag version you want to build"
|
||||
schedule:
|
||||
- cron: "0 8 12 * *"
|
||||
jobs:
|
||||
@ -9,73 +12,45 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get latest go version
|
||||
id: version
|
||||
run: |
|
||||
echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ steps.version.outputs.go_version }}
|
||||
go-version: ^1.22
|
||||
- name: Build geoip
|
||||
id: build
|
||||
run: go run -v .
|
||||
env:
|
||||
FIXED_RELEASE: ${{ github.event.inputs.tag }}
|
||||
- name: Release rule sets
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
run: .github/release-rule-set.sh
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Generate sha256 hash
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
run: |
|
||||
sha256sum geoip.db > geoip.db.sha256sum
|
||||
sha256sum geoip-cn.db > geoip-cn.db.sha256sum
|
||||
- name: Create a release
|
||||
- name: Release release branch
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
run: .github/release-branch.sh
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: dev-drprasad/delete-older-releases@v0.3.2
|
||||
with:
|
||||
keep_latest: 3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Release geoip
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.build.outputs.tag }}
|
||||
release_name: ${{ steps.build.outputs.tag }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Release geoip.db
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./geoip.db
|
||||
asset_name: geoip.db
|
||||
asset_content_type: application/octet-stream
|
||||
- name: Release geoip.db sha256sum
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./geoip.db.sha256sum
|
||||
asset_name: geoip.db.sha256sum
|
||||
asset_content_type: text/plain
|
||||
- name: Release geoip-cn.db
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./geoip-cn.db
|
||||
asset_name: geoip-cn.db
|
||||
asset_content_type: application/octet-stream
|
||||
- name: Release geoip.db sha256sum
|
||||
if: steps.build.outputs.skip != 'true'
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./geoip-cn.db.sha256sum
|
||||
asset_name: geoip-cn.db.sha256sum
|
||||
asset_content_type: text/plain
|
||||
files: |
|
||||
geoip.db
|
||||
geoip.db.sha256sum
|
||||
geoip-cn.db
|
||||
geoip-cn.db.sha256sum
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
/.idea/
|
||||
/vendor/
|
||||
/*.db
|
||||
*.mmdb
|
||||
*.mmdb
|
||||
/rule-set/
|
||||
/release/
|
@ -1,54 +1,17 @@
|
||||
run:
|
||||
timeout: 5m
|
||||
|
||||
linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
- errcheck
|
||||
- wrapcheck
|
||||
- varnamelen
|
||||
- stylecheck
|
||||
- nonamedreturns
|
||||
- nlreturn
|
||||
- ireturn
|
||||
- gomnd
|
||||
- exhaustivestruct
|
||||
- ifshort
|
||||
- goerr113
|
||||
- gochecknoglobals
|
||||
- forcetypeassert
|
||||
- exhaustruct
|
||||
- exhaustive
|
||||
- cyclop
|
||||
- containedctx
|
||||
- wsl
|
||||
- nestif
|
||||
- lll
|
||||
- funlen
|
||||
- goconst
|
||||
- godot
|
||||
- gocognit
|
||||
- golint
|
||||
- goimports
|
||||
- gochecknoinits
|
||||
- maligned
|
||||
- tagliatelle
|
||||
- gocyclo
|
||||
- maintidx
|
||||
- gocritic
|
||||
- nakedret
|
||||
disable-all: true
|
||||
enable:
|
||||
- gofumpt
|
||||
- govet
|
||||
- gci
|
||||
- staticcheck
|
||||
|
||||
linters-settings:
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming
|
||||
disabled: true
|
||||
govet:
|
||||
enable-all: true
|
||||
disable:
|
||||
- composites
|
||||
- fieldalignment
|
||||
- shadow
|
||||
gosec:
|
||||
excludes:
|
||||
- G404
|
||||
gci:
|
||||
custom-order: true
|
||||
sections:
|
||||
- standard
|
||||
- prefix(github.com/sagernet/)
|
||||
- default
|
||||
staticcheck:
|
||||
go: '1.20'
|
||||
|
17
Makefile
Normal file
17
Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
fmt:
|
||||
@gofumpt -l -w .
|
||||
@gofmt -s -w .
|
||||
@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" .
|
||||
|
||||
fmt_install:
|
||||
go install -v mvdan.cc/gofumpt@latest
|
||||
go install -v github.com/daixiang0/gci@latest
|
||||
|
||||
lint:
|
||||
golangci-lint run ./...
|
||||
|
||||
lint_install:
|
||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
|
||||
test:
|
||||
go test -v ./...
|
@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate go install -v mvdan.cc/gofumpt@latest
|
||||
//go:generate go install -v github.com/daixiang0/gci@latest
|
||||
//go:generate gofumpt -l -w .
|
||||
//go:generate gofmt -s -w .
|
||||
//go:generate gci write .
|
29
go.mod
29
go.mod
@ -1,19 +1,28 @@
|
||||
module sing-geoip
|
||||
module github.com/sagernet/sing-geoip
|
||||
|
||||
go 1.18
|
||||
go 1.21
|
||||
|
||||
toolchain go1.22.6
|
||||
|
||||
require (
|
||||
github.com/google/go-github/v45 v45.2.0
|
||||
github.com/maxmind/mmdbwriter v0.0.0-20230530195610-0798c256659b
|
||||
github.com/oschwald/geoip2-golang v1.8.0
|
||||
github.com/oschwald/maxminddb-golang v1.10.0
|
||||
github.com/sagernet/sing v0.2.4
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/maxmind/mmdbwriter v1.0.0
|
||||
github.com/oschwald/geoip2-golang v1.11.0
|
||||
github.com/oschwald/maxminddb-golang v1.13.1
|
||||
github.com/sagernet/sing v0.4.3
|
||||
github.com/sagernet/sing-box v1.9.7
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||
golang.org/x/sys v0.7.0 // indirect
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||
github.com/miekg/dns v1.1.59 // indirect
|
||||
github.com/sagernet/sing-dns v0.2.3 // indirect
|
||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/mod v0.18.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
||||
)
|
||||
|
75
go.sum
75
go.sum
@ -1,35 +1,62 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v45 v45.2.0 h1:5oRLszbrkvxDDqBCNj2hjDZMKmvexaZ1xw/FCD+K3FI=
|
||||
github.com/google/go-github/v45 v45.2.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/maxmind/mmdbwriter v0.0.0-20230530195610-0798c256659b h1:+RXmWNst9zn/gJRLz6e3KpmjwoyDCWiyOPORL8k/Xtk=
|
||||
github.com/maxmind/mmdbwriter v0.0.0-20230530195610-0798c256659b/go.mod h1:/3IBsHZu2HKvnlBELgdw2ewEIkdCKCI+86iUnBYjEEw=
|
||||
github.com/oschwald/geoip2-golang v1.8.0 h1:KfjYB8ojCEn/QLqsDU0AzrJ3R5Qa9vFlx3z6SLNcKTs=
|
||||
github.com/oschwald/geoip2-golang v1.8.0/go.mod h1:R7bRvYjOeaoenAp9sKRS8GX5bJWcZ0laWO5+DauEktw=
|
||||
github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg=
|
||||
github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0=
|
||||
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5XqmmYsTLzJp/TO9Lhy39gkverk=
|
||||
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/maxmind/mmdbwriter v1.0.0 h1:bieL4P6yaYaHvbtLSwnKtEvScUKKD6jcKaLiTM3WSMw=
|
||||
github.com/maxmind/mmdbwriter v1.0.0/go.mod h1:noBMCUtyN5PUQ4H8ikkOvGSHhzhLok51fON2hcrpKj8=
|
||||
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
|
||||
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
|
||||
github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss=
|
||||
github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0=
|
||||
github.com/oschwald/geoip2-golang v1.11.0 h1:hNENhCn1Uyzhf9PTmquXENiWS6AlxAEnBII6r8krA3w=
|
||||
github.com/oschwald/geoip2-golang v1.11.0/go.mod h1:P9zG+54KPEFOliZ29i7SeYZ/GM6tfEL+rgSn03hYuUo=
|
||||
github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE=
|
||||
github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sagernet/sing v0.2.4 h1:gC8BR5sglbJZX23RtMyFa8EETP9YEUADhfbEzU1yVbo=
|
||||
github.com/sagernet/sing v0.2.4/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d h1:ggxwEf5eu0l8v+87VhX1czFh8zJul3hK16Gmruxn7hw=
|
||||
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
|
||||
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
|
||||
github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs=
|
||||
github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
|
||||
github.com/sagernet/quic-go v0.47.0-beta.2 h1:1tCGWFOSaXIeuQaHrwOMJIYvlupjTcaVInGQw5ArULU=
|
||||
github.com/sagernet/quic-go v0.47.0-beta.2/go.mod h1:bLVKvElSEMNv7pu7SZHscW02TYigzQ5lQu3Nh4wNh8Q=
|
||||
github.com/sagernet/sing v0.4.3 h1:Ty/NAiNnVd6844k7ujlL5lkzydhcTH5Psc432jXA4Y8=
|
||||
github.com/sagernet/sing v0.4.3/go.mod h1:ieZHA/+Y9YZfXs2I3WtuwgyCZ6GPsIR7HdKb1SdEnls=
|
||||
github.com/sagernet/sing-box v1.9.7 h1:+vA+xjbZuE7drPrkBRPPL/++Jz3ZcL5AExCR9LKAUVM=
|
||||
github.com/sagernet/sing-box v1.9.7/go.mod h1:1eZ08ofoql6NdYCkBJXICbqhWr1SzQkrxGy1p6RcY/U=
|
||||
github.com/sagernet/sing-dns v0.2.3 h1:YzeBUn2tR38F7HtvGEQ0kLRLmZWMEgi/+7wqa4Twb1k=
|
||||
github.com/sagernet/sing-dns v0.2.3/go.mod h1:BJpJv6XLnrUbSyIntOT6DG9FW0f4fETmPAHvNjOprLg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
|
||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
|
||||
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
|
||||
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
115
main.go
115
main.go
@ -6,20 +6,22 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/rw"
|
||||
|
||||
"github.com/google/go-github/v45/github"
|
||||
"github.com/maxmind/mmdbwriter"
|
||||
"github.com/maxmind/mmdbwriter/inserter"
|
||||
"github.com/maxmind/mmdbwriter/mmdbtype"
|
||||
"github.com/oschwald/geoip2-golang"
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/sagernet/sing-box/common/srs"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
var githubClient *github.Client
|
||||
@ -37,16 +39,25 @@ func init() {
|
||||
}
|
||||
|
||||
func fetch(from string) (*github.RepositoryRelease, error) {
|
||||
fixedRelease := os.Getenv("FIXED_RELEASE")
|
||||
names := strings.SplitN(from, "/", 2)
|
||||
latestRelease, _, err := githubClient.Repositories.GetLatestRelease(context.Background(), names[0], names[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if fixedRelease != "" {
|
||||
latestRelease, _, err := githubClient.Repositories.GetReleaseByTag(context.Background(), names[0], names[1], fixedRelease)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return latestRelease, err
|
||||
} else {
|
||||
latestRelease, _, err := githubClient.Repositories.GetLatestRelease(context.Background(), names[0], names[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return latestRelease, err
|
||||
}
|
||||
return latestRelease, err
|
||||
}
|
||||
|
||||
func get(downloadURL *string) ([]byte, error) {
|
||||
logrus.Info("download ", *downloadURL)
|
||||
log.Info("download ", *downloadURL)
|
||||
response, err := http.Get(*downloadURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -80,18 +91,8 @@ func parse(binary []byte) (metadata maxminddb.Metadata, countryMap map[string][]
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var code string
|
||||
if country.Country.IsoCode != "" {
|
||||
code = strings.ToLower(country.Country.IsoCode)
|
||||
} else if country.RegisteredCountry.IsoCode != "" {
|
||||
code = strings.ToLower(country.RegisteredCountry.IsoCode)
|
||||
} else if country.RepresentedCountry.IsoCode != "" {
|
||||
code = strings.ToLower(country.RepresentedCountry.IsoCode)
|
||||
} else if country.Continent.Code != "" {
|
||||
code = strings.ToLower(country.Continent.Code)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
// idk why
|
||||
code := strings.ToLower(country.RegisteredCountry.IsoCode)
|
||||
countryMap[code] = append(countryMap[code], ipNet)
|
||||
}
|
||||
err = networks.Err()
|
||||
@ -160,38 +161,17 @@ func write(writer *mmdbwriter.Tree, dataMap map[string][]*net.IPNet, output stri
|
||||
return err
|
||||
}
|
||||
|
||||
func local(input string, output string, codes []string) error {
|
||||
binary, err := os.ReadFile(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metadata, countryMap, err := parse(binary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var writer *mmdbwriter.Tree
|
||||
if rw.FileExists(output) {
|
||||
writer, err = open(output, codes)
|
||||
} else {
|
||||
writer, err = newWriter(metadata, codes)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return write(writer, countryMap, output, codes)
|
||||
}
|
||||
|
||||
func release(source string, destination string) error {
|
||||
func release(source string, destination string, output string, ruleSetOutput string) error {
|
||||
sourceRelease, err := fetch(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destinationRelease, err := fetch(destination)
|
||||
if err != nil {
|
||||
logrus.Warn("missing destination latest release")
|
||||
log.Warn("missing destination latest release")
|
||||
} else {
|
||||
if os.Getenv("NO_SKIP") != "true" && strings.Contains(*destinationRelease.Name, *sourceRelease.Name) {
|
||||
logrus.Info("already latest")
|
||||
log.Info("already latest")
|
||||
setActionOutput("skip", "true")
|
||||
return nil
|
||||
}
|
||||
@ -208,14 +188,16 @@ func release(source string, destination string) error {
|
||||
for code := range countryMap {
|
||||
allCodes = append(allCodes, code)
|
||||
}
|
||||
|
||||
writer, err := newWriter(metadata, allCodes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = write(writer, countryMap, "geoip.db", nil)
|
||||
err = write(writer, countryMap, output, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
writer, err = newWriter(metadata, []string{"cn"})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -224,9 +206,39 @@ func release(source string, destination string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
os.RemoveAll(ruleSetOutput)
|
||||
err = os.MkdirAll(ruleSetOutput, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for countryCode, ipNets := range countryMap {
|
||||
var headlessRule option.DefaultHeadlessRule
|
||||
headlessRule.IPCIDR = make([]string, 0, len(ipNets))
|
||||
for _, cidr := range ipNets {
|
||||
headlessRule.IPCIDR = append(headlessRule.IPCIDR, cidr.String())
|
||||
}
|
||||
var plainRuleSet option.PlainRuleSet
|
||||
plainRuleSet.Rules = []option.HeadlessRule{
|
||||
{
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: headlessRule,
|
||||
},
|
||||
}
|
||||
srsPath, _ := filepath.Abs(filepath.Join(ruleSetOutput, "geoip-"+countryCode+".srs"))
|
||||
os.Stderr.WriteString("write " + srsPath + "\n")
|
||||
outputRuleSet, err := os.Create(srsPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = srs.Write(outputRuleSet, plainRuleSet)
|
||||
if err != nil {
|
||||
outputRuleSet.Close()
|
||||
return err
|
||||
}
|
||||
outputRuleSet.Close()
|
||||
}
|
||||
|
||||
setActionOutput("tag", *sourceRelease.Name)
|
||||
return nil
|
||||
}
|
||||
@ -236,13 +248,8 @@ func setActionOutput(name string, content string) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
if len(os.Args) >= 3 {
|
||||
err = local(os.Args[1], os.Args[2], os.Args[3:])
|
||||
} else {
|
||||
err = release("Dreamacro/maxmind-geoip", "sagernet/sing-geoip")
|
||||
}
|
||||
err := release("Dreamacro/maxmind-geoip", "sagernet/sing-geoip", "geoip.db", "rule-set")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user