Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the build process & add some features #255

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ jobs:
with:
go-version: ^1.15

- name: Set $GOPATH and more variables
- name: Set variables
run: |
echo "RELEASE_NAME=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
echo "TAG_NAME=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
echo "REPO_URL=github.com/${{ github.repository }}" >> $GITHUB_ENV
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
shell: bash

- name: Go get project code
run: |
go get -v -insecure $REPO_URL
- name: Checkout codebase
uses: actions/checkout@v2.3.3

- name: Build dlc.dat file
- name: Get dependencies and build dlc.dat file
run: |
domain-list-community --datapath=${{ env.GOPATH }}/src/${{ env.REPO_URL }}/data --exportlists=category-ads-all,tld-cn,cn,tld-\!cn,geolocation-\!cn,apple,icloud
go mod download
go run ./ --exportlists=category-ads-all,tld-cn,cn,tld-\!cn,geolocation-\!cn,apple,icloud

- name: Generate dlc.dat sha256 hash
run: |
Expand All @@ -57,10 +54,10 @@ jobs:
git config --local user.name "actions"
git config --local user.email "action@github.com"
git checkout -b release
git add *.txt dlc.dat dlc.dat.sha256sum dlc.dat.zip dlc.dat.zip.sha256sum dlc.dat.xz dlc.dat.xz.sha256sum gfwlist.txt gfwlist.txt.sha256sum
git add *.txt *.sha256sum dlc.dat dlc.dat.zip dlc.dat.xz
git commit -m "${{ env.RELEASE_NAME }}"
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u origin release
git remote add v2fly "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f v2fly release

- name: Create a release
id: create_release
Expand Down
65 changes: 65 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"

"v2ray.com/core/common"
)

type fileName string

type attribute string

// GetDataDir returns the path to the "data" directory used to generate lists.
// Usage order:
// 1. The datapath that user set when running the program
// 2. The default path "./data" (data directory in the current working directory) if exists
// 3. The path to the data directory in "GOPATH/src/modulepath"
func GetDataDir() string {
var dir string
defaultDataDir := filepath.Join("./", "data")
if *dataPath != defaultDataDir { // Use dataPath option if is set by user
dir = *dataPath
fmt.Printf("Use domain list files in '%s' directory.\n", dir)
return dir
}
if _, err := os.Stat(defaultDataDir); !os.IsNotExist(err) { // Use "./data" directory if exists
dir = defaultDataDir
fmt.Printf("Use domain list files in '%s' directory.\n", dir)
return dir
}
goPath := common.GetGOPATH()
pwd, wdErr := os.Getwd()
if wdErr != nil {
fmt.Println("Failed: cannot get current working directory", wdErr)
fmt.Println("Please run in the root path to the project")
os.Exit(1)
}
moduleName, mnErr := common.GetModuleName(pwd)
if mnErr != nil {
fmt.Println("Failed: cannot get module name", mnErr)
os.Exit(1)
}
modulePath := filepath.Join(strings.Split(moduleName, "/")...)
dir = filepath.Join(goPath, "src", modulePath, "data")
fmt.Println("Use $GOPATH:", goPath)
fmt.Printf("Use domain list files in '%s' directory.\n", dir)
return dir
}

// isEmpty checks if the rule that has been trimmed out spaces is empty
func isEmpty(s string) bool {
return len(strings.TrimSpace(s)) == 0
}

// removeComment removes comments in the rule
func removeComment(line string) string {
idx := strings.Index(line, "#")
if idx == -1 {
return line
}
return strings.TrimSpace(line[:idx])
}
1 change: 1 addition & 0 deletions data/cn
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

include:tld-cn
include:geolocation-cn
include:geolocation-!cn@cn
Loading