Skip to content

Commit

Permalink
ci(push): replace golangci-lint with super-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
streambinder committed Sep 7, 2024
1 parent 46895a5 commit 9cfb34b
Show file tree
Hide file tree
Showing 26 changed files with 177 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Spotitube <a href="https://davidepucci.it/doc/spotitube"><img align="left" src="https://github.com/streambinder.png?size=96"></a>
# Spotitube <a href="https://davidepucci.it/doc/spotitube"><img alt="documentation" align="left" src="https://github.com/streambinder.png?size=96"></a>

Documentation available at [davidepucci.it/doc/spotitube](https://davidepucci.it/doc/spotitube).
28 changes: 28 additions & 0 deletions .github/linters/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gosec
- goconst
linters:
enable:
- gosec
- unconvert
- gocyclo
- goconst
- goimports
- gocritic
- govet
- revive
linters-settings:
errcheck:
check-blank: true
govet:
enable:
- shadowing
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
6 changes: 6 additions & 0 deletions .github/linters/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
failure-threshold: warning

ignored:
- DL3018 # Pin versions in apk add
- SC2215 # This flag is used as a command name
6 changes: 6 additions & 0 deletions .github/linters/.jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"threshold": 3,
"reporters": ["consoleFull"],
"ignore": ["**/__snapshots__/**", "**/node_modules/**", "**/*_test.go"],
"absolute": true
}
38 changes: 33 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ on:
branches:
- master

permissions: write-all
permissions:
actions: read
attestations: none
checks: none
contents: read
deployments: none
id-token: none
issues: none
discussions: none
packages: write
pages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: none

jobs:
commitlint:
Expand All @@ -25,18 +39,23 @@ jobs:
- uses: codespell-project/actions-codespell@v2
with:
check_filenames: true
golangci-lint:
super-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: golangci/golangci-lint-action@v6
- uses: super-linter/super-linter@latest
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_SPOTITUBE }}
VALIDATE_ALL_CODEBASE: false
VALIDATE_GO: false
gofumpt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: |
export PATH=$PATH:$(go env GOPATH)/bin
PATH="$PATH:$(go env GOPATH)/bin"
export PATH
go install mvdan.cc/gofumpt@latest
if gofumpt -l -e . | grep '^' -q; then exit 1; fi
go-channel-closure:
Expand All @@ -56,7 +75,16 @@ jobs:
- run: test "$(grep -cr 'defer gomonkey\.')" = "$(grep -cr 'Reset()$')"
test:
runs-on: ubuntu-latest
needs: [commitlint, codespell, golangci-lint, gofumpt, go-channel-closure, go-http-body-closure, go-monkey-unpatch]
needs:
[
commitlint,
codespell,
super-linter,
gofumpt,
go-channel-closure,
go-http-body-closure,
go-monkey-unpatch,
]
if: success()
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scrape.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: go test -v -run ^TestScraping$ ./...
- run: go test -v -run ^TestScraping$ ./...
env:
TEST_SCRAPING: true
GENIUS_TOKEN: ${{ secrets.GENIUS_TOKEN }}
18 changes: 16 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ name: tag
on:
push:
tags:
- 'v*.*.*'
- "v*.*.*"

permissions: write-all
permissions:
actions: read
attestations: none
checks: none
contents: read
deployments: none
id-token: none
issues: none
discussions: none
packages: write
pages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: none

jobs:
test:
Expand Down
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
FROM golang:alpine AS builder
WORKDIR /workspace
COPY . .
RUN go mod download
RUN --mount=type=secret,id=SPOTIFY_ID \
RUN go mod download && \
--mount=type=secret,id=SPOTIFY_ID \
--mount=type=secret,id=SPOTIFY_KEY \
--mount=type=secret,id=GENIUS_TOKEN \
go build -ldflags="-s -w -X github.com/streambinder/spotitube/spotify.fallbackSpotifyID=$(cat /run/secrets/SPOTIFY_ID) -X github.com/streambinder/spotitube/spotify.fallbackSpotifyKey=$(cat /run/secrets/SPOTIFY_KEY) -X github.com/streambinder/spotitube/lyrics.fallbackGeniusToken=$(cat /run/secrets/GENIUS_TOKEN)"

