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

Commit

Permalink
refactor: build and goimports (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
l3uddz authored Apr 20, 2022
1 parent 5c66ab8 commit 5c98e4b
Show file tree
Hide file tree
Showing 33 changed files with 229 additions and 147 deletions.
52 changes: 41 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ jobs:
uses: goreleaser/goreleaser-action@v2
with:
install-only: true
version: 1.7.0

- name: goreleaser info
run: goreleaser -v

- name: task
uses: arduino/setup-task@v1

- name: task info
run: task --version

- name: qemu
uses: docker/setup-qemu-action@v1
Expand All @@ -33,31 +43,47 @@ jobs:
- name: go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.18

- name: go info
run: |
go version
go env
# cache
- name: cache
uses: actions/cache@v1
- name: cache-paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: cache-build
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: cache-mod
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: cache-task
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
path: .task/**/*
key: ${{ runner.os }}-go-task

# vendor
- name: vendor
run: |
make vendor
task vendor
# test
- name: tests
run: |
make test
task test
# git status
- name: git status
Expand All @@ -67,7 +93,7 @@ jobs:
- name: build
if: startsWith(github.ref, 'refs/tags/') == false
run: |
make snapshot
task snapshot
# publish
- name: publish
Expand All @@ -76,7 +102,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
make publish
task publish
# artifacts
- name: artifact_linux
Expand Down Expand Up @@ -116,6 +142,8 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
cloudb0x/autoscan:${{ steps.releasetag.outputs.tag }}
cloudb0x/autoscan:latest
Expand Down Expand Up @@ -145,6 +173,8 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
cloudb0x/autoscan:${{ steps.dockertag.outputs.replaced }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dist/
*.db
*.log
/autoscan
/config.yml
/config.yml

/.task/
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ checksum:

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

# Changelog
changelog:
Expand Down
57 changes: 0 additions & 57 deletions Makefile

This file was deleted.

66 changes: 66 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3'

vars:
APP: autoscan
CGO_ENABLED: 0
GOOS:
sh: go env GOOS
GOARCH:
sh: go env GOARCH
DIST_PATH: dist
BUILD_PATH: "{{.DIST_PATH}}/{{.APP}}_{{.GOOS}}_{{.GOARCH}}"

env:
GIT_COMMIT:
sh: git rev-parse --short HEAD
TIMESTAMP: '{{now | unixEpoch}}'
VERSION: 0.0.0-dev

tasks:
test:
desc: Go tests
cmds:
- go test ./... -cover -v -race ${GO_PACKAGES}

vendor:
desc: Go vendor
sources:
- '**/*.go'
- ./go.sum
cmds:
- go mod vendor
- go mod tidy

vendor_update:
desc: Go vendor update
cmds:
- go get -u ./...
- task: vendor

build:
desc: Generate a development binary
dir: '{{.BUILD_PATH}}'
deps: [ vendor ]
cmds:
- |
CGO_ENABLED={{.CGO_ENABLED}} \
go build \
-mod vendor \
-trimpath \
-ldflags "-s -w -X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.Timestamp=${TIMESTAMP}" \
../../cmd/{{.APP}}
release:
desc: Generate a release, but don't publish
cmds:
- goreleaser --skip-validate --skip-publish --rm-dist

snapshot:
desc: Generate a snapshot release
cmds:
- goreleaser --snapshot --skip-publish --rm-dist

publish:
desc: Generate a release, and publish
cmds:
- goreleaser --rm-dist
2 changes: 1 addition & 1 deletion cmd/autoscan/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ func getBinaryPath() string {
}

return dir
}
}
5 changes: 3 additions & 2 deletions cmd/autoscan/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/rs/zerolog/hlog"
"github.com/rs/zerolog/log"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"

"github.com/cloudbox/autoscan/processor"
"github.com/cloudbox/autoscan/triggers/a_train"
"github.com/cloudbox/autoscan/triggers/lidarr"
"github.com/cloudbox/autoscan/triggers/manual"
"github.com/cloudbox/autoscan/triggers/radarr"
"github.com/cloudbox/autoscan/triggers/sonarr"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)

func pattern(name string) string {
Expand Down
6 changes: 4 additions & 2 deletions cmd/autoscan/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"errors"
"time"

"github.com/rs/zerolog/log"

"github.com/cloudbox/autoscan"
"github.com/cloudbox/autoscan/processor"
"github.com/rs/zerolog/log"
"time"
)

func scanStats(proc *processor.Processor, interval time.Duration) {
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM sc4h/alpine-s6overlay:3.12
FROM sc4h/alpine-s6overlay:v2-3.15

ARG TARGETOS
ARG TARGETARCH
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/cloudbox/autoscan

go 1.17
go 1.18

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/alecthomas/kong v0.4.1
github.com/alecthomas/kong v0.5.0
github.com/fsnotify/fsnotify v1.5.1
github.com/go-chi/chi/v5 v5.0.7
github.com/l3uddz/bernard v0.5.1
Expand All @@ -15,15 +15,15 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.26.1
golang.org/x/mod v0.5.1 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
golang.org/x/tools v0.1.9 // indirect
golang.org/x/tools v0.1.10 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0
modernc.org/cc/v3 v3.35.22 // indirect
modernc.org/sqlite v1.14.7
modernc.org/cc/v3 v3.35.25 // indirect
modernc.org/sqlite v1.16.0
modernc.org/strutil v1.1.1 // indirect
)

Expand All @@ -32,13 +32,13 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rs/xid v1.3.0 // indirect
github.com/rs/xid v1.4.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/ccgo/v3 v3.15.13 // indirect
modernc.org/libc v1.14.5 // indirect
modernc.org/ccgo/v3 v3.15.18 // indirect
modernc.org/libc v1.14.12 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.5 // indirect
modernc.org/opt v0.1.1 // indirect
modernc.org/memory v1.0.7 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/token v1.0.0 // indirect
)
Loading

0 comments on commit 5c98e4b

Please sign in to comment.