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 golangci-lint to workflows #34

Merged
merged 12 commits into from
Apr 8, 2024
18 changes: 18 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: golangci-lint
on:
push:
kavir1698 marked this conversation as resolved.
Show resolved Hide resolved
branches: [ "main" ]
pull_request:
branches: [ "*" ]

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
only-new-issues: true
71 changes: 71 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
run:
# Timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 3m
minottic marked this conversation as resolved.
Show resolved Hide resolved

# Exit code when at least one issue was found, default is 1
issues-exit-code: 1

# Include test files or not, default is true
tests: true

linters:
# Enable specific linters
enable:
kavir1698 marked this conversation as resolved.
Show resolved Hide resolved
- whitespace
- bodyclose
- dupl
- goprintffuncname
- gosec
- gosimple
- govet
- misspell
- nakedret
- prealloc
- staticcheck
- unparam
- unused

# Disable specific linters
disable:
- typecheck
- gochecknoinits
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- ineffassign
- lll
- stylecheck
- unconvert
- megacheck
- gas
- dogsled
- errcheck

linters-settings:
gocyclo:
# Minimal code complexity to report
min-complexity: 10
golint:
# Minimal confidence to report a problem, low by default
min-confidence: 0.8
unused:
# Treat code as a program (not a library) and report unused exported identifiers; default is false.
# The argument specifies the Go source directory to analyze.
check-exported: false

output:
formats:
- format: colored-line-number
path: stdout
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true
sort-order:
- file
- linter
- severity
show-stats: true
7 changes: 1 addition & 6 deletions cmd/datasetArchiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
var VERSION string

func main() {

var client = &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: 10 * time.Second}
Expand Down Expand Up @@ -59,10 +58,7 @@ func main() {
}

// check for program version only if running interactively
err := datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{})
if err != nil {
log.Fatalf("Error checking for new version: %v", err)
}
datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{})

if *testenvFlag {
APIServer = TEST_API_SERVER
Expand Down Expand Up @@ -128,5 +124,4 @@ func main() {
} else {
log.Fatalf("No archivable datasets remaining")
}

}
6 changes: 1 addition & 5 deletions cmd/datasetCleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func isFlagPassed(name string) bool {
var VERSION string

func main() {

var client = &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: 10 * time.Second}
Expand Down Expand Up @@ -83,10 +82,7 @@ func main() {
}

// check for program version only if running interactively
err := datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{})
if err != nil {
log.Fatalf("Error checking for new version: %v", err)
}
datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{})
datasetUtils.CheckForServiceAvailability(client, *testenvFlag, true)

//}
Expand Down
6 changes: 1 addition & 5 deletions cmd/datasetGetProposal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
var VERSION string

func main() {

var client = &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: 10 * time.Second}
Expand Down Expand Up @@ -54,10 +53,7 @@ func main() {
}

// check for program version only if running interactively
err := datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{})
if err != nil {
log.Fatalf("Error checking for new version: %v", err)
}
datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{})

if *testenvFlag {
APIServer = TEST_API_SERVER
Expand Down
7 changes: 1 addition & 6 deletions cmd/datasetIngestor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ func main() {
}

// check for program version only if running interactively
err := datasetUtils.CheckForNewVersion(client, APP, VERSION, !*noninteractiveFlag, datasetUtils.StdinUserInput{})
if err != nil {
log.Fatalf("Error checking for new version: %v", err)
}
datasetUtils.CheckForNewVersion(client, APP, VERSION, !*noninteractiveFlag, datasetUtils.StdinUserInput{})
datasetUtils.CheckForServiceAvailability(client, *testenvFlag, *autoarchiveFlag)

//}
Expand Down Expand Up @@ -373,7 +370,6 @@ func main() {
}
}
datasetIngestor.ResetUpdatedMetaData(originalMap, metaDataMap)

}
}

Expand Down Expand Up @@ -407,5 +403,4 @@ func main() {
for i := 0; i < len(datasetList); i++ {
fmt.Println(datasetList[i])
}

}
5 changes: 1 addition & 4 deletions cmd/datasetIngestor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
"testing"
)

func init() {
os.Setenv("TEST_MODE", "true")
}

