Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 5c98e4b

Browse files
authored
refactor: build and goimports (#155)
1 parent 5c66ab8 commit 5c98e4b

33 files changed

+229
-147
lines changed

.github/workflows/build.yml

+41-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ jobs:
1616
uses: goreleaser/goreleaser-action@v2
1717
with:
1818
install-only: true
19+
version: 1.7.0
20+
21+
- name: goreleaser info
22+
run: goreleaser -v
23+
24+
- name: task
25+
uses: arduino/setup-task@v1
26+
27+
- name: task info
28+
run: task --version
1929

2030
- name: qemu
2131
uses: docker/setup-qemu-action@v1
@@ -33,31 +43,47 @@ jobs:
3343
- name: go
3444
uses: actions/setup-go@v1
3545
with:
36-
go-version: 1.17
46+
go-version: 1.18
3747

3848
- name: go info
3949
run: |
4050
go version
4151
go env
4252
4353
# cache
44-
- name: cache
45-
uses: actions/cache@v1
54+
- name: cache-paths
55+
id: go-cache-paths
56+
run: |
57+
echo "::set-output name=go-build::$(go env GOCACHE)"
58+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
59+
60+
- name: cache-build
61+
uses: actions/cache@v2
62+
with:
63+
path: ${{ steps.go-cache-paths.outputs.go-build }}
64+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
65+
66+
- name: cache-mod
67+
uses: actions/cache@v2
68+
with:
69+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
70+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
71+
72+
- name: cache-task
73+
uses: actions/cache@v2
4674
with:
47-
path: vendor
48-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
49-
restore-keys: |
50-
${{ runner.os }}-go-
75+
path: .task/**/*
76+
key: ${{ runner.os }}-go-task
5177

5278
# vendor
5379
- name: vendor
5480
run: |
55-
make vendor
81+
task vendor
5682
5783
# test
5884
- name: tests
5985
run: |
60-
make test
86+
task test
6187
6288
# git status
6389
- name: git status
@@ -67,7 +93,7 @@ jobs:
6793
- name: build
6894
if: startsWith(github.ref, 'refs/tags/') == false
6995
run: |
70-
make snapshot
96+
task snapshot
7197
7298
# publish
7399
- name: publish
@@ -76,7 +102,7 @@ jobs:
76102
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77103
GITHUB_REF: ${{ github.ref }}
78104
run: |
79-
make publish
105+
task publish
80106
81107
# artifacts
82108
- name: artifact_linux
@@ -116,6 +142,8 @@ jobs:
116142
platforms: linux/amd64,linux/arm64,linux/arm/v7
117143
pull: true
118144
push: true
145+
cache-from: type=gha
146+
cache-to: type=gha,mode=max
119147
tags: |
120148
cloudb0x/autoscan:${{ steps.releasetag.outputs.tag }}
121149
cloudb0x/autoscan:latest
@@ -145,6 +173,8 @@ jobs:
145173
platforms: linux/amd64,linux/arm64,linux/arm/v7
146174
pull: true
147175
push: true
176+
cache-from: type=gha
177+
cache-to: type=gha,mode=max
148178
tags: |
149179
cloudb0x/autoscan:${{ steps.dockertag.outputs.replaced }}
150180

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ dist/
66
*.db
77
*.log
88
/autoscan
9-
/config.yml
9+
/config.yml
10+
11+
/.task/

.goreleaser.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ checksum:
4848

4949
# Snapshot
5050
snapshot:
51-
name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}"
51+
name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .Branch }}"
5252

5353
# Changelog
5454
changelog:

Makefile

-57
This file was deleted.

Taskfile.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
version: '3'
2+
3+
vars:
4+
APP: autoscan
5+
CGO_ENABLED: 0
6+
GOOS:
7+
sh: go env GOOS
8+
GOARCH:
9+
sh: go env GOARCH
10+
DIST_PATH: dist
11+
BUILD_PATH: "{{.DIST_PATH}}/{{.APP}}_{{.GOOS}}_{{.GOARCH}}"
12+
13+
env:
14+
GIT_COMMIT:
15+
sh: git rev-parse --short HEAD
16+
TIMESTAMP: '{{now | unixEpoch}}'
17+
VERSION: 0.0.0-dev
18+
19+
tasks:
20+
test:
21+
desc: Go tests
22+
cmds:
23+
- go test ./... -cover -v -race ${GO_PACKAGES}
24+
25+
vendor:
26+
desc: Go vendor
27+
sources:
28+
- '**/*.go'
29+
- ./go.sum
30+
cmds:
31+
- go mod vendor
32+
- go mod tidy
33+
34+
vendor_update:
35+
desc: Go vendor update
36+
cmds:
37+
- go get -u ./...
38+
- task: vendor
39+
40+
build:
41+
desc: Generate a development binary
42+
dir: '{{.BUILD_PATH}}'
43+
deps: [ vendor ]
44+
cmds:
45+
- |
46+
CGO_ENABLED={{.CGO_ENABLED}} \
47+
go build \
48+
-mod vendor \
49+
-trimpath \
50+
-ldflags "-s -w -X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.Timestamp=${TIMESTAMP}" \
51+
../../cmd/{{.APP}}
52+
53+
release:
54+
desc: Generate a release, but don't publish
55+
cmds:
56+
- goreleaser --skip-validate --skip-publish --rm-dist
57+
58+
snapshot:
59+
desc: Generate a snapshot release
60+
cmds:
61+
- goreleaser --snapshot --skip-publish --rm-dist
62+
63+
publish:
64+
desc: Generate a release, and publish
65+
cmds:
66+
- goreleaser --rm-dist

