diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index cd8b78a..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: build - -on: - push: - branches: - - main - -jobs: - test: - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - go: ["1.20"] - name: ${{ matrix.os }} @ Go ${{ matrix.go }} - runs-on: ${{ matrix.os }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: main - - - name: Set up Go ${{ matrix.go }} - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go }} - - - name: Build - run: go build -ldflags "-s -w" -trimpath ./cmd/sf - - - name: Upload artifact - uses: actions/upload-artifact@v3 - if: success() - with: - name: ${{ matrix.os }} - if-no-files-found: ignore - path: | - sf.exe - sf diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9c59dd1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: release + +on: + push: + tags: + - v* + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "stable" + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 568e4f3..2823ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -.vscode/ -*.txt -*.pprof -.DS_Store -._* - +*.pprof +.DS_Store +._* +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..b7b83b4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,35 @@ +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - 386 + - arm64 + ignore: + - goos: darwin + goarch: "386" + binary: "{{ .ProjectName }}" + ldflags: + - -s -w -X main.Version={{.Version}} -X main.Branch={{.Branch}} -X main.Commit={{.ShortCommit}} + main: ./cmd/sf + +archives: + - format: zip + +checksum: + algorithm: sha256 + name_template: "checksums.txt" + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +changelog: + use: github diff --git a/README.md b/README.md index eb047a0..30ac567 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # SF -[![build status](https://img.shields.io/github/actions/workflow/status/0x2E/sf/build.yml?branch=main)](https://github.com/0x2E/sf/actions) [![Go Report Card](https://goreportcard.com/badge/github.com/0x2E/sf)](https://goreportcard.com/report/github.com/0x2E/sf) [![go version](https://img.shields.io/github/go-mod/go-version/0x2E/sf)](https://github.com/0x2E/sf/blob/main/go.mod) @@ -13,11 +12,7 @@ SF 是一个高效的子域名爆破工具: ## 安装 -1. 编译好的可执行文件 - - - [Release](https://github.com/0x2E/sf/releases) - - 主分支的最新提交:[Actions](https://github.com/0x2E/sf/actions) 中任意一次 workflow 的 Artifacts - +1. [Release](https://github.com/0x2E/sf/releases) 2. 编译源码 ```shell diff --git a/cmd/sf/sf.go b/cmd/sf/sf.go index 0ca8cd6..3671191 100644 --- a/cmd/sf/sf.go +++ b/cmd/sf/sf.go @@ -16,13 +16,16 @@ import ( "github.com/sirupsen/logrus" ) +var Version, Branch, Commit string + func main() { var ( - c = conf.C - output string - slient bool - debug bool - help bool + c = conf.C + output string + slient bool + debug bool + showHelp bool + showVersion bool ) flag.StringVarP(&c.Target, "domain", "d", "", "Target domain name") flag.StringVarP(&c.Wordlist, "wordlist", "w", "", "Wordlist file") @@ -36,19 +39,26 @@ It is recommended to determine if the rate is appropriate by the send/recv stati flag.BoolVar(&c.ValidCheck, "check", false, "Check the validity of the subdomains") flag.BoolVar(&slient, "slient", false, "Only output valid subdomains, and logs that caused abnormal exit, e.g., fatal and panic") flag.BoolVar(&debug, "debug", false, "Set the log level to debug, and enable golang pprof with web service") - flag.BoolVarP(&help, "help", "h", false, "Show help message") + flag.BoolVarP(&showVersion, "version", "v", false, "Show version") + flag.BoolVarP(&showHelp, "help", "h", false, "Show help message") flag.CommandLine.SortFlags = false flag.Parse() - if help { + if showHelp { flag.Usage() os.Exit(0) } + if showVersion { + version() + os.Exit(0) + } + logrus.SetFormatter(&logrus.TextFormatter{ TimestampFormat: "20060102 15:04:05", FullTimestamp: true, }) + if slient { if debug { logrus.Fatal("cannot enable 'debug' and 'slient' at the same time") @@ -56,6 +66,7 @@ It is recommended to determine if the rate is appropriate by the send/recv stati logrus.SetLevel(logrus.FatalLevel) } else { fmt.Print(banner) + version() } if debug { @@ -103,3 +114,7 @@ func pprof() { logrus.Error(err) } } + +func version() { + fmt.Printf("version: %s. branch: %s. commit: %s\n", Version, Branch, Commit) +}