Skip to content

Commit 4c2faac

Browse files
authored
Merge pull request #136 from VinozzZ/add-staticcheck
run vet and lint in CI
2 parents e448eb7 + 92d7d98 commit 4c2faac

File tree

7 files changed

+29
-42
lines changed

7 files changed

+29
-42
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
cache-dependency-path: go.sum
2020
- name: Set up Mage
2121
run: go run mage.go EnsureMage
22+
- name: VetLint
23+
run: mage -v vet lint
2224
- name: Test
2325
run: mage -v Test
2426
env:

api/v1/porterconfig_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ func MergeMap(target, override map[string]interface{}) map[string]interface{} {
9191

9292
// SecretsConfig is the plugin stanza for secrets.
9393
type SecretsConfig struct {
94-
PluginConfig `json:",squash" yaml:",inline" mapstructure:",squash"`
94+
PluginConfig `json:",inline" yaml:",inline" mapstructure:",squash"`
9595
}
9696

9797
// StorageConfig is the plugin stanza for storage.
9898
type StorageConfig struct {
99-
PluginConfig `json:",squash" yaml:",inline" mapstructure:",squash"`
99+
PluginConfig `json:",inline" yaml:",inline" mapstructure:",squash"`
100100
}
101101

102102
// PluginConfig is a standardized config stanza that defines which plugin to

controllers/agentaction_controller.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,9 @@ func (r *AgentActionReconciler) applyJobToStatus(log logr.Logger, action *porter
170170
case batchv1.JobComplete:
171171
action.Status.Phase = porterv1.PhaseSucceeded
172172
setCondition(log, action, porterv1.ConditionComplete, "JobCompleted")
173-
break
174173
case batchv1.JobFailed:
175174
action.Status.Phase = porterv1.PhaseFailed
176175
setCondition(log, action, porterv1.ConditionFailed, "JobFailed")
177-
break
178176
}
179177
}
180178
}
@@ -628,9 +626,7 @@ func (r *AgentActionReconciler) getAgentEnv(action *porterv1.AgentAction, agentC
628626
},
629627
}
630628

631-
for _, e := range action.Spec.Env {
632-
env = append(env, e)
633-
}
629+
env = append(env, action.Spec.Env...)
634630

635631
envFrom := []corev1.EnvFromSource{
636632
// Environment variables for the plugins
@@ -644,9 +640,7 @@ func (r *AgentActionReconciler) getAgentEnv(action *porterv1.AgentAction, agentC
644640
},
645641
}
646642

647-
for _, e := range action.Spec.EnvFrom {
648-
envFrom = append(envFrom, e)
649-
}
643+
envFrom = append(envFrom, action.Spec.EnvFrom...)
650644

651645
return env, envFrom
652646
}
@@ -714,13 +708,9 @@ func (r *AgentActionReconciler) getAgentVolumes(action *porterv1.AgentAction, pv
714708
)
715709
}
716710

717-
for _, volume := range action.Spec.Volumes {
718-
volumes = append(volumes, volume)
719-
}
711+
volumes = append(volumes, action.Spec.Volumes...)
720712

721-
for _, mount := range action.Spec.VolumeMounts {
722-
volumeMounts = append(volumeMounts, mount)
723-
}
713+
volumeMounts = append(volumeMounts, action.Spec.VolumeMounts...)
724714

725715
return volumes, volumeMounts
726716
}

