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

enable golangci #718

Merged
merged 10 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: golangci-lint

on:
push:
branches:
- master
- main
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.60.1

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
args: --timeout=30m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
15 changes: 9 additions & 6 deletions integration/fabric/atsa/chaincode/views/seller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ func (a *TransferView) Call(ctx view.Context) (interface{}, error) {
assetProperties, err := a.AssetProperties.Bytes()
assert.NoError(err, "failed marshalling assetProperties")

envelope, err := ch.Chaincode("asset_transfer").Endorse(
endorse, err := ch.Chaincode("asset_transfer").Endorse(
"TransferAsset",
a.AssetProperties.ID,
recipientMSPID,
).WithTransientEntry(
"asset_price", assetPrice,
).WithTransientEntry(
"asset_properties", assetProperties,
).WithImplicitCollections(senderMSPID, recipientMSPID).Call()
).WithImplicitCollections(
senderMSPID, recipientMSPID,
).WithTransientEntries(map[string]interface{}{
"asset_price": assetPrice,
"asset_properties": assetProperties,
})
assert.NoError(err, "failed agreeing to sell")
envelope, err := endorse.Call()
assert.NoError(err, "failed asking endorsement")

c, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface)
fmt.Println("Init Function Invoked")
}

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) {
ctx.GetStub().SetEvent("CreateAsset", []byte("Invoked Create Asset Successfully"))
func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) error {
return ctx.GetStub().SetEvent("CreateAsset", []byte("Invoked Create Asset Successfully"))

}

