diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index c38c6ff..5e10425 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -33,3 +33,8 @@ jobs: uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: version: v2.1 + + - name: Check for unstaged changes + run: | + make gen + ./check_unstaged.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ac9b26..10e2ba2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,11 @@ jobs: - name: Install Chat Dependencies run: cd chat && bun install + - name: Run make gen and check for unstaged changes + run: | + make gen + ./check_unstaged.sh + - name: Build and Upload env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index f956c6c..99b4e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v0.6.2 + +- Fix incorrect version string. + +## v0.6.1 + +### Features +- Handle animation on Amp cli start screen. + ## v0.6.0 ### Features diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 3fbc5af..32954b3 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,27 +5,14 @@ Before performing a release, perform a local "smoke-test". If everything seems OK, you can proceed to do the following: -1. Update the version string in the following places: - - `openapi.json` - - `chat/package.json` - - `lib/httpapi/server.go` +1. Update the version string in `internal/version/version.go` and run `make gen`. 2. Add details in `CHANGELOG.md` on what changed. 3. Create a PR with the subject `chore: update version to X.Y.Z` -4. Once the above PR is approved and merged, create a new git tag `vX.Y.Z` pointing to the commit of the above PR merged to `main`:S +4. Once the above PR is approved and merged, update your local branch and run `release.sh`. + If the script reports errors, fix them before continuing. + If there are no issues, it will output the Github tag URL. - ```shell - # Fetch existing tags first! - git fetch --tags - git tag -a vX.Y.Z -m 'vX.Y.Z' - ``` - -5. Push the tag: - - ```shell - git push origin tag vX.Y.Z - ``` - -6. Visit `https://github.com/coder/agentapi/releases/tag/vX.Y.Z` and "Create release from tag". +5. Visit `https://github.com/coder/agentapi/releases/tag/vX.Y.Z` and "Create release from tag". - Select the tag you pushed previously. - Select the previous tag and "Generate release notes". Amend as required. diff --git a/Makefile b/Makefile index 1692d07..e74757c 100644 --- a/Makefile +++ b/Makefile @@ -16,5 +16,9 @@ embed: $(CHAT_SOURCES_STAMP) @echo "Chat build is up to date." .PHONY: build -build: embed +build: gen embed CGO_ENABLED=0 go build -o ${BINPATH} main.go + +.PHONY: gen +gen: + go generate ./... diff --git a/chat/package.json b/chat/package.json index 32b6684..e6e79e0 100644 --- a/chat/package.json +++ b/chat/package.json @@ -1,6 +1,6 @@ { "name": "chat", - "version": "0.6.0", + "version": "0.6.2", "private": true, "scripts": { "dev": "next dev --turbopack", @@ -45,4 +45,4 @@ "tw-animate-css": "^1.3.0", "typescript": "^5" } -} \ No newline at end of file +} diff --git a/check_unstaged.sh b/check_unstaged.sh new file mode 100755 index 0000000..98cd3cd --- /dev/null +++ b/check_unstaged.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +FILES=() +IFS=$'\n' read -r -d '' -a FILES < <(git ls-files --other --modified --exclude-standard && printf '\0') +if [[ ${#FILES[@]} -gt 0 ]]; then + + echo + echo "The following files contain unstaged changes:" + echo + for file in "${FILES[@]}"; do + echo " - $file" + done + + echo + echo "These are the changes:" + echo + for file in "${FILES[@]}"; do + git --no-pager diff -- "$file" 1>&2 + done + + echo + echo "ERROR: Unstaged changes, see above for details." + exit 1 +fi diff --git a/cmd/root.go b/cmd/root.go index 9f7ac65..2980d19 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,6 +6,7 @@ import ( "github.com/coder/agentapi/cmd/attach" "github.com/coder/agentapi/cmd/server" + "github.com/coder/agentapi/internal/version" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ var rootCmd = &cobra.Command{ Use: "agentapi", Short: "AgentAPI CLI", Long: `AgentAPI - HTTP API for Claude Code, Goose, Aider, Gemini and Codex`, - Version: "0.4.1", + Version: version.Version, } func Execute() { diff --git a/cmd/server/server.go b/cmd/server/server.go index 33c294e..912ab66 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -184,6 +184,10 @@ func CreateServerCmd() *cobra.Command { return } logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) + if viper.GetBool(FlagPrintOpenAPI) { + // We don't want log output here. + logger = slog.New(logctx.DiscardHandler) + } ctx := logctx.WithLogger(context.Background(), logger) if err := runServer(ctx, logger, cmd.Flags().Args()); err != nil { fmt.Fprintf(os.Stderr, "%+v\n", err) diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..cb53b66 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,5 @@ +// package version defines the current version of agentapi. + +package version + +var Version = "0.6.2" diff --git a/lib/httpapi/server.go b/lib/httpapi/server.go index fb45ad4..e8abab9 100644 --- a/lib/httpapi/server.go +++ b/lib/httpapi/server.go @@ -13,6 +13,7 @@ import ( "time" "unicode" + "github.com/coder/agentapi/internal/version" "github.com/coder/agentapi/lib/logctx" mf "github.com/coder/agentapi/lib/msgfmt" st "github.com/coder/agentapi/lib/screentracker" @@ -188,7 +189,7 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { }) router.Use(corsMiddleware.Handler) - humaConfig := huma.DefaultConfig("AgentAPI", "0.6.0") + humaConfig := huma.DefaultConfig("AgentAPI", version.Version) humaConfig.Info.Description = "HTTP API for Claude Code, Goose, and Aider.\n\nhttps://github.com/coder/agentapi" api := humachi.New(router, humaConfig) formatMessage := func(message string, userInput string) string { diff --git a/lib/logctx/logctx.go b/lib/logctx/logctx.go index 8f820fc..7280dab 100644 --- a/lib/logctx/logctx.go +++ b/lib/logctx/logctx.go @@ -23,3 +23,14 @@ func From(ctx context.Context) *slog.Logger { } panic("no logger found in context") } + +// plucked from log/slog +// remove once we update to go 1.24 +var DiscardHandler slog.Handler = discardHandler{} + +type discardHandler struct{} + +func (dh discardHandler) Enabled(context.Context, slog.Level) bool { return false } +func (dh discardHandler) Handle(context.Context, slog.Record) error { return nil } +func (dh discardHandler) WithAttrs(attrs []slog.Attr) slog.Handler { return dh } +func (dh discardHandler) WithGroup(name string) slog.Handler { return dh } diff --git a/main.go b/main.go index ad53ab8..67fe4f3 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,7 @@ package main +//go:generate sh -c "go run main.go server --print-openapi dummy > openapi.json" +//go:generate ./version.sh import "github.com/coder/agentapi/cmd" func main() { diff --git a/openapi.json b/openapi.json index 19c4961..c0ee716 100644 --- a/openapi.json +++ b/openapi.json @@ -307,7 +307,7 @@ "info": { "description": "HTTP API for Claude Code, Goose, and Aider.\n\nhttps://github.com/coder/agentapi", "title": "AgentAPI", - "version": "0.6.0" + "version": "0.6.2" }, "openapi": "3.1.0", "paths": { @@ -497,4 +497,4 @@ } } } -} \ No newline at end of file +} diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..75bab1f --- /dev/null +++ b/release.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +GIT_BRANCH="${GIT_BRANCH:-main}" +echo "GIT_BRANCH=${GIT_BRANCH}" +LOCAL_HEAD=$(git rev-parse --short "${GIT_BRANCH}") +echo "LOCAL_HEAD=${LOCAL_HEAD}" +REMOTE_HEAD=$(git rev-parse --short origin/"${GIT_BRANCH}") +echo "REMOTE_HEAD=${REMOTE_HEAD}" +if [[ "${LOCAL_HEAD}" != "${REMOTE_HEAD}" ]]; then + echo "Please ensure your local branch is up to date before continuing." + exit 1 +fi + +VERSION="" +if ! VERSION=$(./version.sh); then + echo "version.sh exited with a non-zero status code. Fix this before continuing." + exit 1 +elif [[ -z "${VERSION}" ]]; then + echo "Version reported by version.sh was empty. Fix this before continuing." + exit 1 +fi + +echo "VERSION=${VERSION}" +./check_unstaged.sh || exit 1 + +if ! grep -q "## v${VERSION}" CHANGELOG.md; then + echo "Please update CHANGELOG.md with details for ${VERSION} before continuing." + exit 1 +fi + +TAG_NAME="v${VERSION}" +echo "TAG_NAME=${TAG_NAME}" +git fetch --tags +git tag -a "${TAG_NAME}" -m "${TAG_NAME}" +git push origin tag "${TAG_NAME}" + +echo "https://github.com/coder/agentapi/releases/new?tag=${TAG_NAME}" diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..7a0d187 --- /dev/null +++ b/version.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +if ! command -v go >/dev/null 2>&1; then + echo "go is required to run this script" && exit 1 +elif ! command -v jq >/dev/null 2>&1; then + echo "jq is required to run this script" && exit 1 +fi + +version=$(go run main.go --version | awk '{print $3}') + +jq --arg version "${version}" '.info.version = $version' openapi.json > openapi.json.tmp && mv openapi.json.tmp openapi.json +jq --arg version "${version}" '.version = $version' chat/package.json > chat/package.json.tmp && mv chat/package.json.tmp chat/package.json + +echo -n "${version}"