mage/docs/docs.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package docs
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"log"
87
"net/http"
98
"os"
@@ -70,7 +69,7 @@ func TriggerNetlifyDeployment(webhook string) error {
7069

7170
if r.StatusCode >= 300 {
7271
defer r.Body.Close()
73-
msg, _ := ioutil.ReadAll(r.Body)
72+
msg, _ := io.ReadAll(r.Body)
7473
return fmt.Errorf("request failed (%d) %s: %s", r.StatusCode, r.Status, msg)
7574
}
7675

mage/docs/docs_test.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package docs
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -12,39 +11,30 @@ import (
1211

1312
func TestEnsurePorterRepository(t *testing.T) {
1413
t.Run("has local repo", func(t *testing.T) {
15-
tmp, err := ioutil.TempDir("", "porter-docs-test")
16-
require.NoError(t, err)
17-
defer os.RemoveAll(tmp)
14+
tmp := t.TempDir()
1815

1916
resolvedPath, err := ensurePorterRepositoryIn(tmp, "")
2017
require.NoError(t, err)
2118
require.Equal(t, tmp, resolvedPath)
2219
})
2320

2421
t.Run("missing local repo", func(t *testing.T) {
25-
tmp, err := ioutil.TempDir("", "porter-docs-test")
26-
require.NoError(t, err)
27-
defer os.RemoveAll(tmp)
22+
tmp := t.TempDir()
2823

2924
resolvedPath, err := ensurePorterRepositoryIn("missing", tmp)
3025
require.NoError(t, err)
3126
require.Equal(t, tmp, resolvedPath)
3227
})
3328

3429
t.Run("local repo unset", func(t *testing.T) {
35-
tmp, err := ioutil.TempDir("", "porter-docs-test")
36-
require.NoError(t, err)
37-
defer os.RemoveAll(tmp)
38-
30+
tmp := t.TempDir()
3931
resolvedPath, err := ensurePorterRepositoryIn("", tmp)
4032
require.NoError(t, err)
4133
require.Equal(t, tmp, resolvedPath)
4234
})
4335

4436
t.Run("empty default path clones repo", func(t *testing.T) {
45-
tmp, err := ioutil.TempDir("", "porter-docs-test")
46-
require.NoError(t, err)
47-
defer os.RemoveAll(tmp)
37+
tmp := t.TempDir()
4838

4939
resolvedPath, err := ensurePorterRepositoryIn("", tmp)
5040
require.NoError(t, err)
@@ -55,9 +45,7 @@ func TestEnsurePorterRepository(t *testing.T) {
5545
})
5646

5747
t.Run("changes in default path are reset", func(t *testing.T) {
58-
tmp, err := ioutil.TempDir("", "porter-docs-test")
59-
require.NoError(t, err)
60-
defer os.RemoveAll(tmp)
48+
tmp := t.TempDir()
6149

6250
repoPath, err := ensurePorterRepositoryIn("", tmp)
6351
require.NoError(t, err)
@@ -67,7 +55,7 @@ func TestEnsurePorterRepository(t *testing.T) {
6755
require.NoError(t, os.Remove(readme))
6856

6957
// Make sure rerunning resets the change
70-
repoPath, err = ensurePorterRepositoryIn("", tmp)
58+
_, err = ensurePorterRepositoryIn("", tmp)
7159
require.NoError(t, err)
7260
require.FileExists(t, readme)
7361
})

magefiles/magefile.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bufio"
99
"bytes"
1010
"fmt"
11-
"io/ioutil"
1211
"log"
1312
"os"
1413
"path/filepath"
@@ -77,7 +76,7 @@ func addGopathBinOnGithubActions() error {
7776

7877
log.Println("Adding GOPATH/bin to the PATH for the GitHub Actions Agent")
7978
gopathBin := gopath.GetGopathBin()
80-
return ioutil.WriteFile(githubPath, []byte(gopathBin), 0644)
79+
return os.WriteFile(githubPath, []byte(gopathBin), 0644)
8180
}
8281

8382
// Ensure EnsureMage is installed and on the PATH.
@@ -93,6 +92,11 @@ func Vet() {
9392
must.RunV("go", "vet", "./...")
9493
}
9594

95+
func Lint() {
96+
mg.Deps(tools.EnsureStaticCheck)
97+
must.RunV("staticcheck", "./...")
98+
}
99+
96100
// Build the controller and bundle.
97101
func Build() {
98102
mg.SerialDeps(BuildController, BuildBundle)
@@ -428,7 +432,7 @@ func Bump(sample string) {
428432

429433
sampleFile := fmt.Sprintf("config/samples/%s.yaml", sample)
430434

431-
dataB, err := ioutil.ReadFile(sampleFile)
435+
dataB, err := os.ReadFile(sampleFile)
432436
mgx.Must(errors.Wrapf(err, "error reading installation definition %s", sampleFile))
433437

434438
updateRetry := fmt.Sprintf(`.metadata.annotations."porter.sh/retry" = "%s"`, time.Now().Format(time.RFC3339))
@@ -570,7 +574,7 @@ func useCluster() bool {
570574
}
571575
os.Setenv("KUBECONFIG", currentKubeConfig)
572576

573-
err := ioutil.WriteFile(kubeconfig, []byte(contents), 0644)
577+
err := os.WriteFile(kubeconfig, []byte(contents), 0644)
574578
mgx.Must(errors.Wrapf(err, "error writing %s", kubeconfig))
575579

576580
setClusterNamespace(operatorNamespace)
@@ -663,7 +667,7 @@ func BuildLocalPorterAgent() {
663667

664668
// generatedCodeFilter remove generated code files from coverage report
665669
func generatedCodeFilter(filename string) error {
666-
fd, err := ioutil.ReadFile(filename)
670+
fd, err := os.ReadFile(filename)
667671
if err != nil {
668672
return err
669673
}
@@ -677,7 +681,7 @@ func generatedCodeFilter(filename string) error {
677681
}
678682

679683
fd = []byte(strings.Join(lines, "\n"))
680-
err = ioutil.WriteFile(filename, fd, 0600)
684+
err = os.WriteFile(filename, fd, 0600)
681685
if err != nil {
682686
return err
683687
}

staticcheck.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Default Config
2+
checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023", "-ST1005"]
3+
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
4+
http_status_code_whitelist = ["200", "400", "404", "500"]

0 commit comments

Comments
 (0)