Skip to content

Commit

Permalink
ci(actions): add a job to run golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Apr 4, 2021
1 parent 8a527b0 commit eac51ad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
38 changes: 27 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,65 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
goVer: [1.12, 1.13, 1.14, 1.15, 1.16]
## Defines the platform for each test run
# Defines the platform for each test run.
runs-on: ${{ matrix.os }}
steps:
## the steps that will be run through for each version and platform
## combination
# The steps that will be run through for each version and platform combination.
- name: Set up Go ${{ matrix.goVer }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.goVer }}
## checks out our code locally so we can work with the files
# Checks out our code locally so we can work with the files.
- name: Checkout code
uses: actions/checkout@v2

# Caches downloaded modules
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
## runs go test ./...
# Runs go test ./...
- name: Test
run: go test -v ./...

coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
## Installs go
# Using a sigle version
# Installs go.
# Using a sigle version.
- name: Install Go
if: success()
uses: actions/setup-go@v2
with:
go-version: 1.16.x
## checks out our code locally so we can work with the files
# Checks out our code locally so we can work with the files.
- name: Checkout code
uses: actions/checkout@v2
## run the test coverage command
## Runs the test coverage command.
- name: Calc coverage
run: |
go test -v -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

lint:
runs-on: ubuntu-latest
steps:
# Installs go using a sigle version.
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
# Checks out our code locally so we can work with the files.
- name: Checkout code
uses: actions/checkout@v2
# Runs the default linters provided by golangci-lint plus golint and godot.
- name: Run linters
uses: golangci/golangci-lint-action@v2
with:
version: v1.39
args: --enable=golint --enable=godot
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/viper"
)

// Define all the global flags.
var (
cfgFile string
driver string
Expand All @@ -38,7 +39,7 @@ var (
ssl string
)

// NewRootCmd returns the root command
// NewRootCmd returns the root command.
func NewRootCmd() *cobra.Command {
return &cobra.Command{
Use: "dblab",
Expand All @@ -57,7 +58,7 @@ func NewRootCmd() *cobra.Command {
}
}

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = NewRootCmd()

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -75,7 +76,7 @@ func init() {

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dblab.yaml)")

// global flags used to open a database connection
// global flags used to open a database connection.
rootCmd.Flags().StringVarP(&driver, "driver", "", "postgres", "Database driver")
rootCmd.Flags().StringVarP(&url, "url", "u", "", "Database connection string")
rootCmd.Flags().StringVarP(&host, "host", "", "localhost", "Server host name or IP")
Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/spf13/cobra"
)

// NewVersionCmd return a versionCmd instance
// NewVersionCmd return a versionCmd instance.
func NewVersionCmd() *cobra.Command {

// versionCmd represents the version command
// versionCmd represents the version command.
versionCmd := &cobra.Command{
Use: "version",
Short: "The version of the project",
Expand Down
6 changes: 5 additions & 1 deletion cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ func TestVersionCmd(t *testing.T) {
cmd := NewVersionCmd()
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.Execute()
err := cmd.Execute()
if err != nil {
t.Fatal(err)
}

out, err := ioutil.ReadAll(b)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit eac51ad

Please sign in to comment.