Skip to content

Commit 1c21618

Browse files
committed
ci: add action to enforce semantic PR titles and run tests (#55)
1 parent 3b9f866 commit 1c21618

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-1
lines changed

.github/workflows/go.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Go Build and Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- edited
9+
- opened
10+
- reopened
11+
- synchronize
12+
push:
13+
branches:
14+
- main
15+
16+
permissions:
17+
contents: read
18+
pull-requests: read
19+
20+
jobs:
21+
build-and-test:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version-file: go.mod
32+
cache-dependency-path: go.sum
33+
cache: true
34+
35+
- name: Run make build
36+
run: make build
37+
38+
- name: Run make test
39+
run: make test

.github/workflows/semantic-prs.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Semantic PRs
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- edited
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
permissions:
12+
pull-requests: read
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
validate_title:
20+
name: Validate Title
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: amannn/[email protected]
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
types: |
28+
fix
29+
feat
30+
improve
31+
refactor
32+
revert
33+
test
34+
ci
35+
docs
36+
chore
37+
38+
scopes: |
39+
ui
40+
cli
41+
config
42+
parser
43+
requireScope: false

.golangci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ issues:
1414
- dupl
1515
- lll
1616

17-
17+
# exclude some linters for the test directory and test files
18+
- path: test/.*|.*_test\.go
19+
linters:
20+
- dupl
21+
- errcheck
22+
- goconst
23+
- gocyclo
24+
- gosec
1825

1926
linters:
2027
disable-all: true

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,35 @@ Contributions are welcome!
200200

201201
We love seeing the community make Lazyssh better 🚀
202202

203+
### Semantic Pull Requests
204+
205+
This repository enforces semantic PR titles via an automated GitHub Action. Please format your PR title as:
206+
207+
- type(scope): short descriptive subject
208+
Notes:
209+
- Scope is optional and should be one of: ui, cli, config, parser.
210+
211+
Allowed types in this repo:
212+
- feat: a new feature
213+
- fix: a bug fix
214+
- improve: quality or UX improvements that are not a refactor or perf
215+
- refactor: code change that neither fixes a bug nor adds a feature
216+
- docs: documentation only changes
217+
- test: adding or refactoring tests
218+
- ci: CI/CD or automation changes
219+
- chore: maintenance tasks, dependency bumps, non-code infra
220+
- revert: reverts a previous commit
221+
222+
Examples:
223+
- feat(ui): add server pinning and sorting options
224+
- fix(parser): handle comments at end of Host blocks
225+
- improve(cli): show friendly error when ssh binary missing
226+
- refactor(config): simplify backup rotation logic
227+
- docs: add installation instructions for Homebrew
228+
- ci: cache Go toolchain and dependencies
229+
230+
Tip: If your PR touches multiple areas, pick the most relevant scope or omit the scope.
231+
203232
---
204233

205234
## ⭐ Support

internal/adapters/ui/validation_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package ui
1616

1717
import (
18+
"os"
19+
"path/filepath"
1820
"testing"
1921
)
2022

@@ -134,6 +136,29 @@ func TestValidateBindAddress(t *testing.T) {
134136
}
135137

136138
func TestValidateKeyPaths(t *testing.T) {
139+
// Prepare an isolated HOME with a mock .ssh folder and key files
140+
oldHome := os.Getenv("HOME")
141+
t.Cleanup(func() {
142+
_ = os.Setenv("HOME", oldHome)
143+
})
144+
145+
tempHome := t.TempDir()
146+
sshDir := filepath.Join(tempHome, ".ssh")
147+
if err := os.MkdirAll(sshDir, 0o755); err != nil {
148+
t.Fatalf("failed to create temp .ssh dir: %v", err)
149+
}
150+
151+
shouldExistFiles := []string{"id_rsa", "id_ed25519"}
152+
for _, name := range shouldExistFiles {
153+
p := filepath.Join(sshDir, name)
154+
if err := os.WriteFile(p, []byte("test"), 0o644); err != nil {
155+
t.Fatalf("failed to create mock key file %s: %v", p, err)
156+
}
157+
}
158+
if err := os.Setenv("HOME", tempHome); err != nil {
159+
t.Fatalf("failed to set HOME: %v", err)
160+
}
161+
137162
tests := []struct {
138163
name string
139164
keys string

0 commit comments

Comments
 (0)