Skip to content
Open
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
40 changes: 40 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# Pre-commit hook to enforce code quality
# Runs golangci-lint on staged Go files

set -e

# Check if we're in the project root
if [ ! -f "go.mod" ]; then
echo "Error: This script must be run from the project root"
exit 1
fi

# Check for staged Go files
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)

if [ -z "$STAGED_GO_FILES" ]; then
exit 0
fi

echo "Running pre-commit checks..."

# Ensure golangci-lint is installed via taskw (uses pinned version)
./taskw install:golangci-lint --silent

# Get unique directories containing staged Go files
STAGED_DIRS=$(echo "$STAGED_GO_FILES" | xargs -n1 dirname | sort -u | sed 's|^|./|')

# Run golangci-lint on affected packages, only reporting new issues
if ! .build/.bin/golangci-lint run --new-from-rev=HEAD $STAGED_DIRS; then
echo ""
echo "Pre-commit checks FAILED"
echo ""
echo "Fix the issues above and try again."
echo " ./taskw lint # Run linter with auto-fix"
echo ""
echo "Use --no-verify to bypass (not recommended)."
exit 1
fi

echo "Pre-commit checks passed."
12 changes: 12 additions & 0 deletions .githooks/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Setup script for git hooks
# Run this once after cloning the repository

set -e

# Configure git to use .githooks directory
git config core.hooksPath .githooks

echo "Git hooks configured."
echo "The pre-commit hook will run golangci-lint before each commit."
echo "To disable: git config --unset core.hooksPath"
1 change: 1 addition & 0 deletions .taskversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v3.40.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# ai-sdk-go
# ai-sdk-go

34 changes: 34 additions & 0 deletions taskw
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -eu

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";

test -f "${SCRIPT_DIR}/.taskversion"

VERSION=$(cat "${SCRIPT_DIR}/.taskversion")
TASK_DIR="${SCRIPT_DIR}/.build/bin"
TASK="${TASK_DIR}/task"

mkdir -p "$TASK_DIR"
mkdir -p .build/

# If the correct version of task is installed already (is in PATH), use it instead of downloading.
# This avoids obsolete downloads of task in CI, where we install it in Dockerfile.
if command -v task > /dev/null && [[ $(task --version | awk '{print $3}') == "${VERSION}" ]]; then
TASK=$(which task)
fi

if [[ ! -x $TASK ]] || [[ $($TASK --version | awk '{print $3}') != "${VERSION}" ]]; then
echo "--- updating task to ${VERSION}"
if ! sh -c "$(curl --retry 5 --retry-delay 0 --retry-max-time 60 --location https://raw.githubusercontent.com/go-task/task/refs/tags/${VERSION}/install-task.sh)" -- -d -b "${TASK_DIR}" "${VERSION}"; then
echo "--- primary source failed, falling back to taskfile.dev"
sh -c "$(curl --retry 5 --retry-delay 0 --retry-max-time 60 --location https://taskfile.dev/install.sh)" -- -d -b "${TASK_DIR}" "${VERSION}"
fi
fi

if ! command -v realpath &>/dev/null; then
echo "--- realpath command not found. Please install 'coreutils' package for your OS to continue. Exiting"
exit 1
fi

$TASK -d "$SCRIPT_DIR" "$@"