Skip to content
This repository was archived by the owner on Sep 18, 2021. It is now read-only.

Commit 21952b9

Browse files
committed
fix: configurable validation source
CLI is validated with the schema stored inside the binary. Project and Module files are still validated with the files from the local Ansible collection.
1 parent c285072 commit 21952b9

File tree

19 files changed

+201
-68
lines changed

19 files changed

+201
-68
lines changed

.build/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
go get github.com/markbates/pkger/cmd/pkger
4+
pkger
5+
go generate ./...
6+
go build -o ./bin/stackhead-cli .

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# Pull Request
2+
3+
## Requirements
4+
15
* **Please check if the PR fulfills these requirements**
26
- [ ] The commit message follows our guidelines
37
- [ ] Tests for the changes have been added (for bug fixes / features)
48
- [ ] Docs have been added / updated (for bug fixes / features)
59

10+
## Details
611

712
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
813

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Set up Go 1.13
17-
uses: actions/setup-go@v1
17+
uses: actions/setup-go@v2
1818
with:
1919
go-version: 1.13
2020
- name: Check out code into the Go module directory
2121
uses: actions/checkout@v2
2222
- name: Build
23-
run: go build -v -o bin/stackhead-cli
23+
run: sh ./.build/build.sh
2424

2525
release:
2626
name: Release

.github/workflows/test-cli.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ jobs:
1818
steps:
1919

2020
- name: Set up Go 1.13
21-
uses: actions/setup-go@v1
21+
uses: actions/setup-go@v2
2222
with:
2323
go-version: 1.13
24-
id: go
2524

2625
- name: Check out code into the Go module directory
2726
uses: actions/checkout@v2
2827

2928
- name: Build
30-
run: go build -v -o bin/stackhead-cli
29+
run: sh ./.build/build.sh
3130

3231
- uses: actions/upload-artifact@v2
3332
with:
@@ -40,10 +39,9 @@ jobs:
4039
runs-on: ubuntu-latest
4140
steps:
4241
- name: Set up Go 1.13
43-
uses: actions/setup-go@v1
42+
uses: actions/setup-go@v2
4443
with:
4544
go-version: 1.13
46-
id: go
4745

4846
- name: Check out code into the Go module directory
4947
uses: actions/checkout@v2
@@ -66,6 +64,8 @@ jobs:
6664
run: pip install ansible==2.10.3
6765
- name: Print Ansible and Python version
6866
run: ansible --version && python --version
67+
- name: Check out code into the Go module directory
68+
uses: actions/checkout@v2
6969
- name: Download StackHead CLI artifact
7070
uses: actions/download-artifact@v2
7171
with:

.github/workflows/test-integration.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ jobs:
1818
steps:
1919

2020
- name: Set up Go 1.13
21-
uses: actions/setup-go@v1
21+
uses: actions/setup-go@v2
2222
with:
2323
go-version: 1.13
24-
id: go
2524

2625
- name: Check out code into the Go module directory
2726
uses: actions/checkout@v2
2827

2928
- name: Build
30-
run: go build -v -o bin/stackhead-cli
29+
run: sh ./.build/build.sh
3130

3231
- uses: actions/upload-artifact@v2
3332
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
bin
33
stackhead-cli
44
.stackhead-cli.yml
5+
pkged.go

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM golang:alpine as builder
22
WORKDIR /build
33
COPY . /build
4-
RUN go build -o ./bin/stackhead-cli .
4+
RUN sh /build/.build/build.sh
55

66
FROM pad92/ansible-alpine:2.10.3
77
COPY --from=builder /build/bin/stackhead-cli /bin/

commands/cli/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func GetCommands() *cobra.Command {
99
Use: "cli",
1010
Short: "StackHead CLI commands",
1111
}
12-
command.AddCommand(Validate)
12+
validate := Validate()
13+
command.AddCommand(validate)
1314
return command
1415
}

commands/cli/validate.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
package cli
22

33
import (
4-
"github.com/spf13/cobra"
5-
64
"github.com/getstackhead/stackhead-cli/routines"
5+
"github.com/spf13/cobra"
76
)
87

98
// Validate is a command object for Cobra that provides the validate command
10-
var Validate = &cobra.Command{
11-
Use: "validate [path to StackHead CLI configuration file]",
12-
Example: "validate ./stackhead-module.yml",
13-
Short: "Validate a StackHead module file",
14-
Long: `validate is used to make sure your StackHead CLI configuration file meets the required syntax.`,
15-
Args: cobra.ExactArgs(1),
16-
Run: func(cmd *cobra.Command, args []string) {
17-
routines.Validate(args[0], "cli-config.schema.json")
18-
},
9+
func Validate() *cobra.Command {
10+
var version, branch string
11+
var ignoreSslCertificate bool
12+
var command = &cobra.Command{
13+
Use: "validate [path to StackHead CLI configuration file]",
14+
Example: "validate ./stackhead-module.yml",
15+
Short: "Validate a StackHead module file",
16+
Long: `validate is used to make sure your StackHead CLI configuration file meets the required syntax.`,
17+
Args: cobra.ExactArgs(1),
18+
Run: routines.CobraValidationBase(
19+
"stackhead_cli",
20+
"cli-config.schema.json",
21+
version,
22+
branch,
23+
ignoreSslCertificate,
24+
),
25+
}
26+
command.PersistentFlags().StringVar(&version, "version", "", "Version of schema to use (requires internet connection)")
27+
command.PersistentFlags().StringVar(&branch, "branch", "", "Branch of schema to use (requires internet connection)")
28+
command.PersistentFlags().BoolVar(&ignoreSslCertificate, "ignore-ssl-certificate", false, "Whether to ignore the SSL certificate for Web request (when --version) is used")
29+
30+
return command
1931
}

commands/module/module.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func GetCommands() *cobra.Command {
99
Use: "module",
1010
Short: "StackHead module commands",
1111
}
12-
command.AddCommand(Validate)
12+
validate := Validate()
13+
command.AddCommand(validate)
1314
return command
1415
}

0 commit comments

Comments
 (0)