Skip to content

Commit ea821ed

Browse files
committed
ci(tidy): add tidy check and format codebase (#170)
Add `make tidy` target that runs several Go source code file formatting checks. Add CI job to verify code formatting is correct. Remove redundant `make lint` and `make golines` targets and CI jobs. Change default `make` target to display help. Apply formatting across the codebase.
1 parent da0989a commit ea821ed

65 files changed

Lines changed: 1583 additions & 432 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
with:
8080
token: ${{ secrets.CODECOV_TOKEN }}
8181

82-
go-lint:
82+
go-tidy:
8383
runs-on: ubuntu-24.04
8484
steps:
8585
- uses: actions/checkout@v4
@@ -89,30 +89,13 @@ jobs:
8989
with:
9090
go-version: '>=1.18.X'
9191

92-
- name: Run lint action
93-
uses: golangci/golangci-lint-action@v4
94-
with:
95-
version: latest
96-
args: --enable=gofmt --enable=goimports
97-
98-
go-lines:
99-
runs-on: ubuntu-24.04
100-
steps:
101-
- uses: actions/checkout@v4
102-
103-
- name: Setup Go
104-
uses: actions/setup-go@v5
105-
with:
106-
go-version: '>=1.18.X'
107-
108-
- name: Run golines
92+
- name: Check code formatting
10993
run: |
110-
if [[ $(make golines | wc -l) -gt 2 ]]; then
111-
echo "Golines would make the following changes:"
112-
make golines
94+
make tidy
95+
if [[ -n $(git status --porcelain) ]]; then
96+
echo "Code is not properly formatted. Please run 'make tidy' locally."
97+
git diff
11398
exit 1
114-
else
115-
echo "No file exceeds the line size limit"
11699
fi
117100
118101
go-audit:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (C) 2022, 2023, 2024 CERN.
3+
Copyright (C) 2022, 2023, 2024, 2025, 2026 CERN.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
SWAGGER := docker run --rm -it -e GOPATH=$(shell go env GOPATH):/go -v $(HOME):$(HOME) -w $(shell pwd) --pull always quay.io/goswagger/swagger
1010

11-
all: build
11+
all: help
1212

1313
audit: # Run quality control checks.
1414
go install honnef.co/go/tools/cmd/staticcheck@latest
@@ -45,16 +45,16 @@ swagger-validate-specs: # Validate OpenAPI specification.
4545
test: # Run test suite.
4646
go test -coverprofile coverage.txt ./cmd/... ./pkg/...
4747

48+
tidy: # Format code and tidy go.mod.
49+
go install github.com/segmentio/golines@latest
50+
go install golang.org/x/tools/cmd/goimports@latest
51+
go fmt ./...
52+
goimports -w .
53+
golines -w -m 80 -t 4 .
54+
go mod tidy
55+
4856
update: # Update go module dependencies.
4957
go get -u
5058
go mod tidy
5159

52-
lint: # Run lint checks
53-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
54-
golangci-lint run --enable=gofmt --enable=goimports
55-
56-
golines: # Run line size checks
57-
go install github.com/segmentio/golines@latest
58-
golines --dry-run ./
59-
60-
.PHONY: all audit build clean help release swagger-generate-client swagger-validate-specs test update lint golines
60+
.PHONY: all audit build clean help release swagger-generate-client swagger-validate-specs test tidy update

client/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func ApiClient() (*API, error) {
2929
return nil, err
3030
}
3131
if u.Host == "" {
32-
return nil, errors.New("environment variable REANA_SERVER_URL is not set")
32+
return nil, errors.New(
33+
"environment variable REANA_SERVER_URL is not set",
34+
)
3335
}
3436

3537
// create the transport

cmd/close.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,18 @@ func newCloseCmd() *cobra.Command {
5151
}
5252

5353
f := cmd.Flags()
54-
f.StringVarP(&o.token, "access-token", "t", "", "Access token of the current user.")
54+
f.StringVarP(
55+
&o.token,
56+
"access-token",
57+
"t",
58+
"",
59+
"Access token of the current user.",
60+
)
5561
f.StringVarP(
5662
&o.workflow,
5763
"workflow",
58-
"w", "",
64+
"w",
65+
"",
5966
"Name or UUID of the workflow. Overrides value of REANA_WORKON environment variable.",
6067
)
6168

@@ -78,7 +85,10 @@ func (o *closeOptions) run(cmd *cobra.Command) error {
7885
}
7986

8087
displayer.DisplayMessage(
81-
fmt.Sprintf("Interactive session for workflow %s was successfully closed", o.workflow),
88+
fmt.Sprintf(
89+
"Interactive session for workflow %s was successfully closed",
90+
o.workflow,
91+
),
8292
displayer.Success,
8393
false,
8494
cmd.OutOrStdout(),

cmd/close_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func TestClose(t *testing.T) {
3737
responseFile: "close_no_open.json",
3838
},
3939
},
40-
args: []string{"-w", "my_workflow"},
41-
expected: []string{"Workflow - my_workflow has no open interactive session."},
40+
args: []string{"-w", "my_workflow"},
41+
expected: []string{
42+
"Workflow - my_workflow has no open interactive session.",
43+
},
4244
wantError: true,
4345
},
4446
}

