-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cmd/lint) add subcommand to validate .gitlab-ci.yml
- Loading branch information
1 parent
f338ef9
commit 4604b39
Showing
7 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ciCmd represents the ci command | ||
var ciCmd = &cobra.Command{ | ||
Use: "ci", | ||
Short: "", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(ciCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
// ciLintCmd represents the lint command | ||
var ciLintCmd = &cobra.Command{ | ||
Use: "lint", | ||
Short: "Validate .gitlab-ci.yml against GitLab", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
path := ".gitlab-ci.yml" | ||
if len(args) == 1 { | ||
path = args[0] | ||
} | ||
b, err := ioutil.ReadFile(path) | ||
if !os.IsNotExist(err) && err != nil { | ||
log.Fatal(err) | ||
} | ||
ok, err := lab.Lint(string(b)) | ||
if !ok || err != nil { | ||
log.Fatal(errors.Wrap(err, "ci yaml invalid")) | ||
} | ||
fmt.Println("Valid!") | ||
}, | ||
} | ||
|
||
func init() { | ||
ciCmd.AddCommand(ciLintCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ciLint(t *testing.T) { | ||
repo := copyTestRepo(t) | ||
cmd := exec.Command("../lab_bin", "ci", "lint") | ||
cmd.Dir = repo | ||
|
||
b, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Log(string(b)) | ||
t.Fatal(err) | ||
} | ||
require.Contains(t, string(b), "Valid!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
image: busybox:latest | ||
|
||
before_script: | ||
- echo "Before script section" | ||
- echo "For example you might run an update here or install a build dependency" | ||
- echo "Or perhaps you might print out some debugging details" | ||
|
||
after_script: | ||
- echo "After script section" | ||
- echo "For example you might do some cleanup here" | ||
|
||
build1: | ||
stage: build | ||
script: | ||
- echo "Do your build here" | ||
|
||
test1: | ||
stage: test | ||
script: | ||
- echo "Do a test here" | ||
- echo "For example run a test suite" | ||
|
||
test2: | ||
stage: test | ||
script: | ||
- echo "Do another parallel test here" | ||
- echo "For example run a lint test" | ||
|
||
deploy1: | ||
stage: deploy | ||
script: | ||
- echo "Do your deploy here" |