Skip to content

fix(cli): streamline command checks and improve argument parsing (#40… #42

fix(cli): streamline command checks and improve argument parsing (#40…

fix(cli): streamline command checks and improve argument parsing (#40… #42

Workflow file for this run

name: CLI Test
on:
push:
branches:
- main
- dev
paths:
- 'src/client/acontext-cli/**'
- '.github/workflows/cli-test.yaml'
pull_request:
branches:
- main
- dev
paths:
- 'src/client/acontext-cli/**'
- '.github/workflows/cli-test.yaml'
env:
GO_VERSION: '1.25.1'
jobs:
test:
name: Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/client/acontext-cli
strategy:
matrix:
go-version: ['1.25.1']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version-file: src/client/acontext-cli/go.mod
cache: true
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('src/client/acontext-cli/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v -race -coverprofile=coverage.out ./...
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: codecov-cli
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/client/acontext-cli
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: src/client/acontext-cli/go.mod
cache: true
- name: Tidy dependencies
run: go mod tidy
- name: Verify build works
run: go build ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
working-directory: src/client/acontext-cli
args: --timeout=5m ./...
only-new-issues: ${{ github.event_name == 'pull_request' }}
build:
name: Build
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: src/client/acontext-cli
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.25.1']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version-file: src/client/acontext-cli/go.mod
cache: true
- name: Download dependencies
run: go mod download
- name: Build
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
go build -ldflags "-X main.version=dev" -o acontext-cli.exe main.go
else
go build -ldflags "-X main.version=dev" -o acontext-cli main.go
fi
- name: Test binary
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
./acontext-cli.exe version
else
./acontext-cli version
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: acontext-cli-${{ matrix.os }}
path: |
${{ matrix.os == 'windows-latest' && 'src/client/acontext-cli/acontext-cli.exe' || 'src/client/acontext-cli/acontext-cli' }}
test-install-script:
name: Test Install Script on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: src/client/acontext-cli
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: src/client/acontext-cli/go.mod
cache: true
- name: Test install script syntax
run: |
sh -n install.sh
echo "✓ Install script syntax is valid"
- name: Test install script help
run: |
sh install.sh --help
- name: Test platform detection logic
run: |
# Test that the script can detect the platform correctly
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
echo "Detected OS: $OS"
echo "Detected ARCH: $ARCH"
# Verify the script handles the platform correctly
case "$ARCH" in
x86_64)
EXPECTED_ARCH="amd64"
;;
aarch64|arm64)
EXPECTED_ARCH="arm64"
;;
*)
echo "✗ Unsupported architecture: $ARCH"
exit 1
;;
esac
case "$OS" in
linux|darwin)
echo "✓ Platform $OS/$EXPECTED_ARCH is supported"
;;
*)
echo "✗ Platform $OS is not supported"
exit 1
;;
esac
- name: Test dependency checks
run: |
# The script should check for curl/wget and tar/unzip
# These should be available on GitHub Actions runners
if command -v curl >/dev/null 2>&1 || command -v wget >/dev/null 2>&1; then
echo "✓ HTTP client (curl/wget) is available"
else
echo "✗ HTTP client is missing"
exit 1
fi
if command -v tar >/dev/null 2>&1 || command -v unzip >/dev/null 2>&1; then
echo "✓ Archive tool (tar/unzip) is available"
else
echo "✗ Archive tool is missing"
exit 1
fi
- name: Build test binary
run: |
go build -ldflags "-X main.version=dev" -o acontext-cli main.go
chmod +x acontext-cli
./acontext-cli version
- name: Test install script argument parsing
run: |
# Test that the script correctly parses --version argument
# We can't fully test installation without sudo, but we can test argument parsing
OUTPUT=$(sh install.sh --version dev 2>&1 || true)
if echo "$OUTPUT" | grep -q "Using specified version: vdev"; then
echo "✓ Install script correctly parses --version argument"
else
echo "✗ Install script failed to parse --version argument"
echo "Output: $OUTPUT"
exit 1
fi
- name: Test install script error handling
run: |
# Test that the script handles invalid arguments correctly
if sh install.sh --invalid-arg 2>&1 | grep -q "Unknown option"; then
echo "✓ Install script correctly handles invalid arguments"
else
echo "✗ Install script failed to handle invalid arguments"
exit 1
fi
# Test that --version without value shows error
if sh install.sh --version 2>&1 | grep -q "Version number required"; then
echo "✓ Install script correctly validates --version argument"
else
echo "✗ Install script failed to validate --version argument"
exit 1
fi