-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CI workflow for automated builds and deployments
- Added GitHub Actions workflow for CI - Configured build and deploy jobs - Uploaded artifacts for rule sets - Improved automation for project maintenance and deployment
- Loading branch information
0 parents
commit e175aa7
Showing
16 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"words": [ | ||
"dtemp", | ||
"emby", | ||
"liblaf", | ||
"pycache", | ||
"pydantic", | ||
"pyproject", | ||
"taplo", | ||
"venv" | ||
], | ||
"ignorePaths": ["**/*-lock.*", "**/*.lock*", "**/.cspell.json"], | ||
"allowCompoundWords": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# shellcheck disable=SC2148 | ||
source_env_if_exists ./.venv/bin/activate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
schedule: | ||
- cron: 0 0 * * * | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Rye | ||
uses: eifinger/setup-rye@v3 | ||
- name: Install sing-box | ||
uses: liblaf/repo/.github/actions/install@main | ||
with: | ||
brew: sing-box | ||
- name: Install Dependencies | ||
run: rye sync --no-lock | ||
- name: Build Rule Sets | ||
run: rye run python scripts/build.py | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: rule-sets | ||
path: rule-sets | ||
|
||
deploy: | ||
name: Deploy | ||
permissions: | ||
contents: write | ||
needs: | ||
- build | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download Artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: rule-sets | ||
path: rule-sets | ||
- name: Deploy to GitHub Branch | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
publish_branch: rule-sets | ||
publish_dir: rule-sets | ||
force_orphan: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# python generated files | ||
__pycache__/ | ||
*.py[oc] | ||
build/ | ||
dist/ | ||
wheels/ | ||
*.egg-info | ||
|
||
# venv | ||
.venv | ||
|
||
rule-sets/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"files.exclude": { | ||
"**/__pycache__": true, | ||
"**/.venv": true | ||
}, | ||
"python.analysis.diagnosticMode": "workspace" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
default: fmt | ||
|
||
fmt: fmt-toml | ||
|
||
fmt-toml: fmt-toml/pyproject.toml | ||
|
||
fmt-toml/%: % | ||
toml-sort --in-place --all "$<" | ||
taplo fmt "$<" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# sing-box-rules | ||
|
||
Describe your project here. | ||
* License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[build-system] | ||
build-backend = "hatchling.build" | ||
requires = ["hatchling"] | ||
|
||
[project] | ||
authors = [ | ||
{ email = "[email protected]", name = "liblaf" }, | ||
] | ||
dependencies = [ | ||
"pydantic>=2.7.3", | ||
"requests>=2.32.3", | ||
] | ||
description = "Add your description here" | ||
license = { text = "MIT" } | ||
name = "sing-box-rules" | ||
readme = "README.md" | ||
requires-python = ">= 3.12" | ||
version = "0.0.0" | ||
|
||
[project.scripts] | ||
"sing-box-rules" = "sbr:main" | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/sbr"] | ||
|
||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
|
||
[tool.rye] | ||
dev-dependencies = [] | ||
managed = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typeCheckingMode": "standard" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# generated by rye | ||
# use `rye lock` or `rye sync` to update this lockfile | ||
# | ||
# last locked with the following flags: | ||
# pre: false | ||
# features: [] | ||
# all-features: false | ||
# with-sources: false | ||
# generate-hashes: false | ||
|
||
-e file:. | ||
annotated-types==0.7.0 | ||
# via pydantic | ||
certifi==2024.6.2 | ||
# via requests | ||
charset-normalizer==3.3.2 | ||
# via requests | ||
idna==3.7 | ||
# via requests | ||
pydantic==2.7.3 | ||
# via sing-box-rules | ||
pydantic-core==2.18.4 | ||
# via pydantic | ||
requests==2.32.3 | ||
# via sing-box-rules | ||
typing-extensions==4.12.2 | ||
# via pydantic | ||
# via pydantic-core | ||
urllib3==2.2.1 | ||
# via requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# generated by rye | ||
# use `rye lock` or `rye sync` to update this lockfile | ||
# | ||
# last locked with the following flags: | ||
# pre: false | ||
# features: [] | ||
# all-features: false | ||
# with-sources: false | ||
# generate-hashes: false | ||
|
||
-e file:. | ||
annotated-types==0.7.0 | ||
# via pydantic | ||
certifi==2024.6.2 | ||
# via requests | ||
charset-normalizer==3.3.2 | ||
# via requests | ||
idna==3.7 | ||
# via requests | ||
pydantic==2.7.3 | ||
# via sing-box-rules | ||
pydantic-core==2.18.4 | ||
# via pydantic | ||
requests==2.32.3 | ||
# via sing-box-rules | ||
typing-extensions==4.12.2 | ||
# via pydantic | ||
# via pydantic-core | ||
urllib3==2.2.1 | ||
# via requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import re | ||
|
||
from sbr.geosite import Geosite | ||
from sbr.rule_set import RuleSet | ||
|
||
URL_PREFIX: str = "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest" | ||
geosite = Geosite(url=f"{URL_PREFIX}/geosite.db") | ||
|
||
geosite_ai: RuleSet = geosite.export("bing", "google", "openai", "perplexity") | ||
geosite_ai.save("rule-sets/ai.srs") | ||
geosite_emby: RuleSet = RuleSet.from_url( | ||
"https://github.com/NotSFC/rulelist/raw/main/sing-box/Emby/Emby.json" | ||
) | ||
geosite_emby.save("rule-sets/emby.srs") | ||
geosite_onedrive: RuleSet = geosite.export("onedrive") | ||
geosite_onedrive.save("rule-sets/onedrive.srs") | ||
geosite_proxy: RuleSet = geosite.export( | ||
*[category for category in geosite.list() if re.match(r".*!cn$", category)] | ||
) | ||
geosite_proxy.save("rule-sets/proxy.srs") | ||
geosite_cn: RuleSet = geosite.export( | ||
*[category for category in geosite.list() if re.match(r"(.*[-@])?cn$", category)] | ||
) | ||
geosite_proxy.save("rule-sets/cn.srs") |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import functools | ||
import json | ||
import pathlib | ||
import subprocess | ||
import tempfile | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
import requests | ||
|
||
from sbr.rule_set import RuleSet | ||
|
||
|
||
class Geosite: | ||
file: pathlib.Path | ||
_dtemp: tempfile.TemporaryDirectory | ||
|
||
def __init__( | ||
self, | ||
file: pathlib.Path | None = None, | ||
url: str = "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.db", | ||
) -> None: | ||
self._dtemp = tempfile.TemporaryDirectory() | ||
if file is None: | ||
self.file = self.dtemp / "geosite.db" | ||
with self.file.open("wb") as fp: | ||
resp: requests.Response = requests.get(url) | ||
resp.raise_for_status() | ||
fp.write(resp.content) | ||
else: | ||
self.file = file | ||
|
||
def export(self, *categories: str) -> RuleSet: | ||
with ThreadPoolExecutor() as executor: | ||
return sum(executor.map(self._export, categories), RuleSet()) | ||
|
||
@functools.cache | ||
def list(self) -> list[str]: | ||
proc: subprocess.CompletedProcess[str] = subprocess.run( | ||
["sing-box", "geosite", "--file", self.file, "list"], | ||
stdin=subprocess.DEVNULL, | ||
stdout=subprocess.PIPE, | ||
text=True, | ||
check=True, | ||
) | ||
categories: list[str] = [] | ||
for line in proc.stdout.splitlines(): | ||
categories.append(line.split()[0]) | ||
return categories | ||
|
||
@functools.cached_property | ||
def dtemp(self) -> pathlib.Path: | ||
return pathlib.Path(self._dtemp.name) | ||
|
||
@functools.lru_cache() | ||
def _export(self, category: str) -> RuleSet: | ||
output: pathlib.Path = self.dtemp / f"geosite-{category}.json" | ||
subprocess.run( | ||
[ | ||
"sing-box", | ||
"geosite", | ||
"--file", | ||
self.file, | ||
"export", | ||
category, | ||
"--output", | ||
output, | ||
], | ||
stdin=subprocess.DEVNULL, | ||
check=True, | ||
) | ||
return RuleSet(**json.loads(output.read_text())) |
Oops, something went wrong.