FROM alpine:latest
RUN apk add --no-cache ffmpeg yt-dlp
RUN mkdir /data
RUN mkdir /cache
FROM alpine:3
RUN apk add --no-cache ffmpeg yt-dlp && \
mkdir /data && \
mkdir /cache && \
useradd -m spotitube
USER spotitube
WORKDIR /data
ENV XDG_MUSIC_DIR=/data
ENV XDG_CACHE_HOME=/cache
COPY --from=builder /workspace/spotitube /usr/sbin/
HEALTHCHECK CMD [ "/usr/sbin/spotitube", "--help" ]
EXPOSE 65535/tcp
ENTRYPOINT ["/usr/sbin/spotitube"]
LABEL org.opencontainers.image.source=https://github.com/streambinder/spotitube
6 changes: 3 additions & 3 deletions cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func cmdAttach() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
var (
path = args[0]
id = args[1]
rename, _ = cmd.Flags().GetBool("rename")
path = args[0]
id = args[1]
rename = util.ErrWrap(false)(cmd.Flags().GetBool("rename"))
)

localTrack, err := id3.Open(path, id3v2.Options{Parse: false})
Expand Down
6 changes: 3 additions & 3 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func cmdAuth() *cobra.Command {
Use: "auth",
Short: "Establish a Spotify session for future uses",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
var (
remote, _ = cmd.Flags().GetBool("remote")
logout, _ = cmd.Flags().GetBool("logout")
remote = util.ErrWrap(false)(cmd.Flags().GetBool("remote"))
logout = util.ErrWrap(false)(cmd.Flags().GetBool("logout"))
callback = "127.0.0.1"
processor = spotify.BrowserProcessor
)
Expand Down
12 changes: 6 additions & 6 deletions cmd/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func cmdLookup() *cobra.Command {
Short: "Utility to lookup for tracks in order to investigate general querying behaviour",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
library, _ := cmd.Flags().GetBool("library")
random, _ := cmd.Flags().GetBool("random")
randomSize, _ := cmd.Flags().GetInt("random-size")
libraryLimit, _ := cmd.Flags().GetInt("library-limit")
library := util.ErrWrap(false)(cmd.Flags().GetBool("library"))
random := util.ErrWrap(false)(cmd.Flags().GetBool("random"))
randomSize := util.ErrWrap(defaultRandomSize)(cmd.Flags().GetInt("random-size"))
libraryLimit := util.ErrWrap(0)(cmd.Flags().GetInt("library-limit"))
if !library && !random && len(args) == 0 {
return errors.New("no track has been issued")
}
Expand All @@ -48,7 +48,7 @@ func cmdLookup() *cobra.Command {
lyricsChannel = make(chan interface{}, 1)
)
return nursery.RunConcurrently(
func(ctx context.Context, ch chan error) {
func(_ context.Context, ch chan error) {
defer close(providerChannel)
defer close(lyricsChannel)
if random {
Expand All @@ -70,7 +70,7 @@ func cmdLookup() *cobra.Command {
}
}
},
func(ctx context.Context, ch chan error) {
func(_ context.Context, _ chan error) {
prefix := "[P]"
for event := range providerChannel {
track := event.(*entity.Track)
Expand Down
4 changes: 2 additions & 2 deletions cmd/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCmdLookupLibraryFailure(t *testing.T) {
ApplyFunc(spotify.Authenticate, func() (*spotify.Client, error) {
return &spotify.Client{}, nil
}).
ApplyMethod(&spotify.Client{}, "Library", func(_ *spotify.Client, _ int, ch ...chan interface{}) error {
ApplyMethod(&spotify.Client{}, "Library", func(_ *spotify.Client, _ int, _ ...chan interface{}) error {
return errors.New("ko")
}).
Reset()
Expand All @@ -125,7 +125,7 @@ func TestCmdLookupTrackFailure(t *testing.T) {
ApplyFunc(spotify.Authenticate, func() (*spotify.Client, error) {
return &spotify.Client{}, nil
}).
ApplyMethod(&spotify.Client{}, "Track", func(_ *spotify.Client, _ string, ch ...chan interface{}) (*entity.Track, error) {
ApplyMethod(&spotify.Client{}, "Track", func(_ *spotify.Client, _ string, _ ...chan interface{}) (*entity.Track, error) {
return nil, errors.New("ko")
}).Reset()

Expand Down
4 changes: 2 additions & 2 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func cmdReset() *cobra.Command {
Short: "Clear cached objects",
SilenceUsage: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
var (
session, _ = cmd.Flags().GetBool("session")
session = util.ErrWrap(false)(cmd.Flags().GetBool("session"))
cacheDirectory = util.CacheDirectory()
)
return filepath.WalkDir(cacheDirectory, func(path string, entry fs.DirEntry, err error) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func BenchmarkReset(b *testing.B) {
func TestCmdReset(t *testing.T) {
// monkey patching
defer gomonkey.NewPatches().
ApplyFunc(filepath.WalkDir, func(path string, f func(string, fs.DirEntry, error) error) error {
ApplyFunc(filepath.WalkDir, func(_ string, f func(string, fs.DirEntry, error) error) error {
_ = f("", DirEntry{name: "", isDir: false}, errors.New("some error"))
_ = f(spotify.TokenBasename, DirEntry{name: spotify.TokenBasename, isDir: false}, nil)
_ = f("fname.txt", DirEntry{name: "fname.txt", isDir: false}, nil)
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ var cmdRoot = &cobra.Command{
}

func Execute() {
_ = cmdRoot.Execute()
if err := cmdRoot.Execute(); err != nil {
cmdRoot.Println(err)
}
}
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func testExecute(cmd *cobra.Command, args ...string) error {
return cmdTest.Execute()
}

func TestExecute(t *testing.T) {
func TestExecute(_ *testing.T) {
cmdRoot.SetOut(io.Discard)
cmdRoot.SetErr(io.Discard)
cmdRoot.SetOutput(io.Discard)
Expand Down
2 changes: 1 addition & 1 deletion cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func cmdShow() *cobra.Command {
Short: "Show local tracks data",
SilenceUsage: true,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
bold := color.New(color.Bold)
for _, path := range args {
if err := func() error {
Expand Down
39 changes: 21 additions & 18 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -54,18 +55,18 @@ func cmdSync() *cobra.Command {
Short: "Synchronize collections",
SilenceUsage: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
var (
path, _ = cmd.Flags().GetString("output")
playlistEncoding, _ = cmd.Flags().GetString("playlist-encoding")
manual, _ = cmd.Flags().GetBool("manual")
library, _ = cmd.Flags().GetBool("library")
playlists, _ = cmd.Flags().GetStringArray("playlist")
playlistsTracks, _ = cmd.Flags().GetStringArray("playlist-tracks")
albums, _ = cmd.Flags().GetStringArray("album")
tracks, _ = cmd.Flags().GetStringArray("track")
fixes, _ = cmd.Flags().GetStringArray("fix")
libraryLimit, _ = cmd.Flags().GetInt("library-limit")
path = util.ErrWrap(xdg.UserDirs.Music)(cmd.Flags().GetString("output"))
playlistEncoding = util.ErrWrap("m3u")(cmd.Flags().GetString("playlist-encoding"))
manual = util.ErrWrap(false)(cmd.Flags().GetBool("manual"))
library = util.ErrWrap(false)(cmd.Flags().GetBool("library"))
playlists = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("playlist"))
playlistsTracks = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("playlist-tracks"))
albums = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("album"))
tracks = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("track"))
fixes = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("fix"))
libraryLimit = util.ErrWrap(0)(cmd.Flags().GetInt("library-limit"))
)

for index, path := range fixes {
Expand All @@ -89,7 +90,7 @@ func cmdSync() *cobra.Command {
routineMix(playlistEncoding),
)
},
PreRun: func(cmd *cobra.Command, args []string) {
PreRun: func(cmd *cobra.Command, _ []string) {
routineSemaphores = map[int](chan bool){
routineTypeIndex: make(chan bool, 1),
routineTypeAuth: make(chan bool, 1),
Expand All @@ -104,16 +105,18 @@ func cmdSync() *cobra.Command {
}

var (
playlists, _ = cmd.Flags().GetStringArray("playlist")
playlistsTracks, _ = cmd.Flags().GetStringArray("playlist-tracks")
albums, _ = cmd.Flags().GetStringArray("album")
tracks, _ = cmd.Flags().GetStringArray("track")
fixes, _ = cmd.Flags().GetStringArray("fix")
playlists = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("playlist"))
playlistsTracks = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("playlist-tracks"))
albums = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("album"))
tracks = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("track"))
fixes = util.ErrWrap([]string{})(cmd.Flags().GetStringArray("fix"))
)
if len(playlists)+len(playlistsTracks)+len(albums)+len(tracks)+len(fixes) == 0 {
cmd.LocalFlags().VisitAll(func(f *pflag.Flag) {
if f.Name == "library" {
_ = f.Value.Set("true")
if err := f.Value.Set("true"); err != nil {
log.Fatal(err)
}
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Documentation

1. [About](about.md)
2. [Installation](installation.md)
3. [Design](design.md)
Loading

0 comments on commit 9cfb34b

Please sign in to comment.