diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a5d7f92 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,50 @@ +name: Build V2Ray rules dat files +on: + schedule: + - cron: "*/15 * * * *" +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + include: + - rule: geoip + artifact_name: geoip.dat + asset_name: geoip.dat + - rule: geosite + artifact_name: geosite.dat + asset_name: geosite.dat + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@master + + - name: Set GOPATH + run: | + echo "##[set-env name=GOPATH;]$(dirname $GITHUB_WORKSPACE)" + echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/bin" + shell: bash + + - name: Generate + run: | + chmod +x generate-rules-dat.sh + ./generate-rules-dat.sh + - name: Create Latest tag + uses: EndBug/latest-tag@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload dat files to release + uses: svenstaro/upload-release-action@v1-release + with: + file: $(dirname $GITHUB_WORKSPACE)/v2ray/${{ matrix.artifact_name }} + asset_name: ${{ matrix.asset_name }} + tag: latest + overwrite: true + repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/generate-rules-dat.sh b/generate-rules-dat.sh new file mode 100755 index 0000000..df23557 --- /dev/null +++ b/generate-rules-dat.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -e + +GREEN='\033[0;32m' +NC='\033[0m' # no color + +# GOPATH=$(mktemp -d) +# export GOPATH=$GOPATH +V2RAY_FOLDER="$GOPATH/v2ray" + +GEOIP_REPO="github.com/ilouiss/geoip" +GEOSITE_REPO="github.com/v2ray/domain-list-community" +getGFWLIST_SCRIPT="https://raw.githubusercontent.com/cokebar/gfwlist2dnsmasq/master/gfwlist2dnsmasq.sh" +CHINA_DOMAINS_URL="https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf" +ADBLOCK_DOMAINS_URL="https://raw.githubusercontent.com/h2y/Shadowrocket-ADBlock-Rules/master/factory/resultant/ad.list" + +echo -e "${GREEN}>>> downloading $GEOIP_REPO...${NC}" +go get -insecure -v -u -d $GEOIP_REPO +cd $GOPATH/src/$GEOIP_REPO +echo -e "${GREEN}>>> building geoip.dat file...${NC}" +go run main.go +mv geoip.dat $V2RAY_FOLDER/geoip.dat + +echo -e "${GREEN}>>> downloading $GEOSITE_REPO...${NC}" +go get -insecure -v -u -d $GEOSITE_REPO +cd $GOPATH/src/$GEOSITE_REPO + +echo -e "${GREEN}>>> generating GFWList...${NC}" +curl -sSL $getGFWLIST_SCRIPT \ + | bash -s -- -l -o $GOPATH/src/$GEOSITE_REPO/data/gfwlist + +echo -e "${GREEN}>>> generating Chinese domains list...${NC}" +curl -sSL $CHINA_DOMAINS_URL \ + | awk -F '/' '{print $2}' \ + > $GOPATH/src/$GEOSITE_REPO/data/chinalist + +echo -e "${GREEN}>>> generating Adblock domains list...${NC}" +curl -sSL $ADBLOCK_DOMAINS_URL \ + | grep -Eov '^(\d{1,3}\.){3}\d{1,3}' \ + | grep -Eov '^[^.]$' \ + | grep -Eo '^(([a-zA-Z0-9]+[a-zA-Z0-9-]*)+\.)+[a-zA-Z0-9]{2,}$' \ + > $GOPATH/src/$GEOSITE_REPO/data/adblocklist + +echo -e "${GREEN}>>> building geosite.dat file...${NC}" +go run main.go +mv dlc.dat $V2RAY_FOLDER/geosite.dat + +echo -e "${GREEN}完成啦!🌈${NC}" + +go version + go get -v -t -d github.com/v2ray/domain-list-community/...