cmd/autoscan/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ func getBinaryPath() string {
4242
}
4343

4444
return dir
45-
}
45+
}

cmd/autoscan/router.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
"github.com/rs/zerolog/hlog"
99
"github.com/rs/zerolog/log"
1010

11+
"github.com/go-chi/chi/v5"
12+
"github.com/go-chi/chi/v5/middleware"
13+
1114
"github.com/cloudbox/autoscan/processor"
1215
"github.com/cloudbox/autoscan/triggers/a_train"
1316
"github.com/cloudbox/autoscan/triggers/lidarr"
1417
"github.com/cloudbox/autoscan/triggers/manual"
1518
"github.com/cloudbox/autoscan/triggers/radarr"
1619
"github.com/cloudbox/autoscan/triggers/sonarr"
17-
"github.com/go-chi/chi/v5"
18-
"github.com/go-chi/chi/v5/middleware"
1920
)
2021

2122
func pattern(name string) string {

cmd/autoscan/stats.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
"errors"
5+
"time"
6+
7+
"github.com/rs/zerolog/log"
8+
59
"github.com/cloudbox/autoscan"
610
"github.com/cloudbox/autoscan/processor"
7-
"github.com/rs/zerolog/log"
8-
"time"
911
)
1012

1113
func scanStats(proc *processor.Processor, interval time.Duration) {

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM sc4h/alpine-s6overlay:3.12
1+
FROM sc4h/alpine-s6overlay:v2-3.15
22

33
ARG TARGETOS
44
ARG TARGETARCH

go.mod

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/cloudbox/autoscan
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/BurntSushi/toml v0.3.1 // indirect
7-
github.com/alecthomas/kong v0.4.1
7+
github.com/alecthomas/kong v0.5.0
88
github.com/fsnotify/fsnotify v1.5.1
99
github.com/go-chi/chi/v5 v5.0.7
1010
github.com/l3uddz/bernard v0.5.1
@@ -15,15 +15,15 @@ require (
1515
github.com/pkg/errors v0.9.1 // indirect
1616
github.com/robfig/cron/v3 v3.0.1
1717
github.com/rs/zerolog v1.26.1
18-
golang.org/x/mod v0.5.1 // indirect
18+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
1919
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
20-
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
20+
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
2121
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
22-
golang.org/x/tools v0.1.9 // indirect
22+
golang.org/x/tools v0.1.10 // indirect
2323
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
2424
gopkg.in/yaml.v2 v2.4.0
25-
modernc.org/cc/v3 v3.35.22 // indirect
26-
modernc.org/sqlite v1.14.7
25+
modernc.org/cc/v3 v3.35.25 // indirect
26+
modernc.org/sqlite v1.16.0
2727
modernc.org/strutil v1.1.1 // indirect
2828
)
2929

@@ -32,13 +32,13 @@ require (
3232
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
3333
github.com/mattn/go-isatty v0.0.14 // indirect
3434
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
35-
github.com/rs/xid v1.3.0 // indirect
35+
github.com/rs/xid v1.4.0 // indirect
3636
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
3737
lukechampine.com/uint128 v1.2.0 // indirect
38-
modernc.org/ccgo/v3 v3.15.13 // indirect
39-
modernc.org/libc v1.14.5 // indirect
38+
modernc.org/ccgo/v3 v3.15.18 // indirect
39+
modernc.org/libc v1.14.12 // indirect
4040
modernc.org/mathutil v1.4.1 // indirect
41-
modernc.org/memory v1.0.5 // indirect
42-
modernc.org/opt v0.1.1 // indirect
41+
modernc.org/memory v1.0.7 // indirect
42+
modernc.org/opt v0.1.3 // indirect
4343
modernc.org/token v1.0.0 // indirect
4444
)

0 commit comments

Comments
 (0)