diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4b403a0..91c186f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,20 +7,53 @@ on: branches: [ main ] jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.36 - build: - name: Build + test: + name: test runs-on: ubuntu-latest steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.16 - id: go + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.16 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Check out code into the Go module directory + uses: actions/checkout@v2 - - name: Build - run: make test + - name: Test + run: go test ./... -coverprofile=coverage.out + + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out + + test-release: + name: test release + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: --skip-publish --snapshot --rm-dist diff --git a/.gitignore b/.gitignore index 0c51afb..a587f4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea coverage.out +dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..d552c52 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,36 @@ +# This is an example goreleaser.yaml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +builds: +- env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X github.com/bakito/adguardhome-sync/version.Version={{.Version}} + goos: + - linux + - windows + - darwin + goarch: + - 386 + - amd64 + - arm + - arm64 + goarm: + - 5 + - 6 + - 7 + hooks: + post: upx {{ .Path }} +archives: +- replacements: + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile index 2283cd2..65630f1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - # Run go fmt against code fmt: go fmt ./... @@ -20,3 +19,11 @@ tidy: test: tidy fmt vet go test ./... -coverprofile=coverage.out go tool cover -func=coverage.out + +release: + @version=$$(go run version/semver/main.go); \ + git tag -s $$version -m"Release $$version" + goreleaser --rm-dist + +test-release: + goreleaser --skip-publish --snapshot --rm-dist \ No newline at end of file diff --git a/README.md b/README.md index 66c24fc..a496846 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ Synchronize [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome) config to a replica instance. -This is still work in progress. Changes on how parameters are provided will change. - ## Current sync features - Filters diff --git a/go.mod b/go.mod index 7ec01c8..d7ec6b5 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/bakito/adguardhome-sync go 1.16 require ( + github.com/coreos/go-semver v0.3.0 github.com/go-resty/resty/v2 v2.5.0 github.com/mitchellh/go-homedir v1.1.0 github.com/robfig/cron/v3 v3.0.1 diff --git a/go.sum b/go.sum index 06281c7..8e689d9 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,7 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= diff --git a/version/semver/main.go b/version/semver/main.go new file mode 100644 index 0000000..ad45c5c --- /dev/null +++ b/version/semver/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "os/exec" + "strings" + + "github.com/coreos/go-semver/semver" +) + +func main() { + out, err := exec.Command("git", "branch", "--show-current").Output() + if err != nil { + panic(err) + } + branch := strings.TrimSpace(string(out)) + if branch != "main" { + panic(fmt.Errorf(`error: must be in "master" branch, current branch: %q`, branch)) + } + + out, err = exec.Command("git", "describe").Output() + if err != nil { + panic(err) + } + + version := strings.TrimPrefix(strings.TrimSpace(string(out)), "v") + v := semver.New(version) + v.BumpPatch() + reader := bufio.NewReader(os.Stdin) + if _, err = fmt.Fprintf(os.Stderr, "Enter Release Version: [v%v] ", v); err != nil { + panic(err) + } + + text, err := reader.ReadString('\n') + if err != nil { + panic(err) + } + if strings.HasPrefix(text, "v") { + text = text[1:] + v = semver.New(strings.TrimSpace(text)) + } + + if _, err = fmt.Fprintf(os.Stderr, "Using Version: v%v\n", v); err != nil { + panic(err) + } + fmt.Printf("v%v", v) +} diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..d0d4d87 --- /dev/null +++ b/version/version.go @@ -0,0 +1,6 @@ +package version + +var ( + // Version the module version + Version = "devel" +)