func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface) {
ctx.GetStub().SetEvent("UpdateAsset", []byte("Invoked Update Asset Successfully"))
func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface) error {
return ctx.GetStub().SetEvent("UpdateAsset", []byte("Invoked Update Asset Successfully"))
}
8 changes: 4 additions & 4 deletions integration/fabric/events/chaincode/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func (s *TestSuite) TestSingleChaincodeEvents() {

Expect(err).ToNot(HaveOccurred())
eventReceived := &views.EventReceived{}
json.Unmarshal(event.([]byte), eventReceived)
Expect(json.Unmarshal(event.([]byte), eventReceived)).ToNot(HaveOccurred())
Expect(string(eventReceived.Event.Payload)).To(Equal("Invoked Create Asset Successfully"))

// - Operate from Bob (Org2)
event, err = bob.EventsView("UpdateAsset", "UpdateAsset")
Expect(err).ToNot(HaveOccurred())
eventReceived = &views.EventReceived{}
json.Unmarshal(event.([]byte), eventReceived)
Expect(json.Unmarshal(event.([]byte), eventReceived)).ToNot(HaveOccurred())
Expect(string(eventReceived.Event.Payload)).To(Equal("Invoked Update Asset Successfully"))
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func (s *TestSuite) TestUpgradeChaincode() {
event, err := alice.EventsView("CreateAsset", "CreateAsset")
Expect(err).ToNot(HaveOccurred())
eventReceived := &views.EventReceived{}
json.Unmarshal(event.([]byte), eventReceived)
Expect(json.Unmarshal(event.([]byte), eventReceived)).ToNot(HaveOccurred())
Expect(string(eventReceived.Event.Payload)).To(Equal("Invoked Create Asset Successfully"))

// Update
Expand All @@ -128,6 +128,6 @@ func (s *TestSuite) TestUpgradeChaincode() {
event, err = alice.EventsView("CreateAsset", "CreateAsset")
Expect(err).ToNot(HaveOccurred())
eventReceived = &views.EventReceived{}
json.Unmarshal(event.([]byte), eventReceived)
Expect(json.Unmarshal(event.([]byte), eventReceived)).ToNot(HaveOccurred())
Expect(string(eventReceived.Event.Payload)).To(Equal("Invoked Create Asset Successfully From Upgraded Chaincode"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface)
fmt.Println("Init Function Invoked")
}

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) {
ctx.GetStub().SetEvent("CreateAsset", []byte("Invoked Create Asset Successfully From Upgraded Chaincode"))

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) error {
return ctx.GetStub().SetEvent("CreateAsset", []byte("Invoked Create Asset Successfully From Upgraded Chaincode"))
}
4 changes: 2 additions & 2 deletions integration/fsc/pingpong/pingpong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("EndToEnd", func() {
// Register views and view factories
err = initiator.RegisterFactory("init", &pingpong.InitiatorViewFactory{})
Expect(err).NotTo(HaveOccurred())
responder.RegisterResponder(&pingpong.Responder{}, &pingpong.Initiator{})
Expect(responder.RegisterResponder(&pingpong.Responder{}, &pingpong.Initiator{})).NotTo(HaveOccurred())

time.Sleep(3 * time.Second)

Expand Down Expand Up @@ -126,7 +126,7 @@ var _ = Describe("EndToEnd", func() {
// Register views and view factories
err = initiator.RegisterFactory("init", &pingpong.InitiatorViewFactory{})
Expect(err).NotTo(HaveOccurred())
responder.RegisterResponder(&pingpong.Responder{}, &pingpong.Initiator{})
Expect(responder.RegisterResponder(&pingpong.Responder{}, &pingpong.Initiator{})).NotTo(HaveOccurred())

time.Sleep(3 * time.Second)
// Initiate a view and check the output
Expand Down
10 changes: 7 additions & 3 deletions integration/nwo/cmd/cryptogen/msp/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func GenerateLocalMSP(baseDir, name string, sans []string, signCA, tlsCA *ca2.CA

// generate config.yaml if required
if nodeOUs {
exportConfig(mspDir, filepath.Join("cacerts", x509Filename(signCA.Name)), true)
if err := exportConfig(mspDir, filepath.Join("cacerts", x509Filename(signCA.Name)), true); err != nil {
return errors.WithMessagef(err, "failed to export cacerts config")
}
}

// the signing identity goes into admincerts.
Expand Down Expand Up @@ -207,7 +209,9 @@ func GenerateVerifyingMSP(

// generate config.yaml if required
if nodeOUs {
exportConfig(baseDir, "cacerts/"+x509Filename(signCA.Name), true)
if err := exportConfig(baseDir, "cacerts/"+x509Filename(signCA.Name), true); err != nil {
return errors.WithMessagef(err, "failed to export cacerts config")
}
}

// create a throwaway cert to act as an admin cert
Expand Down Expand Up @@ -274,7 +278,7 @@ func keyExport(keystore, output string) error {
}

func pemExport(path, pemType string, bytes []byte) error {
//write pem out to file
// write pem out to file
file, err := os.Create(path)
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions integration/nwo/common/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
Expand Down Expand Up @@ -64,7 +65,9 @@ func (s *BuildServer) Serve() {
Expect(err).NotTo(HaveOccurred())

s.lis = lis
go s.server.Serve(lis)
go utils.IgnoreErrorFunc(func() error {
return s.server.Serve(lis)
})
}

func (s *BuildServer) Shutdown(deleteOnStop bool) {
Expand All @@ -74,7 +77,7 @@ func (s *BuildServer) Shutdown(deleteOnStop bool) {
defer gexec.CleanupBuildArtifacts()
}

s.server.Shutdown(ctx)
utils.IgnoreError(s.server.Shutdown(ctx))
}

func (s *BuildServer) Client() *BuilderClient {
Expand Down
7 changes: 4 additions & 3 deletions integration/nwo/common/pkcs11/pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/pkcs11"
Expand Down Expand Up @@ -153,7 +154,7 @@ func ListTokens(opts *config.PKCS11) ([]pkcs11lib.TokenInfo, error) {
if ctx == nil {
return nil, errors.Errorf("pkcs11: instantiation failed for %s", opts.Library)
}
defer ctx.Finalize()
defer utils.IgnoreError(ctx.Finalize())
if err := ctx.Initialize(); err != nil {
return nil, errors.Errorf("pkcs11: initialization failed: %v", err)
}
Expand Down Expand Up @@ -186,7 +187,7 @@ func CheckToken(opts *config.PKCS11) error {
if ctx == nil {
return errors.Errorf("pkcs11: instantiation failed for %s", opts.Library)
}
defer ctx.Finalize()
defer utils.IgnoreError(ctx.Finalize())
if err := ctx.Initialize(); err != nil && !strings.Contains(err.Error(), "CKR_CRYPTOKI_ALREADY_INITIALIZED") {
return errors.Errorf("pkcs11: initialization failed: %v", err)
}
Expand Down Expand Up @@ -233,7 +234,7 @@ func CheckToken(opts *config.PKCS11) error {
if err != nil {
return errors.Wrap(err, "pkcs11: open session")
}
defer ctx.CloseSession(sess)
defer utils.IgnoreError(ctx.CloseSession(sess))
if err := ctx.Login(sess, pkcs11lib.CKU_USER, opts.Pin); err != nil {
return errors.Wrap(err, "pkcs11: login")
}
Expand Down
13 changes: 8 additions & 5 deletions integration/nwo/common/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
Expand Down Expand Up @@ -122,7 +123,7 @@ func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error {
startCheckTimeout = time.After(startCheckDuration)
}

detectStartCheck = allOutput.Detect(r.StartCheck)
detectStartCheck = allOutput.Detect("%s", r.StartCheck)

for {
select {
Expand All @@ -131,13 +132,13 @@ func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error {
startCheckTimeout = nil
detectStartCheck = nil
// close our buffer that is used to detect ready state
allOutput.Close()
allOutput.Clear()
utils.IgnoreError(allOutput.Close())
utils.IgnoreError(allOutput.Clear())
close(ready)

case <-startCheckTimeout:
// clean up hanging process
r.Command.Process.Signal(syscall.SIGKILL)
Expect(r.Command.Process.Signal(syscall.SIGKILL)).ToNot(HaveOccurred())
EventuallyWithOffset(1, r).Should(gexec.Exit())

// fail to start
Expand All @@ -149,7 +150,9 @@ func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error {
)

case signal := <-sigChan:
r.Command.Process.Signal(signal)
if err := r.Command.Process.Signal(signal); err != nil {
logger.Errorf("failed to send signal to process: %s", err)
}

case <-exited:
if r.Cleanup != nil {
Expand Down
4 changes: 2 additions & 2 deletions integration/nwo/fabric/network/network_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (n *Network) ConcatenateTLSCACertificates() {
// network, across all organizations.
func (n *Network) ListTLSCACertificates() []string {
fileName2Path := make(map[string]string)
filepath.Walk(filepath.Join(n.Context.RootDir(), n.Prefix, "crypto"), func(path string, info os.FileInfo, err error) error {
Expect(filepath.Walk(filepath.Join(n.Context.RootDir(), n.Prefix, "crypto"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand All @@ -663,7 +663,7 @@ func (n *Network) ListTLSCACertificates() []string {
fileName2Path[info.Name()] = path
}
return nil
})
})).ToNot(HaveOccurred())

var tlsCACertificates []string
for _, path := range fileName2Path {
Expand Down
Loading
Loading