Skip to content

Commit e0977c7

Browse files
authored
add GHA workflow and linting fixes (#221)
* add GHA workflow and linting fixes Signed-off-by: Corey Hemminger <[email protected]> * lint fixes Signed-off-by: Corey Hemminger <[email protected]> --------- Signed-off-by: Corey Hemminger <[email protected]>
1 parent f7d2209 commit e0977c7

34 files changed

+467
-288
lines changed

.expeditor/verify.pipeline.yml

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,55 @@ expeditor:
1010
timeout_in_minutes: 30
1111

1212
steps:
13-
14-
- label: lint-chefstyle
15-
command:
16-
- cd /workdir/components/ruby
17-
- ../../.expeditor/run_linux_tests.sh "rake style"
18-
expeditor:
19-
executor:
20-
docker:
21-
image: ruby:3.1-bullseye
22-
23-
- label: run-specs-ruby-3.1
24-
command:
25-
- cd /workdir/components/ruby
26-
- ../../.expeditor/run_linux_tests.sh "rake spec"
27-
expeditor:
28-
executor:
29-
docker:
30-
image: ruby:3.1-bullseye
31-
32-
- label: run-specs-ruby-3.4.2
33-
command:
34-
- cd /workdir/components/ruby
35-
- ../../.expeditor/run_linux_tests.sh "rake spec"
36-
expeditor:
37-
executor:
38-
docker:
39-
image: ruby:3.4.2-bullseye
40-
41-
- label: run-specs-ruby-3.1-windows
42-
commands:
43-
- .expeditor/run_windows_tests.ps1
44-
expeditor:
45-
executor:
46-
docker:
47-
host_os: windows
48-
shell: ["powershell", "-Command"]
49-
image: rubydistros/windows-2019:3.1
50-
51-
- label: run-specs-ruby-3.4-windows
52-
commands:
53-
- .expeditor/run_windows_tests.ps1
54-
expeditor:
55-
executor:
56-
docker:
57-
host_os: windows
58-
shell: ["powershell", "-Command"]
59-
image: rubydistros/windows-2019:3.4
60-
61-
- label: run-go-tests-1.22.4-ubuntu
62-
commands:
63-
- cd /workdir/components/go
64-
# - go get .
65-
- go mod tidy
66-
- go test ./...
67-
expeditor:
68-
executor:
69-
docker:
70-
image: golang:1.22-bullseye
13+
- label: lint-chefstyle
14+
command:
15+
- cd /workdir/components/ruby
16+
- ../../.expeditor/run_linux_tests.sh "rake style"
17+
expeditor:
18+
executor:
19+
docker:
20+
image: ruby:3.1-bullseye
21+
- label: run-specs-ruby-3.1
22+
command:
23+
- cd /workdir/components/ruby
24+
- ../../.expeditor/run_linux_tests.sh "rake spec"
25+
expeditor:
26+
executor:
27+
docker:
28+
image: ruby:3.1-bullseye
29+
- label: run-specs-ruby-3.4.2
30+
command:
31+
- cd /workdir/components/ruby
32+
- ../../.expeditor/run_linux_tests.sh "rake spec"
33+
expeditor:
34+
executor:
35+
docker:
36+
image: ruby:3.4.2-bullseye
37+
- label: run-specs-ruby-3.1-windows
38+
commands:
39+
- .expeditor/run_windows_tests.ps1
40+
expeditor:
41+
executor:
42+
docker:
43+
host_os: windows
44+
shell: ["powershell", "-Command"]
45+
image: rubydistros/windows-2019:3.1
46+
- label: run-specs-ruby-3.4-windows
47+
commands:
48+
- .expeditor/run_windows_tests.ps1
49+
expeditor:
50+
executor:
51+
docker:
52+
host_os: windows
53+
shell: ["powershell", "-Command"]
54+
image: rubydistros/windows-2019:3.4
55+
- label: run-go-tests-1.22.4-ubuntu
56+
commands:
57+
- cd /workdir/components/go
58+
# - go get .
59+
- go mod tidy
60+
- go test ./...
61+
expeditor:
62+
executor:
63+
docker:
64+
image: golang:1.22-bullseye

.github/workflows/lint.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
name: Lint & Test
3+
4+
"on":
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'components/**'
10+
- '.github/workflows/**'
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- 'components/**'
16+
- '.github/workflows/**'
17+
workflow_dispatch:
18+
19+
permissions:
20+
contents: read
21+
22+
concurrency:
23+
group: lint-unit-test-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
check-markdown:
28+
name: Markdown Linting
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Check out code
32+
uses: actions/checkout@v6
33+
- name: Run Markdown Lint
34+
uses: DavidAnson/markdownlint-cli2-action@v22
35+
with:
36+
globs: "**/*.md"
37+
38+
yaml-lint:
39+
name: YAML Linting
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v6
43+
- name: Run yaml Lint
44+
uses: actionshub/yamllint@main
45+
46+
json-lint:
47+
name: Json Linting
48+
runs-on: ubuntu-latest
49+
container: python:alpine
50+
steps:
51+
- name: Checkout Code
52+
uses: actions/checkout@v6
53+
- name: Run JSON Linter
54+
run: |
55+
pip install --no-cache-dir demjson3
56+
find . -type f -iname "*.json" -exec jsonlint \{\} \+
57+
58+
ruby-lint:
59+
name: Ruby Linting (Cookstyle)
60+
runs-on: ubuntu-latest
61+
defaults:
62+
run:
63+
working-directory: components/ruby
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v6
67+
- name: Set up Ruby
68+
uses: ruby/setup-ruby@v1
69+
with:
70+
ruby-version: '3.4'
71+
bundler-cache: true
72+
working-directory: components/ruby
73+
- name: Run Cookstyle
74+
run: bundle exec cookstyle --chefstyle --display-cop-names --extra-details
75+
76+
go-lint:
77+
name: Go Linting (golangci-lint)
78+
runs-on: ubuntu-latest
79+
defaults:
80+
run:
81+
working-directory: components/go
82+
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v6
85+
- name: Set up Go
86+
uses: actions/setup-go@v5
87+
with:
88+
go-version-file: 'components/go/go.mod'
89+
cache: true
90+
- name: Run golangci-lint
91+
uses: golangci/golangci-lint-action@v6
92+
with:
93+
version-file: 'components/go/go.mod'
94+
working-directory: components/go
95+
96+
ruby-test:
97+
name: Ruby Unit Tests (RSpec)
98+
runs-on: ubuntu-latest
99+
defaults:
100+
run:
101+
working-directory: components/ruby
102+
steps:
103+
- name: Checkout code
104+
uses: actions/checkout@v6
105+
- name: Set up Ruby
106+
uses: ruby/setup-ruby@v1
107+
with:
108+
ruby-version: '3.4'
109+
bundler-cache: true
110+
working-directory: components/ruby
111+
- name: Run RSpec tests
112+
run: bundle exec rspec --format documentation --color
113+
114+
go-test:
115+
name: Go Unit Tests
116+
runs-on: ubuntu-latest
117+
defaults:
118+
run:
119+
working-directory: components/go
120+
steps:
121+
- name: Checkout code
122+
uses: actions/checkout@v6
123+
- name: Set up Go
124+
uses: actions/setup-go@v5
125+
with:
126+
go-version-file: 'components/go/go.mod'
127+
cache: true
128+
- name: Run Go tests
129+
run: |
130+
go test -v ./...

.markdownlint-cli2.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
config:
3+
line-length: false # MD013
4+
no-duplicate-heading: false # MD024
5+
ignores:
6+
- .github/copilot-instructions.md
7+
- CHANGELOG.md
8+
- CODE_OF_CONDUCT.md

.yamllint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
rules:
4+
line-length: disable

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# chef-licensing
22

3-
Ruby library to support CLI tools that use Progress Chef
4-
license storage, generation, and entitlement.
5-
3+
Ruby library to support CLI tools that use Progress Chef license storage, generation, and entitlement.

components/go/pkg/api/api_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestSetHeader(t *testing.T) {
5151
func MockAPIResponse(mockResponse string, status int) *httptest.Server {
5252
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5353
w.WriteHeader(status)
54-
w.Write([]byte(mockResponse))
54+
_, _ = w.Write([]byte(mockResponse))
5555
}))
5656
setConfig(mockServer.URL)
5757

