Skip to content

Commit 9f8a5e7

Browse files
committed
Generate new rule-sets
1 parent c69c0c0 commit 9f8a5e7

File tree

4 files changed

+99
-49
lines changed

4 files changed

+99
-49
lines changed

.github/release-rule-set.sh

+16-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
set -e -o pipefail
44

5-
cd rule-set
6-
git init
7-
git config --local user.email "[email protected]"
8-
git config --local user.name "GitHub Action"
9-
git remote add origin https://github-action:$GITHUB_TOKEN@github.com/SagerNet/sing-geosite.git
10-
git branch -M rule-set
11-
git add .
12-
git commit -m "Update rule-set"
13-
git push -f origin rule-set
5+
function releaseRuleSet() {
6+
dirName=$1
7+
pushd $dirName
8+
git init
9+
git config --local user.email "[email protected]"
10+
git config --local user.name "GitHub Action"
11+
git remote add origin https://github-action:$GITHUB_TOKEN@github.com/SagerNet/sing-geosite.git
12+
git branch -M $dirName
13+
git add .
14+
git commit -m "Update rule-set"
15+
git push -f origin $dirName
16+
popd
17+
}
18+
19+
releaseRuleSet rule-set
20+
releaseRuleSet rule-set-unstable

go.mod

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ toolchain go1.22.3
66

77
require (
88
github.com/google/go-github/v45 v45.2.0
9-
github.com/sagernet/sing v0.3.8
10-
github.com/sagernet/sing-box v1.8.13
9+
github.com/sagernet/sing v0.5.0-alpha.12.0.20240717075530-332e47007567
10+
github.com/sagernet/sing-box v1.9.4-0.20240718050851-e2b52d9664a6
1111
github.com/v2fly/v2ray-core/v5 v5.16.1
12-
google.golang.org/protobuf v1.34.0
12+
google.golang.org/protobuf v1.34.2
1313
)
1414

1515
require (
1616
github.com/adrg/xdg v0.4.0 // indirect
1717
github.com/golang/protobuf v1.5.4 // indirect
1818
github.com/google/go-querystring v1.1.0 // indirect
1919
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
20-
github.com/miekg/dns v1.1.59 // indirect
21-
github.com/sagernet/sing-dns v0.1.14 // indirect
20+
github.com/miekg/dns v1.1.61 // indirect
21+
github.com/sagernet/sing-dns v0.3.0-beta.10 // indirect
2222
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
23-
golang.org/x/crypto v0.22.0 // indirect
24-
golang.org/x/mod v0.17.0 // indirect
25-
golang.org/x/net v0.24.0 // indirect
23+
golang.org/x/crypto v0.24.0 // indirect
24+
golang.org/x/mod v0.18.0 // indirect
25+
golang.org/x/net v0.26.0 // indirect
2626
golang.org/x/sync v0.7.0 // indirect
27-
golang.org/x/sys v0.19.0 // indirect
28-
golang.org/x/tools v0.20.0 // indirect
27+
golang.org/x/sys v0.21.0 // indirect
28+
golang.org/x/tools v0.22.0 // indirect
2929
)

go.sum

