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

refactor: build and goimports #155

Merged
merged 6 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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