components/go/pkg/key_fetcher/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (ad ActionDetail) TimeoutSelect() string {
8686
return ad.ResponsePathMap[val]
8787
}
8888
case <-timeoutContext.Done():
89-
fmt.Printf(printInColor(attribute.TimeoutWarningColor, attribute.TimeoutMessage, false, true))
89+
fmt.Print(printInColor(attribute.TimeoutWarningColor, attribute.TimeoutMessage, false, true))
9090
fmt.Printf("Timeout!\n")
9191
if !attribute.TimeoutContinue {
9292
os.Exit(1)

components/go/pkg/key_fetcher/action_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func TestSayAction(t *testing.T) {
7878
}
7979

8080
func TestTimeoutSelect(t *testing.T) {
81+
// Skip this test in CI environments where /dev/tty is not available
82+
if tty, err := os.Open("/dev/tty"); err != nil {
83+
t.Skip("Skipping test: /dev/tty not available (likely running in CI)")
84+
} else {
85+
tty.Close()
86+
}
87+
8188
actions := loadInteractions()
8289

8390
detail := actions["ask_for_license_timeout"]
@@ -219,7 +226,7 @@ func TestFetchLicenseTypeRestricted(t *testing.T) {
219226

220227
func loadInteractions() map[string]keyfetcher.ActionDetail {
221228
var intr keyfetcher.Interaction
222-
yaml.Unmarshal([]byte(YAML_DATA), &intr)
229+
_ = yaml.Unmarshal([]byte(YAML_DATA), &intr)
223230

224231
return intr.Actions
225232
}
@@ -235,15 +242,15 @@ func readFromSTDOUT(function actionFunction) (string, string) {
235242
os.Stdout = originalStdout
236243

237244
var buf bytes.Buffer
238-
io.Copy(&buf, r)
245+
_, _ = io.Copy(&buf, r)
239246

240247
return buf.String(), output
241248
}
242249

243250
func mockAPIResponse(mockResponse string, status int) *httptest.Server {
244251
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
245252
w.WriteHeader(status)
246-
w.Write([]byte(mockResponse))
253+
_, _ = w.Write([]byte(mockResponse))
247254
}))
248255
setConfig(mockServer.URL)
249256
return mockServer

components/go/pkg/key_fetcher/key_fetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
QUIT_KEY_REGEX = "(q|Q)"
2020
)
2121

22-
var ErrInvalidKeyFormat = fmt.Errorf(fmt.Sprintf("Malformed License Key passed on command line - should be %s or %s", LICENSE_KEY_PATTERN_DESC, SERIAL_KEY_PATTERN_DESC))
22+
var ErrInvalidKeyFormat = fmt.Errorf("Malformed License Key passed on command line - should be %s or %s", LICENSE_KEY_PATTERN_DESC, SERIAL_KEY_PATTERN_DESC)
2323

2424
func ValidateKeyFormat(key string) (matches bool) {
2525
var regexes []*regexp.Regexp

components/go/pkg/spinner/spinner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func StopSpinner(spinner *yacspin.Spinner, stopMessage, stopChar, stopColor stri
3636
if IsTTY() {
3737
spinner.StopMessage(stopMessage)
3838
spinner.StopCharacter(stopChar)
39-
spinner.StopColors(stopColor)
39+
_ = spinner.StopColors(stopColor)
4040
_ = spinner.Stop()
4141
}
4242
}

0 commit comments

Comments
 (0)