Skip to content

Commit ee0bae4

Browse files
committed
add github workflows
1 parent 3490ee5 commit ee0bae4

File tree

12 files changed

+1097
-34
lines changed

12 files changed

+1097
-34
lines changed

.github/workflows/ci.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.21'
22+
23+
- name: Cache Go modules
24+
uses: actions/cache@v3
25+
with:
26+
path: ~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
30+
31+
- name: Download dependencies
32+
run: go mod download
33+
34+
- name: Verify dependencies
35+
run: go mod verify
36+
37+
- name: Run tests
38+
run: go test -v ./...
39+
40+
- name: Run tests with race detector
41+
run: go test -race -v ./...
42+
43+
format:
44+
name: Format Check
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v4
53+
with:
54+
go-version: '1.21'
55+
56+
- name: Check formatting
57+
run: |
58+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
59+
echo "The following files are not formatted:"
60+
gofmt -s -l .
61+
echo "Please run 'gofmt -s -w .' to format your code."
62+
exit 1
63+
fi
64+
65+
- name: Run go vet
66+
run: go vet ./...
67+
68+
- name: Install staticcheck
69+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
70+
71+
- name: Run staticcheck
72+
run: staticcheck ./...
73+
74+
- name: Install golint
75+
run: go install golang.org/x/lint/golint@latest
76+
77+
- name: Run golint
78+
run: golint -set_exit_status ./...
79+
80+
build:
81+
name: Build
82+
runs-on: ubuntu-latest
83+
needs: [test, format]
84+
85+
strategy:
86+
matrix:
87+
goos: [linux, windows, darwin]
88+
goarch: [amd64, arm64]
89+
exclude:
90+
- goos: windows
91+
goarch: arm64
92+
93+
steps:
94+
- name: Checkout code
95+
uses: actions/checkout@v4
96+
97+
- name: Set up Go
98+
uses: actions/setup-go@v4
99+
with:
100+
go-version: '1.21'
101+
102+
- name: Cache Go modules
103+
uses: actions/cache@v3
104+
with:
105+
path: ~/go/pkg/mod
106+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
107+
restore-keys: |
108+
${{ runner.os }}-go-
109+
110+
- name: Download dependencies
111+
run: go mod download
112+
113+
- name: Build binary
114+
env:
115+
GOOS: ${{ matrix.goos }}
116+
GOARCH: ${{ matrix.goarch }}
117+
run: |
118+
mkdir -p build
119+
BINARY_NAME=devbox
120+
if [ "$GOOS" = "windows" ]; then
121+
BINARY_NAME="${BINARY_NAME}.exe"
122+
fi
123+
CGO_ENABLED=0 go build -ldflags="-w -s" -o build/${BINARY_NAME}-${GOOS}-${GOARCH} ./cmd/devbox
124+
125+
- name: Upload artifacts
126+
uses: actions/upload-artifact@v3
127+
with:
128+
name: devbox-${{ matrix.goos }}-${{ matrix.goarch }}
129+
path: build/devbox*
130+
retention-days: 7

.github/workflows/docs.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths: [ 'docs/**' ]
7+
pull_request:
8+
branches: [ main ]
9+
paths: [ 'docs/**' ]
10+
11+
jobs:
12+
build-docs:
13+
name: Build Documentation
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '18'
24+
cache: 'npm'
25+
cache-dependency-path: docs/package.json
26+
27+
- name: Install dependencies
28+
working-directory: docs
29+
run: npm ci
30+
31+
- name: Build documentation
32+
working-directory: docs
33+
run: npm run build
34+
35+
- name: Upload documentation artifacts
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: documentation
39+
path: docs/dist/
40+
retention-days: 7
41+
42+
deploy-docs:
43+
name: Deploy Documentation
44+
runs-on: ubuntu-latest
45+
needs: build-docs
46+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
47+
48+
permissions:
49+
contents: read
50+
pages: write
51+
id-token: write
52+
53+
steps:
54+
- name: Download documentation artifacts
55+
uses: actions/download-artifact@v3
56+
with:
57+
name: documentation
58+
path: ./docs-dist
59+
60+
- name: Setup Pages
61+
uses: actions/configure-pages@v3
62+
63+
- name: Upload to GitHub Pages
64+
uses: actions/upload-pages-artifact@v2
65+
with:
66+
path: ./docs-dist
67+
68+
- name: Deploy to GitHub Pages
69+
id: deployment
70+
uses: actions/deploy-pages@v2

.github/workflows/quality.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
# Run weekly on Sundays at 2 AM UTC
10+
- cron: '0 2 * * 0'
11+
12+
jobs:
13+
security:
14+
name: Security Scan
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: '1.21'
25+
26+
- name: Install gosec
27+
run: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
28+
29+
- name: Run Gosec Security Scanner
30+
run: gosec ./...
31+
32+
- name: Install govulncheck
33+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
34+
35+
- name: Run govulncheck
36+
run: govulncheck ./...
37+
38+
quality:
39+
name: Code Quality
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Go
47+
uses: actions/setup-go@v4
48+
with:
49+
go-version: '1.21'
50+
51+
- name: Cache Go modules
52+
uses: actions/cache@v3
53+
with:
54+
path: ~/go/pkg/mod
55+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
56+
restore-keys: |
57+
${{ runner.os }}-go-
58+
59+
- name: Download dependencies
60+
run: go mod download
61+
62+
- name: Install golangci-lint
63+
uses: golangci/golangci-lint-action@v3
64+
with:
65+
version: latest
66+
args: --timeout=5m
67+
68+
- name: Install gocyclo
69+
run: go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
70+
71+
- name: Check cyclomatic complexity
72+
run: gocyclo -over 15 .
73+
74+
- name: Install ineffassign
75+
run: go install github.com/gordonklaus/ineffassign@latest
76+
77+
- name: Check for ineffectual assignments
78+
run: ineffassign ./...
79+
80+
- name: Install misspell
81+
run: go install github.com/client9/misspell/cmd/misspell@latest
82+
83+
- name: Check for misspellings
84+
run: misspell -error .
85+
86+
coverage:
87+
name: Test Coverage
88+
runs-on: ubuntu-latest
89+
90+
steps:
91+
- name: Checkout code
92+
uses: actions/checkout@v4
93+
94+
- name: Set up Go
95+
uses: actions/setup-go@v4
96+
with:
97+
go-version: '1.21'
98+
99+
- name: Cache Go modules
100+
uses: actions/cache@v3
101+
with:
102+
path: ~/go/pkg/mod
103+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
104+
restore-keys: |
105+
${{ runner.os }}-go-
106+
107+
- name: Download dependencies
108+
run: go mod download
109+
110+
- name: Run tests with coverage
111+
run: go test -coverprofile=coverage.out ./...
112+
113+
- name: Generate coverage report
114+
run: go tool cover -html=coverage.out -o coverage.html
115+
116+
- name: Upload coverage reports
117+
uses: actions/upload-artifact@v3
118+
with:
119+
name: coverage-report
120+
path: |
121+
coverage.out
122+
coverage.html
123+
retention-days: 30
124+
125+
- name: Check coverage threshold
126+
run: |
127+
COVERAGE=$(go tool cover -func=coverage.out | tail -n 1 | awk '{print $3}' | sed 's/%//')
128+
echo "Coverage: ${COVERAGE}%"
129+
if (( $(echo "$COVERAGE < 50" | bc -l) )); then
130+
echo "Coverage is below 50%"
131+
exit 1
132+
fi

0 commit comments

Comments
 (0)