Skip to content

Commit

Permalink
Use GitHub actions (#8)
Browse files Browse the repository at this point in the history
* use Github Actions
  • Loading branch information
zabio3 committed Dec 3, 2019
1 parent 63f1eb9 commit 69e1f82
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 81 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/go112.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: go1.12
on: [push]
jobs:

build:
name: Build in Go1.12
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.12
uses: actions/setup-go@v1
with:
go-version: 1.12
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Test
run: go test -v -cover .
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ godolint
===

[![GitHub release](http://img.shields.io/github/release/zabio3/godolint.svg?style=flat-square)](https://github.com/zabio3/godolint/releases/latest)
[![Build Status](https://travis-ci.org/zabio3/godolint.svg?branch=master)](https://travis-ci.org/zabio3/godolint)
[![Actions Status](https://github.com/zabio3/godolint/workflows/go1.12/badge.svg)](https://github.com/zabio3/godolint/actions)
[![Golang CI](https://golangci.com/badges/github.com/zabio3/godolint.svg)](https://golangci.com/r/github.com/zabio3/godolint)
[![codecov](https://codecov.io/gh/zabio3/godolint/branch/master/graph/badge.svg)](https://codecov.io/gh/zabio3/godolint)
[![Go Report Card](https://goreportcard.com/badge/github.com/zabio3/godolint)](https://goreportcard.com/report/github.com/zabio3/godolint)
[![GoDoc](https://godoc.org/github.com/zabio3/godolint?status.svg)](https://godoc.org/github.com/zabio3/godolint)
[![Maintainability](https://api.codeclimate.com/v1/badges/4c1c216781e5592d4194/maintainability)](https://codeclimate.com/github/zabio3/godolint/maintainability)
Expand Down
24 changes: 12 additions & 12 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// Exit codes are int values that represent an exit code for a particular error.
const (
ExitCodeOK = iota
ExitCodeOK = iota + 1
ExitCodeParseFlagsError
ExitCodeNoExistError
ExitCodeFileError
Expand All @@ -41,7 +41,7 @@ Other Commands:
--version -v Print the version information
`

// CLI represents CLI interface
// CLI represents CLI interface.
type CLI struct {
OutStream, ErrStream io.Writer
}
Expand All @@ -64,56 +64,56 @@ func (cli *CLI) Run(args []string) int {

flags := flag.NewFlagSet(name, flag.ContinueOnError)
flags.Usage = func() {
_, _ = fmt.Fprint(cli.OutStream, usage)
fmt.Fprint(cli.OutStream, usage)
}

flags.Var(&ignoreRules, "ignore", "Set ignore strings")
flags.BoolVar(&isVersion, "version", false, "version")
flags.BoolVar(&isVersion, "v", false, "version")

if err := flags.Parse(args[1:]); err != nil {
_, _ = fmt.Fprintf(cli.ErrStream, "%v\n", err)
fmt.Fprintf(cli.ErrStream, "%v\n", err)
return ExitCodeParseFlagsError
}

if isVersion {
_, _ = fmt.Fprintf(cli.OutStream, "godolint version %v\n", version)
fmt.Fprintf(cli.OutStream, "godolint version %v\n", version)
return ExitCodeOK
}

length := len(args)
// The Dockerfile to be analyzed must be the last.
if length < 2 {
_, _ = fmt.Fprintf(cli.ErrStream, "Please provide a Dockerfile\n")
fmt.Fprintf(cli.ErrStream, "Please provide a Dockerfile\n")
return ExitCodeNoExistError
}

file := args[length-1]
f, err := os.Open(file)
if err != nil {
_, _ = fmt.Fprintf(cli.ErrStream, "%v\n", err)
fmt.Fprintf(cli.ErrStream, "%v\n", err)
return ExitCodeFileError
}

r, err := parser.Parse(f)
if err != nil {
_, _ = fmt.Fprintf(cli.ErrStream, "%v\n", err)
fmt.Fprintf(cli.ErrStream, "%v\n", err)
return ExitCodeAstParseError
}

analyzer := linter.NewAnalyzer(ignoreRules)
rst, err := analyzer.Run(r.AST)
if err != nil {
_, _ = fmt.Fprintf(cli.ErrStream, "%v\n", err)
fmt.Fprintf(cli.ErrStream, "%v\n", err)
return ExitCodeLintCheckError
}

rst = sort.StringSlice(rst)
var output string
for _, s := range rst {
for i := range rst {
// ends of each strings have "\n"
output = output + s
output = output + rst[i]
}
_, _ = fmt.Fprint(cli.OutStream, output)
fmt.Fprint(cli.OutStream, output)
return ExitCodeOK
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/zabio3/godolint

require github.com/moby/buildkit v0.6.1
require github.com/moby/buildkit v0.6.3
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on
github.com/containerd/containerd v1.2.4/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.3.0-0.20190507210959-7c1e88399ec0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/continuity v0.0.0-20181001140422-bd77b46c8352/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
github.com/containerd/go-cni v0.0.0-20190610170741-5a4663dad645/go.mod h1:2wlRxCQdiBY+OcjNg5x8kI+5mEL1fGt25L4IzQHYJsM=
github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0=
github.com/containerd/go-runc v0.0.0-20190911050354-e029b79d8cda/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0=
github.com/containerd/ttrpc v0.0.0-20190411181408-699c4e40d1e7/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o=
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
github.com/containernetworking/cni v0.6.1-0.20180218032124-142cde0c766c/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
Expand Down Expand Up @@ -57,8 +57,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/moby/buildkit v0.6.1 h1:mD45fgAPzbFsP38XdJQkYYy0ij6RWzjJGBBnuF25Aq0=
github.com/moby/buildkit v0.6.1/go.mod h1:bXDz0nCc9+IvUTVSAyjytY1WcXApDpwpP7vOc0lFTNY=
github.com/moby/buildkit v0.6.3 h1:2eFVHDz1E9uyMsbquywvjPIZ0yHT58HWCcn0K9qavWM=
github.com/moby/buildkit v0.6.3/go.mod h1:JKVImCzxztxvULr5P6ZiBfA/B2P+ZpR6UHxOXQn4KiU=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -82,7 +82,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tonistiigi/fsutil v0.0.0-20190327153851-3bbb99cdbd76/go.mod h1:pzh7kdwkDRh+Bx8J30uqaKJ1M4QrSH/um8fcIXeM8rc=
github.com/tonistiigi/fsutil v0.0.0-20190819224149-3d2716dd0a4d/go.mod h1:pzh7kdwkDRh+Bx8J30uqaKJ1M4QrSH/um8fcIXeM8rc=
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6cRcDZSUvVmezrxJPkiO87ThFYsoUiMwWNDJk=
github.com/uber/jaeger-client-go v0.0.0-20180103221425-e02c85f9069e/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v1.2.1/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
Expand Down
26 changes: 13 additions & 13 deletions linter/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Analyzer struct {
rules []*rules.Rule
}

// NewAnalyzer generate a NewAnalyzer with rules to apply
// NewAnalyzer generate a NewAnalyzer with rules to apply.
func NewAnalyzer(ignoreRules []string) Analyzer {
return newAnalyzer(ignoreRules)
}
Expand All @@ -27,21 +27,21 @@ func newAnalyzer(ignoreRules []string) Analyzer {
return Analyzer{rules: filteredRules}
}

// Run apply docker best practice rules to docker ast
// Run apply docker best practice rules to docker ast.
func (a Analyzer) Run(node *parser.Node) ([]string, error) {
var rst []string
rstChan := make(chan []string, len(a.rules))
errChan := make(chan error, len(a.rules))

for _, rule := range a.rules {
for i := range a.rules {
go func(r *rules.Rule) {
vrst, err := r.ValidateFunc(node)
if err != nil {
errChan <- err
} else {
rstChan <- rules.CreateMessage(rule, vrst)
rstChan <- rules.CreateMessage(a.rules[i], vrst)
}
}(rule)
}(a.rules[i])
select {
case value := <-rstChan:
rst = append(rst, value...)
Expand All @@ -52,29 +52,29 @@ func (a Analyzer) Run(node *parser.Node) ([]string, error) {
return rst, nil
}

// getMakeDifference is a function to create a difference set
// getMakeDifference is a function to create a difference set.
func getMakeDiff(xs, ys []string) []string {
if len(xs) > len(ys) {
return makeDiff(xs, ys)
}
return makeDiff(ys, xs)
}

// make set difference
// make set difference.
func makeDiff(xs, ys []string) []string {
var set []string
for _, c := range xs {
if !isContain(ys, c) {
set = append(set, c)
for i := range xs {
if !isContain(ys, xs[i]) {
set = append(set, xs[i])
}
}
return set
}

// isContain is a function to check if s is in xs
// isContain is a function to check if s is in xs.
func isContain(xs []string, s string) bool {
for _, x := range xs {
if s == x {
for i := range xs {
if xs[i] == s {
return true
}
}
Expand Down
3 changes: 2 additions & 1 deletion linter/rules/dl3001.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/parser"
)

// validateDL3001 is "For some bash commands it makes no sense running them in a Docker container like ssh, vim, shutdown, service, ps, free, top, kill, mount, ifconfig."
// validateDL3001 is "For some bash commands it makes no sense running them in a Docker container
// like ssh, vim, shutdown, service, ps, free, top, kill, mount, ifconfig."
func validateDL3001(node *parser.Node) (rst []ValidateResult, err error) {
for _, child := range node.Children {
if child.Value == RUN {
Expand Down
10 changes: 8 additions & 2 deletions linter/rules/dl3012.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ package rules
// "github.com/moby/buildkit/frontend/dockerfile/parser"
//)
//
//// validateDL3012 Provide an email address or URL as maintainer. (deprecated)
//func validateDL3012(node *parser.Node, file string) (rst []ValidateResult, err error) {
//// validateDL3012 Provide an email address or URL as maintainer.
//func validateDL3012(node *parser.Node) (rst []ValidateResult, err error) {
// for _, child := range node.Children {
// if child.Value == MAINTAINER {
//
//
// }
// }
// return rst, nil
//}
1 change: 0 additions & 1 deletion linter/rules/dl3012_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package rules

//
//import (
// "testing"
//)
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl3024.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ func validateDL3024(node *parser.Node) (rst []ValidateResult, err error) {
isAs := false
var asBuildName []string
for _, child := range node.Children {
switch child.Value {
case FROM:
if child.Value == FROM {
for _, v := range strings.Fields(child.Original) {
switch v {
case "as":
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl3025.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
func validateDL3025(node *parser.Node) (rst []ValidateResult, err error) {
for _, child := range node.Children {
isErr := false
switch child.Value {
case ENTRYPOINT, CMD:
if (child.Value == ENTRYPOINT) || (child.Value == CMD) {
args := strings.Fields(child.Original)
length := len(args) - 1
for i, v := range strings.Fields(child.Original) {
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl4000.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
// validateDL4000 MAINTAINER is deprecated
func validateDL4000(node *parser.Node) (rst []ValidateResult, err error) {
for _, child := range node.Children {
switch child.Value {
case MAINTAINER:
if child.Value == MAINTAINER {
rst = append(rst, ValidateResult{line: child.StartLine, addMsg: ""})
}
}
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl4001.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ func validateDL4001(node *parser.Node) (rst []ValidateResult, err error) {
isCurl, isWget := false, false
var numArr []int
for _, child := range node.Children {
switch child.Value {
case RUN:
if child.Value == RUN {
for _, v := range strings.Fields(child.Next.Value) {
switch v {
case "curl":
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl4003.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
func validateDL4003(node *parser.Node) (rst []ValidateResult, err error) {
isCmd := false
for _, child := range node.Children {
switch child.Value {
case CMD:
if child.Value == CMD {
if !isCmd {
isCmd = true
} else {
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl4004.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
func validateDL4004(node *parser.Node) (rst []ValidateResult, err error) {
isEntryPoint := false
for _, child := range node.Children {
switch child.Value {
case ENTRYPOINT:
if child.Value == ENTRYPOINT {
if !isEntryPoint {
isEntryPoint = true
} else {
Expand Down
3 changes: 1 addition & 2 deletions linter/rules/dl4005.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
// validateDL4005 Use SHELL to change the default shell
func validateDL4005(node *parser.Node) (rst []ValidateResult, err error) {
for _, child := range node.Children {
switch child.Value {
case RUN:
if child.Value == RUN {
isLn := false
for _, v := range strings.Fields(child.Next.Value) {
switch v {
Expand Down

0 comments on commit 69e1f82

Please sign in to comment.