+36-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
7+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
68
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
79
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
810
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -12,18 +14,28 @@ github.com/google/go-github/v45 v45.2.0 h1:5oRLszbrkvxDDqBCNj2hjDZMKmvexaZ1xw/FC
1214
github.com/google/go-github/v45 v45.2.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
1315
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
1416
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
17+
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5XqmmYsTLzJp/TO9Lhy39gkverk=
18+
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
1519
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
1620
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
17-
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
18-
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
21+
github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs=
22+
github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ=
23+
github.com/onsi/ginkgo/v2 v2.10.0 h1:sfUl4qgLdvkChZrWCYndY2EAu9BRIw1YphNAzy1VNWs=
24+
github.com/onsi/ginkgo/v2 v2.10.0/go.mod h1:UDQOh5wbQUlMnkLfVaIUMtQ1Vus92oM+P2JX1aulgcE=
1925
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2026
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
21-
github.com/sagernet/sing v0.3.8 h1:gm4JKalPhydMYX2zFOTnnd4TXtM/16WFRqSjMepYQQk=
22-
github.com/sagernet/sing v0.3.8/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI=
23-
github.com/sagernet/sing-box v1.8.13 h1:M8mLo7AWDKV9d+Bq41fOz7B5CvS4+xhBR1tmwzrr7PY=
24-
github.com/sagernet/sing-box v1.8.13/go.mod h1:Cb0FBO7r5UnQJQ7Ql0jgdJ8SmzCyFvCQ7eeXq2clTOI=
25-
github.com/sagernet/sing-dns v0.1.14 h1:kxE/Ik3jMXmD3sXsdt9MgrNzLFWt64mghV+MQqzyf40=
26-
github.com/sagernet/sing-dns v0.1.14/go.mod h1:AA+vZMNovuPN5i/sPnfF6756Nq94nzb5nXodMWbta5w=
27+
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
28+
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
29+
github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs=
30+
github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
31+
github.com/sagernet/quic-go v0.45.1-beta.2 h1:zkEeCbhdFFkrxKcuIRBtXNKci/1t2J/39QSG/sPvlmc=
32+
github.com/sagernet/quic-go v0.45.1-beta.2/go.mod h1:+N3FqM9DAzOWfe64uxXuBejVJwX7DeW7BslzLO6N/xI=
33+
github.com/sagernet/sing v0.5.0-alpha.12.0.20240717075530-332e47007567 h1:Sus0pCYn5KPOQmArXdRTtrml6XccSzV87FkFTDqATtU=
34+
github.com/sagernet/sing v0.5.0-alpha.12.0.20240717075530-332e47007567/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
35+
github.com/sagernet/sing-box v1.9.4-0.20240718050851-e2b52d9664a6 h1:BlgwOJWF/Aq+AyTHA6RUbptK77xyP+n4uKmsgpDNCCA=
36+
github.com/sagernet/sing-box v1.9.4-0.20240718050851-e2b52d9664a6/go.mod h1:pCo+ThuniLGPJvb/B/Q6uAmiahA4WnETHVqUJuNHpTs=
37+
github.com/sagernet/sing-dns v0.3.0-beta.10 h1:Js61EjQXVpcu2VDegWEQTH1isCcVwJju8WEHYgG4tQ0=
38+
github.com/sagernet/sing-dns v0.3.0-beta.10/go.mod h1:nXE6EYMXahB5DV3AcXYbFfuorqF7tbQ86kxweSxRKM4=
2739
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2840
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2941
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
@@ -32,22 +44,26 @@ github.com/v2fly/v2ray-core/v5 v5.16.1 h1:hIuRzCJhmRYqCA76hGiNLkAHopgbNt91L871wl
3244
github.com/v2fly/v2ray-core/v5 v5.16.1/go.mod h1:3pWIBTmNagMKpzd9/QicXq/7JZCQt716GsGZdBNmYkU=
3345
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
3446
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
35-
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
36-
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
37-
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
38-
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
39-
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
40-
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
47+
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
48+
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
49+
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
50+
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
51+
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
52+
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
53+
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
54+
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
4155
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
4256
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
4357
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
44-
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
45-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
46-
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
47-
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
58+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
59+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
60+
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
61+
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
62+
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
63+
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
4864
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
49-
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
50-
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
65+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
66+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
5167
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5268
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5369
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

main.go

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bufio"
45
"context"
56
"crypto/sha256"
67
"encoding/hex"
@@ -282,7 +283,7 @@ func mergeTags(data map[string][]geosite.Item) {
282283
println("merged cn categories: " + strings.Join(cnCodeList, ","))
283284
}
284285

