Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI with Linting and Testing #142

Merged
merged 6 commits into from
Feb 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI Pipeline

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache-dependency-path: "go.sum"

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

- name: Build binary
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o immich-linux-amd64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o immich-linux-arm64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o immich-linux-arm6.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o immich-linux-arm7.exe -ldflags="-s -w -extldflags=-static" main.go

CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o immich-windows-amd64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o immich-windows-arm64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=windows GOARCH=arm GOARM=6 go build -o immich-windows-arm6.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=windows GOARCH=arm GOARM=7 go build -o immich-windows-arm7.exe -ldflags="-s -w -extldflags=-static" main.go

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o immich-darwin-amd64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o immich-darwin-arm64.exe -ldflags="-s -w -extldflags=-static" main.go

CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o immich-freebsd-amd64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o immich-freebsd-arm64.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=6 go build -o immich-freebsd-arm6.exe -ldflags="-s -w -extldflags=-static" main.go
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=7 go build -o immich-freebsd-arm7.exe -ldflags="-s -w -extldflags=-static" main.go

- name: Run tests
run: |
go test --race -v -count=1 -coverprofile=coverage.out ./...
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
run:
timeout: 3m

issues:
max-issues-per-linter: 100
max-same-issues: 100

linters-settings:
gocritic:
enabled-checks:
- captLocal
- singleCaseSwitch
- switchTrue
- httpNoBody
- emptyStringTest
- builtinShadow
- exposedSyncMutex
enabled-tags:
- diagnostic
disabled-tags:
- performance
- style
- experimental
- opinionated

linters:
disable-all: true
enable:
- gocritic
- gosimple
- govet
- ineffassign
- misspell
- whitespace
- gci
- gofmt
- goimports
- loggercheck
- asasalint
- contextcheck
- decorder
- dogsled
- errchkjson
- exportloopref
- ginkgolinter
- gocheckcompilerdirectives
- goprintffuncname
- mirror
- nakedret
7 changes: 1 addition & 6 deletions browser/files/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *browser.LocalAsse
}
}
return nil

})
if err != nil {
// Check if the context has been cancelled before sending the error
Expand All @@ -68,7 +67,6 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *browser.LocalAsse
}
}
}

}(ctx)

return fileChan
Expand Down Expand Up @@ -151,7 +149,6 @@ func (la *LocalAssetBrowser) handleFolder(ctx context.Context, fsys fs.FS, fileC
default:
fileChan <- &f
}

}
return nil
}
Expand All @@ -174,7 +171,6 @@ func (la *LocalAssetBrowser) checkSidecar(fsys fs.FS, f *browser.LocalAssetFile,
la.log.AddEntry(name, logger.ASSOCIATED_META, "")
return true
}

}
}
return false
Expand All @@ -193,8 +189,7 @@ func baseNames(n string) []string {
return names
}
n = strings.TrimSuffix(n, ext)
names = append(names, n)
names = append(names, n+".*")
names = append(names, n, n+".*")
ext = path.Ext(n)
}
}
Expand Down
7 changes: 2 additions & 5 deletions browser/files/localassets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"sort"
"testing"

"github.com/simulot/immich-go/browser/files"
"github.com/simulot/immich-go/logger"

"github.com/kr/pretty"
"github.com/psanford/memfs"
"github.com/simulot/immich-go/browser/files"
"github.com/simulot/immich-go/logger"
)

type inMemFS struct {
Expand Down Expand Up @@ -91,8 +90,6 @@ func TestLocalAssets(t *testing.T) {
t.Errorf("difference\n")
pretty.Ldiff(t, c.expected, results)
}

})

}
}
3 changes: 0 additions & 3 deletions browser/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"unicode/utf8"

"github.com/simulot/immich-go/browser"

"github.com/simulot/immich-go/helpers/fshelper"
"github.com/simulot/immich-go/helpers/gen"
"github.com/simulot/immich-go/logger"
Expand Down Expand Up @@ -94,7 +93,6 @@ func (to *Takeout) passOne(ctx context.Context) error {

func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
err := fs.WalkDir(w, ".", func(name string, d fs.DirEntry, err error) error {

if err != nil {
return err
}
Expand Down Expand Up @@ -474,7 +472,6 @@ func (to *Takeout) passTwoWalk(ctx context.Context, w fs.FS, assetChan chan *bro
}
return nil
})

}

// googleMDToAsset makes a localAssetFile based on the google metadata
Expand Down
2 changes: 0 additions & 2 deletions browser/gp/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestPresentFields(t *testing.T) {

tcs := []struct {
name string
json string
Expand Down Expand Up @@ -132,5 +131,4 @@ func TestPresentFields(t *testing.T) {
}
})
}

}
11 changes: 4 additions & 7 deletions browser/gp/testgp_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"strings"
"time"

"github.com/simulot/immich-go/immich/metadata"

"github.com/psanford/memfs"
"github.com/simulot/immich-go/immich/metadata"
)

