Skip to content

Commit

Permalink
Merge branch 'v8' into v8
Browse files Browse the repository at this point in the history
  • Loading branch information
gururajsh committed May 23, 2024
2 parents 04c3401 + 4fb7f7c commit 2e939c0
Show file tree
Hide file tree
Showing 214 changed files with 1,016 additions and 994 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: golangci-lint

on:
push:
tags:
- "v9.*"
- "v8.*"
- "v7.*"
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main
- v9
- v8
- v7
paths-ignore:
- "doc/**"
- ".gitpod.yml"
- "README.md"

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.58
args: -v --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin
format:
name: Run go fmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set Up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Run go fmt
run: go fmt && git diff --exit-code
17 changes: 0 additions & 17 deletions .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,6 @@ defaults:
shell: bash

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Set Up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true

- name: Run go fmt
run: go fmt && git diff --exit-code

units:
name: Units
strategy:
Expand Down
14 changes: 6 additions & 8 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"run": {
"concurrency": 4,
"timeout": "20m",
"skip-files": [
"integration/helpers/fake_server.go"
]
"timeout": "20m"
},
"linters": {
"disable-all": true,
Expand All @@ -14,15 +11,16 @@
"errcheck",
"staticcheck",
"unused",
"structcheck",
"varcheck",
"ineffassign",
"deadcode"
"ineffassign"
]
},
"linters-settings": {},
"issues": {
"max-same-issue": 0,
"exclude-files": [
"integration/helpers/fake_server.go",
"command/plugin/*.go$"
],
"exclude": [
"Error return value of `client.GetApplicationTasks` is not checked",
"Error return value of `logger.output.Stop` is not checked",
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ integration-tests-full-ci: install-test-deps integration-cleanup
integration/shared/isolated integration/v7/isolated integration/shared/plugin integration/shared/experimental integration/v7/experimental integration/v7/push
$(ginkgo_int) -flake-attempts $(FLAKE_ATTEMPTS) integration/shared/global integration/v7/global

lint: ## Runs all linters and formatters
lint: format ## Runs all linters and formatters
@echo "Running linters..."
go list -f "{{.Dir}}" ./... \
| grep -v -e "/cf/" -e "/fixtures/" -e "/assets/" -e "/plugin/" -e "/command/plugin" -e "fakes" \
| xargs golangci-lint run
golangci-lint run --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin
@echo "No lint errors!"

# TODO: version specific tagging for all these builds
Expand Down Expand Up @@ -206,15 +204,13 @@ units-non-plugin: install-test-deps
@rm -f $(wildcard fixtures/plugins/*.exe)
@ginkgo version
CF_HOME=$(CURDIR)/fixtures CF_USERNAME="" CF_PASSWORD="" $(ginkgo_units) \
-skip-package integration,cf\ssh,plugin,cf\actors\plugin,cf\commands\plugin,cf\actors\plugin,util\randomword
CF_HOME=$(CURDIR)/fixtures $(ginkgo_units) -flake-attempts 3 cf/ssh
-skip-package integration,plugin,cf\actors\plugin,cf\commands\plugin,cf\actors\plugin,util\randomword
else
units-non-plugin: install-test-deps
@rm -f $(wildcard fixtures/plugins/*.exe)
@ginkgo version
CF_HOME=$(CURDIR)/fixtures CF_USERNAME="" CF_PASSWORD="" $(ginkgo_units) \
-skip-package integration,cf/ssh,plugin,cf/actors/plugin,cf/commands/plugin,cf/actors/plugin,util/randomword
CF_HOME=$(CURDIR)/fixtures $(ginkgo_units) -flake-attempts 3 cf/ssh
-skip-package integration,plugin,cf/actors/plugin,cf/commands/plugin,cf/actors/plugin,util/randomword
endif

units-full: build units-plugin units-non-plugin
Expand Down
5 changes: 2 additions & 3 deletions actor/pluginaction/checksum_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"

. "code.cloudfoundry.org/cli/actor/pluginaction"
Expand All @@ -25,11 +24,11 @@ var _ = Describe("Checksums", func() {
var file *os.File
BeforeEach(func() {
var err error
file, err = ioutil.TempFile("", "")
file, err = os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
defer file.Close()

err = ioutil.WriteFile(file.Name(), []byte("foo"), 0600)
err = os.WriteFile(file.Name(), []byte("foo"), 0600)
Expect(err).NotTo(HaveOccurred())
})

Expand Down
3 changes: 1 addition & 2 deletions actor/pluginaction/install.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pluginaction

import (
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -189,7 +188,7 @@ func (actor Actor) InstallPluginFromPath(path string, plugin configv3.Plugin) er
}

func makeTempFile(tempDir string) (*os.File, error) {
tempFile, err := ioutil.TempFile(tempDir, "")
tempFile, err := os.CreateTemp(tempDir, "")
if err != nil {
return nil, err
}
Expand Down
17 changes: 8 additions & 9 deletions actor/pluginaction/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pluginaction_test

import (
"errors"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -32,7 +31,7 @@ var _ = Describe("install actions", func() {
actor = NewActor(fakeConfig, fakeClient)

var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -46,7 +45,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand All @@ -66,7 +65,7 @@ var _ = Describe("install actions", func() {
copyPath, err := actor.CreateExecutableCopy(pluginPath, tempPluginDir)
Expect(err).ToNot(HaveOccurred())

contents, err := ioutil.ReadFile(copyPath)
contents, err := os.ReadFile(copyPath)
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(BeEquivalentTo("cthulhu"))
})
Expand Down Expand Up @@ -101,14 +100,14 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
data = []byte("some test data")
fakeClient.DownloadPluginStub = func(_ string, path string, _ plugin.ProxyReader) error {
err := ioutil.WriteFile(path, data, 0700)
err := os.WriteFile(path, data, 0700)
Expect(err).ToNot(HaveOccurred())
return nil
}
})
It("returns the path to the file and the size", func() {
Expect(downloadErr).ToNot(HaveOccurred())
fileData, err := ioutil.ReadFile(path)
fileData, err := os.ReadFile(path)
Expect(err).ToNot(HaveOccurred())
Expect(fileData).To(Equal(data))

Expand Down Expand Up @@ -139,7 +138,7 @@ var _ = Describe("install actions", func() {

When("the file exists", func() {
BeforeEach(func() {
pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -661,14 +660,14 @@ var _ = Describe("install actions", func() {
},
}

pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())

pluginPath = pluginFile.Name()

tempDir, err = ioutil.TempDir("", "")
tempDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin")
Expand Down
9 changes: 4 additions & 5 deletions actor/pluginaction/install_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -26,7 +25,7 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
fakeConfig = new(pluginactionfakes.FakeConfig)
var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
actor = NewActor(fakeConfig, nil)
})
Expand All @@ -41,7 +40,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand Down Expand Up @@ -86,14 +85,14 @@ var _ = Describe("install actions", func() {
},
}

pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())

pluginPath = pluginFile.Name()

tempDir, err = ioutil.TempDir("", "")
tempDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin")
Expand Down
5 changes: 2 additions & 3 deletions actor/pluginaction/install_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"

. "code.cloudfoundry.org/cli/actor/pluginaction"
Expand All @@ -23,7 +22,7 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
fakeConfig = new(pluginactionfakes.FakeConfig)
var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
actor = NewActor(fakeConfig, nil)
})
Expand All @@ -38,7 +37,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand Down
7 changes: 3 additions & 4 deletions actor/pluginaction/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pluginaction_test

import (
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -35,11 +34,11 @@ var _ = Describe("Plugin actor", func() {

BeforeEach(func() {
var err error
pluginHome, err = ioutil.TempDir("", "")
pluginHome, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

binaryPath = filepath.Join(pluginHome, "banana-faceman")
err = ioutil.WriteFile(binaryPath, nil, 0600)
err = os.WriteFile(binaryPath, nil, 0600)
Expect(err).ToNot(HaveOccurred())

fakePluginUninstaller = new(pluginactionfakes.FakePluginUninstaller)
Expand Down Expand Up @@ -188,7 +187,7 @@ var _ = Describe("Plugin actor", func() {
Expect(err).ToNot(HaveOccurred())
err = os.Mkdir(binaryPath, 0700)
Expect(err).ToNot(HaveOccurred())
err = ioutil.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500)
err = os.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
7 changes: 3 additions & 4 deletions actor/sharedaction/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha1"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -214,7 +213,7 @@ func (actor Actor) GatherDirectoryResources(sourceDir string) ([]Resource, error
// filemode for user is forced to be readable and executable.
func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude []Resource) (string, error) {
log.WithField("sourceArchive", sourceArchivePath).Info("zipping source files from archive")
zipFile, err := ioutil.TempFile("", "cf-cli-")
zipFile, err := os.CreateTemp("", "cf-cli-")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -274,7 +273,7 @@ func (actor Actor) ZipArchiveResources(sourceArchivePath string, filesToInclude
// filemode for user is forced to be readable and executable.
func (actor Actor) ZipDirectoryResources(sourceDir string, filesToInclude []Resource) (string, error) {
log.WithField("sourceDir", sourceDir).Info("zipping source files from directory")
zipFile, err := ioutil.TempFile("", "cf-cli-")
zipFile, err := os.CreateTemp("", "cf-cli-")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -434,7 +433,7 @@ func (Actor) generateArchiveCFIgnoreMatcher(files []*zip.File) (*ignore.GitIgnor
}
defer fileReader.Close()

raw, err := ioutil.ReadAll(fileReader)
raw, err := io.ReadAll(fileReader)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2e939c0

Please sign in to comment.