Skip to content

Commit

Permalink
Add CI with Linting and Testing (#142)
Browse files Browse the repository at this point in the history
* Refactor codebase for improved functionality, error handling, and data manipulation

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Add Dependabot configuration file

- Added a new file `.github/dependbot.yml` to the codebase.
- The file includes configuration for Dependabot.
- Added settings for two package ecosystems: `github-actions` and `gomod`.
- Both ecosystems are set to be checked on a weekly basis.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Add CI pipeline configuration for continuous integration

A new file named "ci.yml" has been added to the GitHub repository. This file contains a CI pipeline configuration that enables continuous integration. The pipeline is triggered by pull requests and pushes to the main branch. It runs on an Ubuntu environment and includes several steps such as checking out code, setting up Go, running golangci-lint, and building binaries for different operating systems and architectures. Additionally, the configuration includes build commands for different operating systems and architectures, followed by a test command for running tests with coverage analysis.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Refactor CI workflow to remove unnecessary build steps for darwin/arm platforms

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Rename .github/dependbot.yml to .github/dependabot.yml.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Refactor linter settings in .golangci.yml

Removed the errcheck and stylecheck linters from the list of enabled linters in .golangci.yml.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

---------

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
  • Loading branch information
rodneyosodo committed Feb 3, 2024
1 parent c6cf7da commit c3907ec
Show file tree
Hide file tree
Showing 43 changed files with 188 additions and 142 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
@@ -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
@@ -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
@@ -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
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
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
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
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
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
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
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
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
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
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
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
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

0 comments on commit c3907ec

Please sign in to comment.