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

Add test and CI #5

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
55 changes: 55 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:

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-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
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.54

# 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 --config=/my/path/.golangci.yml --issues-exit-code=0
args: --timeout=3m -v

# 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"
2 changes: 1 addition & 1 deletion .github/workflows/release-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
release-binary:
name: Release Go Binary
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: codecov

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage.txt
175 changes: 175 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
### Config GolangCI

# Options for analysis running.
run:
# The default concurrency value is the number of available CPU.
concurrency: 2

# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 2

# Include test files or not.
# Default: true
tests: false

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
#
# Allowed values: readonly|vendor|mod
# By default, it isn't set.
modules-download-mode: readonly

# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: false

# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
go: '1.18'


# output configuration options
output:
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.xml,json:stdout,colored-line-number"
#
# Default: colored-line-number
format: json

# Print lines of code with issue.
# Default: true
print-issued-lines: false
# Print linter name in the end of issue text.
# Default: true
print-linter-name: false
# Make issues output unique by line.
# Default: true
uniq-by-line: false
# Add a prefix to the output file references.
# Default is no prefix.
path-prefix: ""
# Sort results by: filepath, line and column.
sort-results: false

linters:
# Disable all linters.
# Default: false
disable-all: false

# Enable all available linters.
# Default: false
enable-all: false

enable:
- errcheck
- gosimple
- govet
- ineffassign
- unused
- asciicheck
- bidichk
- containedctx
- cyclop
- decorder
- depguard
- dupl
- dupword
- execinquery
- exhaustruct
- goconst
- gosec
- interfacebloat
- misspell
- sqlclosecheck
- unconvert
- unparam
- usestdlibvars

# Run only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true


linters-settings:
cyclop:
# The maximal average package complexity.
# If it's higher than 0.0 (float) the check is enabled
# Default: 0.0
package-average: 0.5
# Should ignore tests.
# Default: false
skip-tests: true

decorder:
# Required order of `type`, `const`, `var` and `func` declarations inside a file.
# Default: types before constants before variables before functions.
dec-order:
- type
- const
- var
- func
# If true, underscore vars (vars with "_" as the name) will be ignored at all checks
# Default: false (underscore vars are not ignored)
ignore-underscore-vars: false
# If true, order of declarations is not checked at all.
# Default: true (disabled)
disable-dec-order-check: false
# If true, `init` func can be anywhere in file (does not have to be declared before all other functions).
# Default: true (disabled)
disable-init-func-first-check: false
# If true, multiple global `type`, `const` and `var` declarations are allowed.
# Default: true (disabled)
disable-dec-num-check: false
# If true, type declarations will be ignored for dec num check
# Default: false (type statements are not ignored)
disable-type-dec-num-check: false
# If true, const declarations will be ignored for dec num check
# Default: false (const statements are not ignored)
disable-const-dec-num-check: false
# If true, var declarations will be ignored for dec num check
# Default: false (var statements are not ignored)
disable-var-dec-num-check: false

dupl:
# Tokens count to trigger issue.
# Default: 150
threshold: 150

dupword:
# Keywords for detecting duplicate words.
# If this list is not empty, only the words defined in this list will be detected.
# Default: []
keywords:
- "the"
- "and"
- "a"
# Keywords used to ignore detection.
# Default: []
ignore:
- "0C0C"

exhaustivestruct:
# Struct Patterns is list of expressions to match struct packages and names.
# The struct packages have the form `example.com/package.ExampleStruct`.
# The matching patterns can use matching syntax from https://pkg.go.dev/path#Match.
# If this list is empty, all structs are tested.
# Default: []
struct-patterns:
- '*.Test'
- 'example.com/package.ExampleStruct'
2 changes: 0 additions & 2 deletions pkg/command/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ func init() {
}

type DB struct {
dummyCommand

dbType string
db *sql.DB
isFinished bool
Expand Down
16 changes: 11 additions & 5 deletions pkg/command/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"syscall"
)

const (
WINDOWS_OS = "windows"
LINUX_OS = "linux"
MAC_OS = "darwin"
)

func init() {
commands["shell"] = &Shell{}
}
Expand Down Expand Up @@ -57,7 +63,7 @@ func ExecShell(command string) {
fmt.Println(command)
fmt.Println()
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
if runtime.GOOS == WINDOWS_OS {
cmd = exec.Command("cmd", "/C", command)
} else {
cmd = exec.Command("bash", "-c", command)
Expand All @@ -80,7 +86,7 @@ func ExecShell(command string) {
case <-done:
return
case <-sigChan:
if runtime.GOOS == "windows" {
if runtime.GOOS == WINDOWS_OS {
_ = cmd.Process.Signal(os.Kill)
} else {
_ = syscall.Kill(cmd.Process.Pid, syscall.SIGINT)
Expand All @@ -92,11 +98,11 @@ func ExecShell(command string) {
func getOSInfo() string {
var version string
switch runtime.GOOS {
case "darwin":
case MAC_OS:
version = darwinVersion()
case "linux":
case LINUX_OS:
version = linuxVersion()
case "windows":
case WINDOWS_OS:
version = windowsVersion()
}
return fmt.Sprintf("%s %s", runtime.GOOS, version)
Expand Down
2 changes: 0 additions & 2 deletions pkg/command/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
}

type Ssh struct {
dummyCommand

client *ssh.Client
host string
osInfo string
Expand Down Expand Up @@ -125,7 +123,7 @@
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),

Check failure on line 126 in pkg/command/ssh.go

View workflow job for this annotation

GitHub Actions / lint

G106: Use of ssh InsecureIgnoreHostKey should be audited (gosec)
Timeout: 5 * time.Minute,
}
addr := fmt.Sprintf("%s:%s", hostname, port)
Expand Down
11 changes: 9 additions & 2 deletions pkg/command/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"fmt"
"net/http"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -44,8 +45,14 @@
return []string{prompt}
}

func crawl(url string) string {
resp, err := http.Get(url)
func crawl(url_input string) string {
// Validate the URL
if _, err := url.ParseRequestURI(url_input); err != nil {
fmt.Println("Invalid URL: ", err)
return ""
}

resp, err := http.Get(url_input)

Check failure on line 55 in pkg/command/summary.go

View workflow job for this annotation

GitHub Actions / lint

G107: Potential HTTP request made with variable url (gosec)
if err != nil {
fmt.Println("Error fetching URL: ", err)
return ""
Expand Down
Loading