From 731e2d789d1b445ac986f2bb45e0dba627a50196 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Fri, 14 Mar 2025 05:24:46 +0100 Subject: [PATCH] ci: add go lint --- .github/workflows/lint.yml | 23 +++++++++++++++++++++++ pkg/backup.go | 3 ++- pkg/helper.go | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..445e2be --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + lint: + name: Run on Ubuntu + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Run linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 diff --git a/pkg/backup.go b/pkg/backup.go index f0758b7..e4009ff 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -27,6 +27,7 @@ package pkg import ( "bytes" + "errors" "fmt" "github.com/jkaninda/encryptor" "github.com/jkaninda/go-storage/pkg/local" @@ -388,7 +389,7 @@ func listDatabases(db dbConfig) ([]string, error) { databases := []string{} // Create the mysql client config file if err := createMysqlClientConfigFile(db); err != nil { - return databases, fmt.Errorf(err.Error()) + return databases, errors.New(err.Error()) } utils.Info("Listing databases...") // Step 1: List all databases diff --git a/pkg/helper.go b/pkg/helper.go index 4019467..298dd1e 100644 --- a/pkg/helper.go +++ b/pkg/helper.go @@ -26,6 +26,7 @@ package pkg import ( "bytes" + "errors" "fmt" goutils "github.com/jkaninda/go-utils" "github.com/jkaninda/mysql-bkup/utils" @@ -70,14 +71,13 @@ func deleteTemp() { func testDatabaseConnection(db *dbConfig) error { // Create the mysql client config file if err := createMysqlClientConfigFile(*db); err != nil { - return fmt.Errorf(err.Error()) + return errors.New(err.Error()) } utils.Info("Connecting to %s database ...", db.dbName) // Set database name for notification error utils.DatabaseName = db.dbName // Prepare the command to test the database connection - //cmd := exec.Command("mariadb", "-h", db.dbHost, "-P", db.dbPort, "-u", db.dbUserName, db.dbName, "-e", "quit") cmd := exec.Command("mariadb", fmt.Sprintf("--defaults-file=%s", mysqlClientConfig), db.dbName, "-e", "quit") // Capture the output var out bytes.Buffer