285-
func generate(release *github.RepositoryRelease, output string, cnOutput string, ruleSetOutput string) error {
286+
func generate(release *github.RepositoryRelease, output string, cnOutput string, ruleSetOutput string, ruleSetUnstableOutput string) error {
286287
vData, err := download(release)
287288
if err != nil {
288289
return err
@@ -300,7 +301,12 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
300301
return err
301302
}
302303
defer outputFile.Close()
303-
err = geosite.Write(outputFile, domainMap)
304+
writer := bufio.NewWriter(outputFile)
305+
err = geosite.Write(writer, domainMap)
306+
if err != nil {
307+
return err
308+
}
309+
err = writer.Flush()
304310
if err != nil {
305311
return err
306312
}
@@ -316,12 +322,19 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
316322
return err
317323
}
318324
defer cnOutputFile.Close()
319-
err = geosite.Write(cnOutputFile, cnDomainMap)
325+
writer.Reset(cnOutputFile)
326+
err = geosite.Write(writer, cnDomainMap)
327+
if err != nil {
328+
return err
329+
}
330+
err = writer.Flush()
320331
if err != nil {
321332
return err
322333
}
323334
os.RemoveAll(ruleSetOutput)
335+
os.RemoveAll(ruleSetUnstableOutput)
324336
err = os.MkdirAll(ruleSetOutput, 0o755)
337+
err = os.MkdirAll(ruleSetUnstableOutput, 0o755)
325338
if err != nil {
326339
return err
327340
}
@@ -340,17 +353,30 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
340353
},
341354
}
342355
srsPath, _ := filepath.Abs(filepath.Join(ruleSetOutput, "geosite-"+code+".srs"))
343-
//os.Stderr.WriteString("write " + srsPath + "\n")
344-
outputRuleSet, err := os.Create(srsPath)
356+
unstableSRSPath, _ := filepath.Abs(filepath.Join(ruleSetUnstableOutput, "geosite-"+code+".srs"))
357+
// os.Stderr.WriteString("write " + srsPath + "\n")
358+
var (
359+
outputRuleSet *os.File
360+
outputRuleSetUnstable *os.File
361+
)
362+
outputRuleSet, err = os.Create(srsPath)
363+
if err != nil {
364+
return err
365+
}
366+
err = srs.Write(outputRuleSet, plainRuleSet, false)
367+
outputRuleSet.Close()
345368
if err != nil {
346369
return err
347370
}
348-
err = srs.Write(outputRuleSet, plainRuleSet)
371+
outputRuleSetUnstable, err = os.Create(unstableSRSPath)
372+
if err != nil {
373+
return err
374+
}
375+
err = srs.Write(outputRuleSetUnstable, plainRuleSet, true)
376+
outputRuleSetUnstable.Close()
349377
if err != nil {
350-
outputRuleSet.Close()
351378
return err
352379
}
353-
outputRuleSet.Close()
354380
}
355381
return nil
356382
}
@@ -359,7 +385,7 @@ func setActionOutput(name string, content string) {
359385
os.Stdout.WriteString("::set-output name=" + name + "::" + content + "\n")
360386
}
361387

362-
func release(source string, destination string, output string, cnOutput string, ruleSetOutput string) error {
388+
func release(source string, destination string, output string, cnOutput string, ruleSetOutput string, ruleSetOutputUnstable string) error {
363389
sourceRelease, err := fetch(source)
364390
if err != nil {
365391
return err
@@ -374,7 +400,7 @@ func release(source string, destination string, output string, cnOutput string,
374400
return nil
375401
}
376402
}
377-
err = generate(sourceRelease, output, cnOutput, ruleSetOutput)
403+
err = generate(sourceRelease, output, cnOutput, ruleSetOutput, ruleSetOutputUnstable)
378404
if err != nil {
379405
return err
380406
}
@@ -389,6 +415,7 @@ func main() {
389415
"geosite.db",
390416
"geosite-cn.db",
391417
"rule-set",
418+
"rule-set-unstable",
392419
)
393420
if err != nil {
394421
log.Fatal(err)

0 commit comments

Comments
 (0)