type inMemFS struct {
Expand All @@ -36,9 +35,9 @@ func (mfs *inMemFS) addFile(name string, content []byte) *inMemFS {
return mfs
}

func (mfs *inMemFS) addImage(name string, len int) *inMemFS {
b := make([]byte, len)
for i := 0; i < len; i++ {
func (mfs *inMemFS) addImage(name string, length int) *inMemFS {
b := make([]byte, length)
for i := 0; i < length; i++ {
b[i] = byte(i % 256)
}
mfs.addFile(name, b)
Expand Down Expand Up @@ -124,7 +123,6 @@ func simpleYear() *inMemFS {
addImage("Takeout/Google Photos/Photos from 2023/PXL_20230922_144936660.jpg", 10).
addJSONImage("Takeout/Google Photos/Photos from 2023/PXL_20230922_144956000.jpg.json", "PXL_20230922_144956000.jpg").
addImage("Takeout/Google Photos/Photos from 2023/PXL_20230922_144956000.jpg", 20)

}

func simpleAlbum() *inMemFS {
Expand Down Expand Up @@ -190,7 +188,6 @@ func titlesWithForbiddenChars() *inMemFS {
addImage("Takeout/Google Photos/Photos from 2012/27_06_12 - 1.mov", 52).
addJSONImage("Takeout/Google Photos/Photos from 2012/27_06_12 - 1.json", "27/06/12 - 1").
addImage("Takeout/Google Photos/Photos from 2012/27_06_12 - 1.jpg", 24)

}

func namesIssue39() *inMemFS {
Expand Down
8 changes: 1 addition & 7 deletions browser/gp/testgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"reflect"
"testing"

"github.com/simulot/immich-go/logger"

"github.com/kr/pretty"
"github.com/simulot/immich-go/logger"
)

func TestBrowse(t *testing.T) {
Expand Down Expand Up @@ -97,7 +96,6 @@ func TestBrowse(t *testing.T) {
}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {

fsys := c.gen()
if fsys.err != nil {
t.Error(fsys.err)
Expand All @@ -122,11 +120,9 @@ func TestBrowse(t *testing.T) {
}
})
}

}

func TestAlbums(t *testing.T) {

type album map[string][]fileResult
tc := []struct {
name string
Expand Down Expand Up @@ -173,7 +169,6 @@ func TestAlbums(t *testing.T) {

for _, c := range tc {
t.Run(c.name, func(t *testing.T) {

ctx := context.Background()
fsys := c.gen()
if fsys.err != nil {
Expand Down Expand Up @@ -203,7 +198,6 @@ func TestAlbums(t *testing.T) {
t.Errorf("difference\n")
pretty.Ldiff(t, c.albums, albums)
}

})
}
}
1 change: 0 additions & 1 deletion browser/readersearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func searchPattern(r io.Reader, pattern []byte, maxDataLen int) ([]byte, error)
}

func seekReaderAtPattern(r io.Reader, pattern []byte) (io.Reader, error) {

var err error
pos := 0
// Create a buffer to hold the chunk of dataZ
Expand Down
13 changes: 5 additions & 8 deletions cmdduplicate/duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ func DuplicateCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.
return false
}
c = strings.Compare(keys[i].Name, keys[j].Name)
switch c {
case -1:
return true
}
return false

return c == -1
})

for _, k := range keys {
Expand All @@ -118,12 +115,12 @@ func DuplicateCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.
l := app.assetsByBaseAndDate[k]
app.logger.OK("There are %d copies of the asset %s, taken on %s ", len(l), k.Name, l[0].ExifInfo.DateTimeOriginal.Format(time.RFC3339))
albums := []immich.AlbumSimplified{}
delete := []string{}
assetsToDelete := []string{}
sort.Slice(l, func(i, j int) bool { return l[i].ExifInfo.FileSizeInByte < l[j].ExifInfo.FileSizeInByte })
for p, a := range l {
if p < len(l)-1 {
log.OK(" delete %s %dx%d, %s, %s", a.OriginalFileName, a.ExifInfo.ExifImageWidth, a.ExifInfo.ExifImageHeight, ui.FormatBytes(a.ExifInfo.FileSizeInByte), a.OriginalPath)
delete = append(delete, a.ID)
assetsToDelete = append(assetsToDelete, a.ID)
r, err := app.Immich.GetAssetAlbums(ctx, a.ID)
if err != nil {
log.Error("Can't get asset's albums: %s", err.Error())
Expand All @@ -143,7 +140,7 @@ func DuplicateCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.
}
}
if yes {
err = app.Immich.DeleteAssets(ctx, delete, false)
err = app.Immich.DeleteAssets(ctx, assetsToDelete, false)
if err != nil {
log.Error("Can't delete asset: %s", err.Error())
} else {
Expand Down
3 changes: 1 addition & 2 deletions cmdtool/cmdalbum/cmdalbum.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func AlbumCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log,
cmd := args[0]
args = args[1:]

switch cmd {
case "delete":
if cmd == "delete" {
return deleteAlbum(ctx, ic, log, args)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmdtool/cmdtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ func CommandTool(ctx context.Context, ic *immich.ImmichClient, logger *logger.Lo
cmd := args[0]
args = args[1:]

switch cmd {
case "album":
if cmd == "album" {
return cmdalbum.AlbumCommand(ctx, ic, logger, args)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmdupload/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (ai *AssetIndex) Len() int {
return len(ai.assets)
}

func (ai *AssetIndex) AddLocalAsset(la *browser.LocalAssetFile, ImmichID string) {
func (ai *AssetIndex) AddLocalAsset(la *browser.LocalAssetFile, immichID string) {
sa := &immich.Asset{
ID: ImmichID,
ID: immichID,
DeviceAssetID: la.DeviceAssetID(),
OriginalFileName: strings.TrimSuffix(path.Base(la.Title), path.Ext(la.Title)),
ExifInfo: immich.ExifInfo{
Expand Down
1 change: 0 additions & 1 deletion cmdupload/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func (c *Configuration) IsValid() error {
c.ExcludeExtensions, _ = checkExtensions(c.ExcludeExtensions)

return jerr

}

func checkExtensions(l StringList) (StringList, error) {
Expand Down