Add unit tests. #463
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
name: Generate | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
schedule: | |
- cron: '0 12 * * *' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Use Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
cache: 'pip' | |
- name: Setup environment | |
run: pip install -r requirements.txt | |
- name: Run pytest | |
run: | | |
cd Tests | |
pytest | |
build: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Use Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
cache: 'pip' | |
- name: Setup environment | |
run: pip install -r requirements.txt | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
- name: Pull v2fly community domain list | |
uses: actions/checkout@v3 | |
with: | |
repository: 'v2fly/domain-list-community' | |
path: 'domain-list-community' | |
- name: Pull Loyalsoldier's geosite tool | |
uses: actions/checkout@v3 | |
with: | |
repository: 'Loyalsoldier/domain-list-custom' | |
path: 'tool_geosite' | |
- name: Install Loyalsoldier's geoip tool | |
run: go install -v github.com/Loyalsoldier/geoip@latest | |
- name: Pull sing-geoip tool | |
uses: actions/checkout@v3 | |
with: | |
repository: 'xkww3n/sing-geoip' | |
path: 'tool_sing-geoip' | |
- name: Pull sing-geosite tool | |
uses: actions/checkout@v3 | |
with: | |
repository: 'xkww3n/sing-geosite' | |
path: 'tool_sing-geosite' | |
- name: Generate rules | |
run: python generate.py | |
- name: Download MaxMind GeoLite2 Country DB | |
env: | |
MAXMIND_KEY: ${{ secrets.MAXMIND_KEY }} | |
run: | | |
wget -O ./GeoLite2-Country.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${MAXMIND_KEY}&suffix=tar.gz" | |
tar xzvf ./GeoLite2-Country.tar.gz | |
cp ./GeoLite2-Country_*/GeoLite2-Country.mmdb ./ | |
- name: Generate Geosite DB | |
run: | | |
cd tool_geosite | |
go run ./ --datapath=../dists/geosite --outputpath=../dists --exportlists="" --togfwlist="" | |
- name: Generate GeoIP DB | |
run: | | |
cat <<EOF > config.json | |
{ | |
"input": [ | |
{ | |
"type": "private", | |
"action": "add" | |
}, | |
{ | |
"type": "maxmindMMDB", | |
"action": "add", | |
"args": { | |
"uri": "./GeoLite2-Country.mmdb" | |
} | |
}, | |
{ | |
"type": "cutter", | |
"action": "remove", | |
"args": { | |
"wantedList": ["cn"], | |
"onlyIPType": "ipv4" | |
} | |
}, | |
{ | |
"type": "text", | |
"action": "add", | |
"args": { | |
"name": "cn", | |
"uri": "./dists/text/domestic_ip.txt", | |
"onlyIPType": "ipv4" | |
} | |
}, | |
{ | |
"type": "text", | |
"action": "add", | |
"args": { | |
"name": "cn", | |
"uri": "./dists/text/domestic_ip6.txt", | |
"onlyIPType": "ipv6" | |
} | |
}, | |
{ | |
"type": "text", | |
"action": "add", | |
"args": { | |
"name": "telegram", | |
"uri": "https://core.telegram.org/resources/cidr.txt" | |
} | |
}, | |
{ | |
"type": "clashRuleSetClassical", | |
"action": "add", | |
"args": { | |
"name": "apns", | |
"uri": "./dists/yaml/apns.yaml" | |
} | |
} | |
], | |
"output": [ | |
{ | |
"type": "v2rayGeoIPDat", | |
"action": "output", | |
"args": { | |
"outputName": "geoip.dat", | |
"outputDir": "./dists" | |
} | |
}, | |
{ | |
"type": "maxmindMMDB", | |
"action": "output", | |
"args": { | |
"outputName": "geoip.mmdb", | |
"outputDir": "./dists", | |
"overwriteList": [ | |
"cn", | |
"private", | |
"telegram", | |
"apns" | |
] | |
} | |
} | |
] | |
} | |
EOF | |
geoip -c config.json | |
- name: Generate sing-box Geosite DB | |
run: | | |
cp dists/geosite.dat tool_sing-geosite/ | |
cd tool_sing-geosite | |
go run . | |
cp geosite.db ../dists/ | |
- name: Generate sing-box GeoIP DB | |
run: | | |
cp dists/geoip.mmdb tool_sing-geoip/ | |
cd tool_sing-geoip | |
go run . | |
cp geoip.db ../dists/ | |
- name: Remove tmp files | |
run: | | |
rm -rf dists/geosite | |
rm dists/gfwlist.txt | |
- name: Generate home page | |
run: python generate_homepage.py | |
- name: Publish to Cloudflare Pages | |
uses: cloudflare/pages-action@v1 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: 2e54d1245681bc04eaa33ed5d68bdfa7 | |
projectName: xkww3n-rules | |
directory: ./dists | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
wranglerVersion: '3' |