-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b49419a
Showing
75 changed files
with
4,734 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,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
PROJECTS=$(dirname "$0")/../.. | ||
go get -x github.com/sagernet/$1@$(git -C $PROJECTS/$1 rev-parse HEAD) | ||
go mod tidy |
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,51 @@ | ||
name: Debug build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
paths-ignore: | ||
- '**.md' | ||
- '.github/**' | ||
- '!.github/workflows/debug.yml' | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
build: | ||
name: Debug build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Get latest go version | ||
id: version | ||
run: | | ||
echo go_version=$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') >> $GITHUB_OUTPUT | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ steps.version.outputs.go_version }} | ||
- name: Cache go module | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
key: go-${{ hashFiles('**/go.sum') }} | ||
- name: Add cache to Go proxy | ||
run: | | ||
version=`git rev-parse HEAD` | ||
mkdir build | ||
pushd build | ||
go mod init build | ||
go get -v github.com/sagernet/serenity@$version | ||
popd | ||
continue-on-error: true | ||
- name: Run Test | ||
run: | | ||
go test -v ./... |
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,39 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
paths-ignore: | ||
- '**.md' | ||
- '.github/**' | ||
- '!.github/workflows/lint.yml' | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Get latest go version | ||
id: version | ||
run: | | ||
echo go_version=$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') >> $GITHUB_OUTPUT | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ steps.version.outputs.go_version }} | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout=30m | ||
install-mode: binary |
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,11 @@ | ||
/.idea/ | ||
/vendor/ | ||
/*.json | ||
/*.db | ||
/site/ | ||
/bin/ | ||
/dist/ | ||
/build/ | ||
.DS_Store | ||
/serenity | ||
/serenity.exe |
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,18 @@ | ||
linters: | ||
disable-all: true | ||
enable: | ||
- gofumpt | ||
- govet | ||
- gci | ||
- staticcheck | ||
- paralleltest | ||
|
||
linters-settings: | ||
gci: | ||
custom-order: true | ||
sections: | ||
- standard | ||
- prefix(github.com/sagernet/) | ||
- default | ||
staticcheck: | ||
go: '1.20' |
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,77 @@ | ||
project_name: serenity | ||
builds: | ||
- id: main | ||
main: ./cmd/serenity | ||
flags: | ||
- -v | ||
- -trimpath | ||
asmflags: | ||
- all=-trimpath={{.Env.GOPATH}} | ||
gcflags: | ||
- all=-trimpath={{.Env.GOPATH}} | ||
ldflags: | ||
- -X github.com/sagernet/serenity/cmd/serenity.Version={{ .Version }} -s -w -buildid= | ||
env: | ||
- CGO_ENABLED=0 | ||
targets: | ||
- linux_386 | ||
- linux_amd64_v1 | ||
- linux_arm64 | ||
- linux_arm_7 | ||
- linux_s390x | ||
mod_timestamp: '{{ .CommitTimestamp }}' | ||
snapshot: | ||
name_template: "{{ .Version }}.{{ .ShortCommit }}" | ||
archives: | ||
- id: archive | ||
builds: | ||
- main | ||
- android | ||
format: tar.gz | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
wrap_in_directory: true | ||
files: | ||
- LICENSE | ||
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
nfpms: | ||
- id: package | ||
package_name: serenity | ||
file_name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
vendor: sagernet | ||
homepage: https://serenity.sagernet.org/ | ||
maintainer: nekohasekai <[email protected]> | ||
description: The configuration generator for sing-box. | ||
license: GPLv3 or later | ||
formats: | ||
- deb | ||
- rpm | ||
- archlinux | ||
priority: extra | ||
contents: | ||
- src: release/config/config.json | ||
dst: /etc/serenity/config.json | ||
type: config | ||
- src: release/config/serenity.service | ||
dst: /etc/systemd/system/serenity.service | ||
- src: release/config/[email protected] | ||
dst: /etc/systemd/system/[email protected] | ||
- src: LICENSE | ||
dst: /usr/share/licenses/serenity/LICENSE | ||
source: | ||
enabled: false | ||
name_template: '{{ .ProjectName }}-{{ .Version }}.source' | ||
prefix_template: '{{ .ProjectName }}-{{ .Version }}/' | ||
checksum: | ||
disable: true | ||
name_template: '{{ .ProjectName }}-{{ .Version }}.checksum' | ||
signs: | ||
- artifacts: checksum | ||
release: | ||
github: | ||
owner: SagerNet | ||
name: serenity | ||
name_template: '{{ if .IsSnapshot }}{{ nightly }}{{ else }}{{ .Version }}{{ end }}' | ||
draft: true | ||
mode: replace |
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,17 @@ | ||
Copyright (C) 2022 by nekohasekai <[email protected]> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
In addition, no derivative work may use the name or imply association | ||
with this application without prior consent. |
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,63 @@ | ||
NAME = serenity | ||
COMMIT = $(shell git rev-parse --short HEAD) | ||
|
||
PARAMS = -v -trimpath -ldflags "-s -w -buildid=" | ||
MAIN_PARAMS = $(PARAMS) | ||
MAIN = ./cmd/serenity | ||
PREFIX ?= $(shell go env GOPATH) | ||
|
||
.PHONY: release docs | ||
|
||
build: | ||
go build $(MAIN_PARAMS) $(MAIN) | ||
|
||
install: | ||
go build -o $(PREFIX)/bin/$(NAME) $(MAIN_PARAMS) $(MAIN) | ||
|
||
fmt: | ||
@gofumpt -l -w . | ||
@gofmt -s -w . | ||
@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" . | ||
|
||
fmt_install: | ||
go install -v mvdan.cc/gofumpt@latest | ||
go install -v github.com/daixiang0/gci@latest | ||
|
||
lint: | ||
GOOS=linux golangci-lint run ./... | ||
GOOS=android golangci-lint run ./... | ||
GOOS=windows golangci-lint run ./... | ||
GOOS=darwin golangci-lint run ./... | ||
GOOS=freebsd golangci-lint run ./... | ||
|
||
lint_install: | ||
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
|
||
release: | ||
goreleaser release --clean --skip-publish || exit 1 | ||
mkdir dist/release | ||
mv dist/*.tar.gz dist/*.deb dist/*.rpm dist/*.pkg.tar.zst dist/release | ||
ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release | ||
rm -r dist/release | ||
|
||
release_install: | ||
go install -v github.com/goreleaser/goreleaser@latest | ||
go install -v github.com/tcnksm/ghr@latest | ||
|
||
docs: | ||
mkdocs serve | ||
|
||
publish_docs: | ||
mkdocs gh-deploy -m "Update" --force --ignore-version --no-history | ||
|
||
docs_install: | ||
pip install --force-reinstall mkdocs-material=="9.*" mkdocs-static-i18n=="1.2.*" | ||
|
||
clean: | ||
rm -rf bin dist serenity | ||
rm -f $(shell go env GOPATH)/serenity | ||
|
||
update: | ||
git fetch | ||
git reset FETCH_HEAD --hard | ||
git clean -fdx |
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 @@ | ||
# serenity | ||
|
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sagernet/serenity/server" | ||
"github.com/sagernet/sing-box/log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var commandCheck = &cobra.Command{ | ||
Use: "check", | ||
Short: "Check configuration", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := check() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
func init() { | ||
mainCommand.AddCommand(commandCheck) | ||
} | ||
|
||
func check() error { | ||
options, err := readConfigAndMerge() | ||
if err != nil { | ||
return err | ||
} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
instance, err := server.New(ctx, options) | ||
if err == nil { | ||
instance.Close() | ||
} | ||
cancel() | ||
return err | ||
} |
Oops, something went wrong.