cmd/completion.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func newCompletionCmd() *cobra.Command {
6565
Long: completionLongDesc,
6666
DisableFlagsInUseLine: true,
6767
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
68-
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
68+
Args: cobra.MatchAll(
69+
cobra.ExactArgs(1),
70+
cobra.OnlyValidArgs,
71+
),
6972
RunE: func(cmd *cobra.Command, args []string) error {
7073
switch args[0] {
7174
case "bash":

cmd/delete.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,27 @@ func newDeleteCmd() *cobra.Command {
5353
}
5454

5555
f := cmd.Flags()
56-
f.StringVarP(&o.token, "access-token", "t", "", "Access token of the current user.")
56+
f.StringVarP(
57+
&o.token,
58+
"access-token",
59+
"t",
60+
"",
61+
"Access token of the current user.",
62+
)
5763
f.StringVarP(
5864
&o.workflow,
5965
"workflow",
60-
"w", "",
66+
"w",
67+
"",
6168
"Name or UUID of the workflow. Overrides value of REANA_WORKON environment variable.",
6269
)
63-
f.BoolVarP(&o.includeWorkspace, "include-workspace", "", true, "Delete workspace from REANA.")
70+
f.BoolVarP(
71+
&o.includeWorkspace,
72+
"include-workspace",
73+
"",
74+
true,
75+
"Delete workspace from REANA.",
76+
)
6477
f.BoolVarP(
6578
&o.includeAllRuns,
6679
"include-all-runs",
@@ -87,14 +100,22 @@ func (o *deleteOptions) run(cmd *cobra.Command) error {
87100
var message string
88101
if o.includeAllRuns {
89102
name, _ := workflows.GetNameAndRunNumber(o.workflow)
90-
message = fmt.Sprintf("All workflows named '%s' have been deleted", name)
103+
message = fmt.Sprintf(
104+
"All workflows named '%s' have been deleted",
105+
name,
106+
)
91107
} else {
92108
message, err = workflows.StatusChangeMessage(o.workflow, "deleted")
93109
if err != nil {
94110
return err
95111
}
96112
}
97-
displayer.DisplayMessage(message, displayer.Success, false, cmd.OutOrStdout())
113+
displayer.DisplayMessage(
114+
message,
115+
displayer.Success,
116+
false,
117+
cmd.OutOrStdout(),
118+
)
98119

99120
return nil
100121
}

cmd/diff.go

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,27 @@ func newDiffCmd() *cobra.Command {
6464
}
6565

6666
f := cmd.Flags()
67-
f.StringVarP(&o.token, "access-token", "t", "", "Access token of the current user.")
68-
f.BoolVarP(&o.brief, "brief", "q", false, `If not set, differences in the contents of the
69-
files in the two workspaces are shown.`)
67+
f.StringVarP(
68+
&o.token,
69+
"access-token",
70+
"t",
71+
"",
72+
"Access token of the current user.",
73+
)
74+
f.BoolVarP(
75+
&o.brief,
76+
"brief",
77+
"q",
78+
false,
79+
`If not set, differences in the contents of the
80+
files in the two workspaces are shown.`,
81+
)
7082
f.IntVarP(
71-
&o.unified, "unified", "u", 5, "Sets number of context lines for workspace diff output.",
83+
&o.unified,
84+
"unified",
85+
"u",
86+
5,
87+
"Sets number of context lines for workspace diff output.",
7288
)
7389

7490
return cmd
@@ -100,7 +116,10 @@ func (o *diffOptions) run(cmd *cobra.Command) error {
100116
return nil
101117
}
102118

103-
func displayDiffPayload(cmd *cobra.Command, p *operations.GetWorkflowDiffOKBody) error {
119+
func displayDiffPayload(
120+
cmd *cobra.Command,
121+
p *operations.GetWorkflowDiffOKBody,
122+
) error {
104123
if p.ReanaSpecification != "" {
105124
specificationDiff := orderedmap.New()
106125
err := json.Unmarshal([]byte(p.ReanaSpecification), &specificationDiff)
@@ -120,21 +139,31 @@ func displayDiffPayload(cmd *cobra.Command, p *operations.GetWorkflowDiffOKBody)
120139
sectionDiffs, _ := specificationDiff.Get(section)
121140
linesInterface, ok := sectionDiffs.([]any)
122141
if !ok {
123-
return fmt.Errorf("expected diff to be an array, got %v", sectionDiffs)
142+
return fmt.Errorf(
143+
"expected diff to be an array, got %v",
144+
sectionDiffs,
145+
)
124146
}
125147
lines := make([]string, 0, len(linesInterface))
126148
for _, line := range linesInterface {
127149
lineString, ok := line.(string)
128150
if !ok {
129-
return fmt.Errorf("expected diff line to be a string, got %v", line)
151+
return fmt.Errorf(
152+
"expected diff line to be a string, got %v",
153+
line,
154+
)
130155
}
131156
lines = append(lines, lineString)
132157
}
133158

134159
if len(lines) != 0 {
135160
equalSpecification = false
136161
displayer.PrintColorable(
137-
fmt.Sprintf("%s Differences in workflow %s\n", config.LeadingMark, section),
162+
fmt.Sprintf(
163+
"%s Differences in workflow %s\n",
164+
config.LeadingMark,
165+
section,
166+
),
138167
cmd.OutOrStdout(),
139168
text.FgYellow,
140169
text.Bold,
@@ -144,7 +173,10 @@ func displayDiffPayload(cmd *cobra.Command, p *operations.GetWorkflowDiffOKBody)
144173
}
145174
if equalSpecification {
146175
displayer.PrintColorable(
147-
fmt.Sprintf("%s No differences in REANA specifications.\n", config.LeadingMark),
176+
fmt.Sprintf(
177+
"%s No differences in REANA specifications.\n",
178+
config.LeadingMark,
179+
),
148180
cmd.OutOrStdout(),
149181
text.FgYellow,
150182
text.Bold,
@@ -162,7 +194,10 @@ func displayDiffPayload(cmd *cobra.Command, p *operations.GetWorkflowDiffOKBody)
162194
workspaceDiff := datautils.SplitLinesNoEmpty(workspaceDiffRaw)
163195

164196
displayer.PrintColorable(
165-
fmt.Sprintf("%s Differences in workflow workspace\n", config.LeadingMark),
197+
fmt.Sprintf(
198+
"%s Differences in workflow workspace\n",
199+
config.LeadingMark,
200+
),
166201
cmd.OutOrStdout(),
167202
text.FgYellow,
168203
text.Bold,

cmd/diff_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,18 @@ func TestPrintDiff(t *testing.T) {
141141
expectedColors: []text.Color{text.FgGreen},
142142
},
143143
"mixed text": {
144-
lines: []string{"@@ -1 +1 @@", "context", "- removed text", "+ added text"},
145-
expectedColors: []text.Color{text.FgCyan, text.Reset, text.FgRed, text.FgGreen},
144+
lines: []string{
145+
"@@ -1 +1 @@",
146+
"context",
147+
"- removed text",
148+
"+ added text",
149+
},
150+
expectedColors: []text.Color{
151+
text.FgCyan,
152+
text.Reset,
153+
text.FgRed,
154+
text.FgGreen,
155+
},
146156
},
147157
}
148158

@@ -153,11 +163,19 @@ func TestPrintDiff(t *testing.T) {
153163
result := datautils.SplitLinesNoEmpty(resBuf.String())
154164

155165
if len(result) != len(test.lines) {
156-
t.Fatalf("Expected %d lines, got %d", len(test.lines), len(result))
166+
t.Fatalf(
167+
"Expected %d lines, got %d",
168+
len(test.lines),
169+
len(result),
170+
)
157171
}
158172
for i, line := range result {
159173
testBuf := new(bytes.Buffer)
160-
displayer.PrintColorable(test.lines[i], testBuf, test.expectedColors[i])
174+
displayer.PrintColorable(
175+
test.lines[i],
176+
testBuf,
177+
test.expectedColors[i],
178+
)
161179
expected := testBuf.String()
162180
if line != expected {
163181
t.Errorf("Expected %s, got %s", expected, line)

0 commit comments

Comments
 (0)