From 56462014f76d2cdf4702bf7011cd94030d2996b7 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 3 Sep 2025 09:51:07 +0100 Subject: [PATCH 1/4] chore: add release automation script --- MAINTAINERS.md | 21 ++++---------------- main.go | 2 +- release.sh | 37 ++++++++++++++++++++++++++++++++++++ set_version.sh => version.sh | 2 ++ 4 files changed, 44 insertions(+), 18 deletions(-) create mode 100755 release.sh rename set_version.sh => version.sh (96%) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 5e8f39f..32954b3 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -8,24 +8,11 @@ If everything seems OK, you can proceed to do the following: 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`: +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 - # Ensure your local copy is up to date with main. Be sure to stash any changes first. - git fetch origin - git reset --hard origin/main - # 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/main.go b/main.go index 571cf32..67fe4f3 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main //go:generate sh -c "go run main.go server --print-openapi dummy > openapi.json" -//go:generate ./set_version.sh +//go:generate ./version.sh import "github.com/coder/agentapi/cmd" func main() { diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..a60d3a9 --- /dev/null +++ b/release.sh @@ -0,0 +1,37 @@ +#!/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." +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/tag/${TAG_NAME}" diff --git a/set_version.sh b/version.sh similarity index 96% rename from set_version.sh rename to version.sh index d31c32b..7a0d187 100755 --- a/set_version.sh +++ b/version.sh @@ -11,3 +11,5 @@ 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}" From 206b4cc7a1484eff4ddb1696fd2731fddb8ed65a Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 3 Sep 2025 11:29:31 +0100 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Mathias Fredriksson --- release.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/release.sh b/release.sh index a60d3a9..75bab1f 100755 --- a/release.sh +++ b/release.sh @@ -26,6 +26,7 @@ echo "VERSION=${VERSION}" 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}" @@ -34,4 +35,4 @@ git fetch --tags git tag -a "${TAG_NAME}" -m "${TAG_NAME}" git push origin tag "${TAG_NAME}" -echo "https://github.com/coder/agentapi/releases/tag/${TAG_NAME}" +echo "https://github.com/coder/agentapi/releases/new?tag=${TAG_NAME}" From 3de1e6c478a9d982b95dc41629f175a323e94d50 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 3 Sep 2025 11:32:47 +0100 Subject: [PATCH 3/4] make gen --- openapi.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openapi.json b/openapi.json index c0ee716..c3992ba 100644 --- a/openapi.json +++ b/openapi.json @@ -326,10 +326,10 @@ { "properties": { "data": { - "$ref": "#/components/schemas/MessageUpdateBody" + "$ref": "#/components/schemas/StatusChangeBody" }, "event": { - "const": "message_update", + "const": "status_change", "description": "The event name.", "type": "string" }, @@ -346,16 +346,16 @@ "data", "event" ], - "title": "Event message_update", + "title": "Event status_change", "type": "object" }, { "properties": { "data": { - "$ref": "#/components/schemas/StatusChangeBody" + "$ref": "#/components/schemas/MessageUpdateBody" }, "event": { - "const": "status_change", + "const": "message_update", "description": "The event name.", "type": "string" }, @@ -372,7 +372,7 @@ "data", "event" ], - "title": "Event status_change", + "title": "Event message_update", "type": "object" } ] From 856d3872614914a004bcc58504bcfcbc1c003150 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 3 Sep 2025 11:51:06 +0100 Subject: [PATCH 4/4] make gen --- openapi.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openapi.json b/openapi.json index c3992ba..c0ee716 100644 --- a/openapi.json +++ b/openapi.json @@ -326,10 +326,10 @@ { "properties": { "data": { - "$ref": "#/components/schemas/StatusChangeBody" + "$ref": "#/components/schemas/MessageUpdateBody" }, "event": { - "const": "status_change", + "const": "message_update", "description": "The event name.", "type": "string" }, @@ -346,16 +346,16 @@ "data", "event" ], - "title": "Event status_change", + "title": "Event message_update", "type": "object" }, { "properties": { "data": { - "$ref": "#/components/schemas/MessageUpdateBody" + "$ref": "#/components/schemas/StatusChangeBody" }, "event": { - "const": "message_update", + "const": "status_change", "description": "The event name.", "type": "string" }, @@ -372,7 +372,7 @@ "data", "event" ], - "title": "Event message_update", + "title": "Event status_change", "type": "object" } ]