Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Lint

on:
pull_request: {}
push:
branches:
- main

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
go-mod-tidy:
name: Check Golang Modules
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.25

- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Check module vendoring
run: |
go mod tidy
go mod vendor
test -z "$(git status --porcelain)" || \
(echo "::error::modules files is not up to date, please run 'go mod tidy && go mod vendor', re-submit changes"; exit 1)

verify-signatures:
name: Verify Commit Signatures
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false

- name: Verify commit signed-off
run: |
set -eu -o pipefail
COMMITS=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
for commit in $COMMITS; do
commit_msg=$(git log --format=%B -n 1 $commit)
if ! echo "$commit_msg" | grep -qE "^Signed-off-by: .+ <.+@.+>$"; then
echo "::error::Commit $commit is missing proper Signed-off-by line (format: Signed-off-by: Name <email>)"
exit 1
fi
done

golangci:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.25

- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.4.0
skip-cache: true
args: "--verbose --modules-download-mode=vendor"

117 changes: 117 additions & 0 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Build and Test

on:
pull_request: {}
push:
branches:
- main

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
build_commits:
name: Build All
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false

- name: Install Golang
uses: actions/setup-go@v6
with:
go-version: 1.25
cache: false

- name: Build for every commit
run: |
set -eu -o pipefail
COMMITS=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
for commit in $COMMITS ; do
git checkout $commit || exit 1
go build ./...
done

- name: Failed build commit
if: ${{ failure() }}
run: |
echo "::error::Build failed for commit $(git --no-pager log -n 1 --format=reference)"

test_commits:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false

- name: Install Golang
uses: actions/setup-go@v6
with:
go-version: 1.25
cache: false

- name: Run unit test for every commit
run: |
set -eu -o pipefail
COMMITS=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
for commit in $COMMITS ; do
git checkout $commit || exit 1
make test
done

- name: Failed test commit
if: ${{ failure() }}
run: |
echo "::error::Test failed for commit $(git --no-pager log -n 1 --format=reference)"

test_cli_commits:
name: CLI Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false

- name: Install Golang
uses: actions/setup-go@v6
with:
go-version: 1.25
cache: false

- name: Run CLI tests for every commit
run: |
set -eu -o pipefail
COMMITS=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
for commit in $COMMITS ; do
git checkout $commit || exit 1
make cli-test clean
done

- name: Failed CLI test commit
if: ${{ failure() }}
run: |
echo "::error::CLI test failed for commit $(git --no-pager log -n 1 --format=reference)"

- name: Upload server files
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: cli-test-files
path: tmp/
19 changes: 5 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
version: 2

version: "2"
run:
timeout: 10m
modules-download-mode: readonly
issues-exit-code: 1
tests: true

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

timeout: 10m
formatters:
enable:
- gofmt
- goimports

linters:
disable-all: true
default: none
enable:
- depguard
- err113
Expand Down Expand Up @@ -72,7 +66,6 @@ linters:
enable:
- nilness
gosec:
exclude-generated: true
includes:
- G101 # Look for hard coded credentials
- G112 # Potential Slowloris Attack because ReadHeaderTimeout is not configured
Expand All @@ -83,8 +76,6 @@ linters:
line-length: 140
misspell:
locale: US
unused:
check-exported: false
exclusions:
generated: lax
presets:
Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.PHONY: build test lint clean check help all build-hos build-hosd cli-test
.PHONY: build test lint clean check help all build-hos build-hosd build-all cli-test

# Default target
all: build

# Build commands
build: build-hos build-hosd

build-all:
@echo "Building all packages..."
go build ./...

build-hos:
@echo "Building hos client..."
go build -o bin/hos ./cmd/hos
Expand All @@ -17,12 +21,12 @@ build-hosd:
# Test commands
test:
@echo "Running tests..."
go test -v ./...
go test ./...

# Code quality commands
lint:
@echo "Running golangci-lint..."
golangci-lint run
golangci-lint run --verbose --modules-download-mode=vendor

# Clean up
clean:
Expand All @@ -42,6 +46,7 @@ check: test cli-test lint
help:
@echo "Available commands:"
@echo " build - Build both hos and hosd binaries"
@echo " build-all - Build all packages"
@echo " build-hos - Build only hos client"
@echo " build-hosd - Build only hosd server"
@echo " test - Run unit tests"
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ func newTestClient(s *Server, t *testing.T, users ...string) *clientT {
}

func (c *clientT) do(user, method, path string, data any, header map[string]string) (*http.Response, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
ctx := context.Background()

cfns := []clientFunc{headers(header)}
if data != nil {
Expand Down
4 changes: 3 additions & 1 deletion scripts/cli-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ start_server() {
local server_pid=$!
echo "$server_pid" > "$pid_file"


# Wait for server to be ready using health check
local max_wait=30
local wait_count=0
local health_url="https://$address/healthz"

log_info "Waiting for server to be ready at $health_url..."

# Lets disable exit on error while checking for server status
set +e
while [[ $wait_count -lt $max_wait ]]; do
# Check if process is still running
if ! kill -0 "$server_pid" 2>/dev/null; then
Expand All @@ -135,6 +136,7 @@ start_server() {
sleep 1
((wait_count++))
done
set -e

log_error "Server at $address did not become ready within ${max_wait} seconds"
return 1
Expand Down
Loading