// TestMainOutput is a test function that verifies the output of the main function.
// It captures the stdout, runs the main function, and checks if the output contains the expected strings.
// This just checks if the main function prints the help message.
func TestMainOutput(t *testing.T) {
os.Setenv("TEST_MODE", "true")
oldTestMode := "false"
defer os.Setenv("TEST_MODE", oldTestMode)
// Capture stdout
Expand Down
8 changes: 4 additions & 4 deletions cmd/datasetPublishData/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*

Purpose: copy all files from a publisheddata entry (list of datasets) to publication server
taking into account orginal sourceFolder names
taking into account original sourceFolder names

This script must be run on the retrieve servers (from root) and pushes data to the publication server
hosted in the DMZ. It requires that a previous retrieve job for the datasets, executed
Expand Down Expand Up @@ -79,9 +79,7 @@ func check(e error) {
}

func main() {

// check input parameters

publishFlag := flag.Bool("publish", false, "Defines if this command is meant to actually publish data (default nothing is done)")
publishedDataId := flag.String("publisheddata", "", "Defines to publish data froma given publishedData document ID")
// datasetId := flag.String("dataset", "", "Defines single datasetId to publish")
Expand Down Expand Up @@ -208,7 +206,6 @@ func findMinLength(arr []string) int {
// A Function that returns the longest common prefix path (runes)
// from the array of strings
func commonPrefix(arr []string) string {

n := len(arr)
if n == 1 {
return arr[0]
Expand Down Expand Up @@ -317,6 +314,9 @@ func createWebpage(urls []string, title string, doi string, datasetDetails []dat

myurl := APIServer + "/PublishedData/" + strings.Replace(publishedDataId, "/", "%2F", 1) + "?access_token=" + user["accessToken"]
req, err := http.NewRequest("PATCH", myurl, bytes.NewBuffer(cmm))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
// fmt.Printf("request to message broker:%v\n", req)
resp, err := client.Do(req)
Expand Down
2 changes: 0 additions & 2 deletions cmd/datasetPublishDataRetrieve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ var scanner = bufio.NewScanner(os.Stdin)
var VERSION string

func main() {

// check input parameters

retrieveFlag := flag.Bool("retrieve", false, "Defines if this command is meant to actually retrieve data (default: retrieve actions are only displayed)")
publishedDataId := flag.String("publisheddata", "", "Defines to publish data from a given publishedData document ID")
userpass := flag.String("user", "", "Defines optional username:password string")
Expand Down
8 changes: 2 additions & 6 deletions cmd/datasetRetriever/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*

Purpose: retrieve datasets from intermediate cache, taking into account orginal sourceFolder names
Purpose: retrieve datasets from intermediate cache, taking into account original sourceFolder names

This script must be run on the machine having write access to the destination folder

Expand Down Expand Up @@ -74,10 +74,7 @@ func main() {
return
}

err := datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{})
if err != nil {
log.Fatalf("Error checking for new version: %v", err)
}
datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{})

var env string
if *testenvFlag {
Expand Down Expand Up @@ -150,7 +147,6 @@ func main() {
}
}
}

}

type Dataset struct {
Expand Down
1 change: 0 additions & 1 deletion cmd/waitForJobFinished/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Job struct {
var VERSION string

func main() {

var client = &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: 10 * time.Second}
Expand Down
8 changes: 5 additions & 3 deletions datasetIngestor/addAttachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func AddAttachment(client *http.Client, APIServer string, datasetId string, metaDataDataset map[string]interface{}, accessToken string, attachmentFile string, caption string) {

// turn image into base64 structure:
imgFile, err := os.Open(attachmentFile)
if err != nil {
Expand Down Expand Up @@ -40,12 +39,12 @@ func AddAttachment(client *http.Client, APIServer string, datasetId string, meta
metaDataMap["caption"] = caption
metaDataMap["datasetId"] = datasetId
if ownerGroup, ok := metaDataDataset["ownerGroup"]; ok {
metaDataMap["ownerGroup"], ok = ownerGroup.(string)
metaDataMap["ownerGroup"], _ = ownerGroup.(string)
}
if accessGroups, ok := metaDataDataset["accessGroups"]; ok {
metaDataMap["accessGroups"], ok = accessGroups.([]string)
if !ok {
metaDataMap["accessGroups"], ok = accessGroups.([]interface{})
metaDataMap["accessGroups"], _ = accessGroups.([]interface{})
}
}

Expand All @@ -56,6 +55,9 @@ func AddAttachment(client *http.Client, APIServer string, datasetId string, meta
myurl := APIServer + "/Datasets/" + strings.Replace(datasetId, "/", "%2F", 1) + "/attachments?access_token=" + accessToken

req, err := http.NewRequest("POST", myurl, bytes.NewBuffer(bm))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions datasetIngestor/assembleFilelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Datafile struct {
var skippedLinks = 0
var illegalFileNames = 0
var errorGroupIds = 0

const windows = "windows"
var scanner = bufio.NewScanner(os.Stdin)

// readLines reads a whole file into memory
Expand All @@ -47,7 +47,6 @@ func readLines(path string) ([]string, error) {
}

func AssembleFilelisting(sourceFolder string, filelistingPath string, skip *string) (fullFileArray []Datafile, startTime time.Time, endTime time.Time, owner string, numFiles int64, totalSize int64) {

// scan all lines
//fmt.Println("sourceFolder,listing:", sourceFolder, filelistingPath)
fullFileArray = make([]Datafile, 0)
Expand Down Expand Up @@ -82,7 +81,7 @@ func AssembleFilelisting(sourceFolder string, filelistingPath string, skip *stri
// for windows source path add colon in the leading drive character
// windowsSource := strings.Replace(sourceFolder, "/C/", "C:/", 1)
osSource := sourceFolder
if runtime.GOOS == "windows" {
if runtime.GOOS == windows {
re := regexp.MustCompile(`^\/([A-Z])\/`)
osSource = re.ReplaceAllString(sourceFolder, "$1:/")
}
Expand Down Expand Up @@ -130,7 +129,7 @@ func AssembleFilelisting(sourceFolder string, filelistingPath string, skip *stri
uidName, gidName := GetFileOwner(f)
// replace backslashes for windows path
modpath := path
if runtime.GOOS == "windows" {
if runtime.GOOS == windows {
modpath = strings.Replace(path, "\\", "/", -1)
}
fileStruct := Datafile{Path: modpath, User: uidName, Group: gidName, Perm: f.Mode().String(), Size: f.Size(), Time: f.ModTime().Format(time.RFC3339)}
Expand All @@ -145,6 +144,7 @@ func AssembleFilelisting(sourceFolder string, filelistingPath string, skip *stri
if err != nil {
log.Printf("Could not follow symlink for file:%v %v", pabs, err)
keep = false
log.Printf("keep variable set to %v", keep)
}
}
//fmt.Printf("Skip variable:%v\n", *skip)
Expand Down Expand Up @@ -187,7 +187,6 @@ Do you want to keep the link in dataset or skip it (D(efault)/k(eep)/s(kip) ?`,
log.Printf("You chose to remove the link %v -> %v.\n\n", modpath, pointee)
}
color.Unset()

}

// make sure that filenames do not contain characters like "\" or "*"
Expand Down
Loading
Loading