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
239 changes: 239 additions & 0 deletions .github/workflows/cut-sdk-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Cut SDK Release

on:
workflow_dispatch:
inputs:
spec_version:
description: "UCP specification version (YYYY-MM-DD, >= 2026-08-25)"
required: true
type: string
bump:
description: "Version bump mode"
required: true
type: choice
options:
- initial
- patch
- minor
- publish-existing
default: initial
ucp_sha:
description: "Optional 40-char commit SHA on ucp release/<spec_version> (defaults to HEAD)"
required: false
type: string
default: ""
publish_release:
description: "Create tag v<NEW_VERSION> and publish GitHub Release to trigger PyPI publish"
required: false
type: boolean
default: true

permissions:
contents: read

concurrency:
group: cut-sdk-release-${{ inputs.spec_version }}
cancel-in-progress: false

jobs:
cut-release:
name: Cut and tag SDK release
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Validate inputs, clone UCP specification, and prepare release branch
id: prep
env:
SPEC_VERSION: ${{ inputs.spec_version }}
BUMP_MODE: ${{ inputs.bump }}
INPUT_UCP_SHA: ${{ inputs.ucp_sha }}
PUBLISH_RELEASE: ${{ inputs.publish_release }}
run: |
set -euo pipefail
if [[ ! "$SPEC_VERSION" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] \
|| [ "$(date -u -d "$SPEC_VERSION" +%Y-%m-%d 2>/dev/null || true)" != "$SPEC_VERSION" ]; then
echo "::error::Invalid calendar date spec_version '$SPEC_VERSION' (expected YYYY-MM-DD)"
exit 1
fi
EPOCH="${SPEC_VERSION//-/}"
(( 10#$EPOCH >= 20260825 )) || { echo "::error::spec_version '$SPEC_VERSION' has epoch $EPOCH < 20260825"; exit 1; }
case "$BUMP_MODE" in
initial|patch|minor) ;;
publish-existing)
[ "$PUBLISH_RELEASE" = "true" ] || { echo "::error::bump=publish-existing requires publish_release=true"; exit 1; }
;;
*) echo "::error::Unsupported bump '$BUMP_MODE'"; exit 1 ;;
esac

RELEASE_BRANCH="release/${SPEC_VERSION}"
rm -rf "$RUNNER_TEMP/ucp-spec"
git clone --filter=blob:none --no-checkout \
"${UCP_REMOTE_URL:-https://github.com/Universal-Commerce-Protocol/ucp.git}" "$RUNNER_TEMP/ucp-spec"
git -C "$RUNNER_TEMP/ucp-spec" show-ref --verify --quiet "refs/remotes/origin/${RELEASE_BRANCH}" \
|| { echo "::error::Branch ${RELEASE_BRANCH} does not exist in Universal-Commerce-Protocol/ucp"; exit 1; }

if [ -z "$INPUT_UCP_SHA" ]; then
RESOLVED_UCP_SHA="$(git -C "$RUNNER_TEMP/ucp-spec" rev-parse "origin/${RELEASE_BRANCH}")"
else
[[ "$INPUT_UCP_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::Invalid 40-char ucp_sha '$INPUT_UCP_SHA'"; exit 1; }
git -C "$RUNNER_TEMP/ucp-spec" cat-file -e "${INPUT_UCP_SHA}^{commit}" 2>/dev/null \
|| { echo "::error::ucp_sha '$INPUT_UCP_SHA' does not exist in ucp"; exit 1; }
git -C "$RUNNER_TEMP/ucp-spec" merge-base --is-ancestor "$INPUT_UCP_SHA" "origin/${RELEASE_BRANCH}" \
|| { echo "::error::ucp_sha '$INPUT_UCP_SHA' is not an ancestor of origin/${RELEASE_BRANCH} in ucp"; exit 1; }
RESOLVED_UCP_SHA="$INPUT_UCP_SHA"
fi
git -C "$RUNNER_TEMP/ucp-spec" checkout --detach "$RESOLVED_UCP_SHA"

if [ "$BUMP_MODE" = "initial" ]; then
! git show-ref --verify --quiet "refs/remotes/origin/${RELEASE_BRANCH}" \
|| { echo "::error::Branch ${RELEASE_BRANCH} already exists; use patch, minor, or publish-existing"; exit 1; }
git checkout -B "$RELEASE_BRANCH" origin/main
NEW_VERSION="${EPOCH}.0.0"
else
git show-ref --verify --quiet "refs/remotes/origin/${RELEASE_BRANCH}" \
|| { echo "::error::Branch ${RELEASE_BRANCH} does not exist; use bump=initial first"; exit 1; }
git checkout -B "$RELEASE_BRANCH" "origin/${RELEASE_BRANCH}"
CURRENT_VERSION="$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
if [[ ! "$CURRENT_VERSION" =~ ^${EPOCH}\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::pyproject.toml version '$CURRENT_VERSION' does not match canonical ${EPOCH}.MINOR.PATCH"
exit 1
fi
MINOR="${BASH_REMATCH[1]}"; PATCH="${BASH_REMATCH[2]}"
if [ "$BUMP_MODE" = "publish-existing" ]; then
NEW_VERSION="$CURRENT_VERSION"
[ -f ucp-lock.json ] || { echo "::error::ucp-lock.json is missing on ${RELEASE_BRANCH}"; exit 1; }
jq -e --arg ref "$RELEASE_BRANCH" --arg sha "$RESOLVED_UCP_SHA" \
'.channel == "release" and .ucp_ref == $ref and .ucp_sha == $sha' ucp-lock.json >/dev/null \
|| { echo "::error::ucp-lock.json does not match prepared ${RELEASE_BRANCH} @ ${RESOLVED_UCP_SHA}"; exit 1; }
elif [ "$BUMP_MODE" = "patch" ]; then
NEW_VERSION="${EPOCH}.${MINOR}.$((PATCH + 1))"
else
NEW_VERSION="${EPOCH}.$((MINOR + 1)).0"
fi
fi
Comment on lines +107 to +133

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When dispatched with publish_release: false, this workflow still commits and pushes NEW_VERSION (${EPOCH}.0.0 or the bumped patch/minor version) to origin/${RELEASE_BRANCH} without creating the tag/release. There is currently no way to subsequently publish that prepared version via cut-sdk-release.yml: re-running bump=initial fails at L116–119 because ${RELEASE_BRANCH} already exists, while running bump=patch increments to .0.1 (L147) and permanently skips .0.0.

Consider adding a publish-existing / none option (or allowing bump=initial when origin/${RELEASE_BRANCH} is at ${EPOCH}.0.0 and refs/tags/v${EPOCH}.0.0 does not exist yet), and failing loudly at L280 if git diff --cached --quiet is unexpectedly empty during a version bump.

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated in 79a8c53. Added a publish-existing option to bump that verifies the prepared commit and lockfile on the release branch and tags/publishes it without bumping past .0.0, and made initial/patch/minor bumps fail loudly if the staged diff is empty.


prep_tag_rc=0
git ls-remote --exit-code --tags origin "refs/tags/v${NEW_VERSION}" >/dev/null || prep_tag_rc=$?
[ "$prep_tag_rc" -eq 2 ] || { echo "::error::Tag v${NEW_VERSION} already exists or remote check failed (rc=${prep_tag_rc})"; exit 1; }

UCP_SCHEMA_VERSION="2.0.0"
if [ -f ucp-lock.json ]; then
UCP_SCHEMA_VERSION="$(jq -er '.ucp_schema_version // "2.0.0" | select(type == "string" and test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))' ucp-lock.json)"
fi
printf 'release_branch=%s\nnew_version=%s\nucp_schema_version=%s\n' \
"$RELEASE_BRANCH" "$NEW_VERSION" "$UCP_SCHEMA_VERSION" >> "$GITHUB_OUTPUT"

- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true

- name: Regenerate models, update version, and run tests
env:
BUMP_MODE: ${{ inputs.bump }}
RELEASE_BRANCH: ${{ steps.prep.outputs.release_branch }}
NEW_VERSION: ${{ steps.prep.outputs.new_version }}
UCP_SCHEMA_VERSION: ${{ steps.prep.outputs.ucp_schema_version }}
run: |
set -euo pipefail
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
base_url="https://github.com/Universal-Commerce-Protocol/ucp-schema/releases/download/v${UCP_SCHEMA_VERSION}"
curl -fsSL --retry 3 -o "$tmp_dir/ucp-schema-linux-x86_64" "${base_url}/ucp-schema-linux-x86_64"
curl -fsSL --retry 3 -o "$tmp_dir/SHA256SUMS" "${base_url}/SHA256SUMS"
(cd "$tmp_dir" && sha256sum -c --ignore-missing SHA256SUMS)
mkdir -p "$HOME/.local/bin"
install -m 0755 "$tmp_dir/ucp-schema-linux-x86_64" "$HOME/.local/bin/ucp-schema"
export PATH="$HOME/.local/bin:$PATH"

if [ "$BUMP_MODE" = "publish-existing" ]; then
./generate_models.sh --from-lock --spec-dir "$RUNNER_TEMP/ucp-spec"
if [ -n "$(git status --porcelain -- src/ucp_sdk pyproject.toml ucp-lock.json)" ]; then
echo "::error::Prepared release commit on ${RELEASE_BRANCH} has model drift against ucp-lock.json"
git status --short -- src/ucp_sdk pyproject.toml ucp-lock.json
exit 1
fi
else
./generate_models.sh --spec-dir "$RUNNER_TEMP/ucp-spec" --channel release --ref "$RELEASE_BRANCH" --write-lock
uv version --frozen "$NEW_VERSION"
fi

uv run python -m unittest discover -s tests -p "test_*.py"
uv build
rm -rf dist

- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write

- name: Commit, push release branch, and publish GitHub Release
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
REPOSITORY: ${{ github.repository }}
SPEC_VERSION: ${{ inputs.spec_version }}
BUMP_MODE: ${{ inputs.bump }}
RELEASE_BRANCH: ${{ steps.prep.outputs.release_branch }}
NEW_VERSION: ${{ steps.prep.outputs.new_version }}
PUBLISH_RELEASE: ${{ inputs.publish_release }}
run: |
set -euo pipefail
EPOCH="${SPEC_VERSION//-/}"
tag_rc=0
git ls-remote --exit-code --tags origin "refs/tags/v${NEW_VERSION}" >/dev/null || tag_rc=$?
[ "$tag_rc" -eq 2 ] || { echo "::error::Tag v${NEW_VERSION} already exists or remote check failed (rc=${tag_rc})"; exit 1; }

BOT_NAME="${APP_SLUG:-ucp-automation}[bot]"
BOT_ID="$(gh api "/users/${BOT_NAME}" --jq .id)"
[[ "$BOT_ID" =~ ^[0-9]+$ ]] || { echo "::error::Invalid bot user ID for ${BOT_NAME}"; exit 1; }
git config user.name "$BOT_NAME"
git config user.email "${BOT_ID}+${BOT_NAME}@users.noreply.github.com"

if [ "$BUMP_MODE" = "publish-existing" ]; then
git fetch origin "+refs/heads/${RELEASE_BRANCH}:refs/remotes/origin/${RELEASE_BRANCH}"
[ "$(git rev-parse HEAD)" = "$(git rev-parse "origin/${RELEASE_BRANCH}")" ] \
|| { echo "::error::origin/${RELEASE_BRANCH} changed during run"; exit 1; }
else
git add -- pyproject.toml ucp-lock.json src/ucp_sdk/models/schemas
! git diff --cached --quiet || { echo "::error::Expected changes for v${NEW_VERSION}, but staged diff is empty"; exit 1; }
git commit -m "chore(release): v${NEW_VERSION}"
git push "https://x-access-token:${GH_TOKEN}@github.com/${REPOSITORY}.git" "HEAD:refs/heads/${RELEASE_BRANCH}"
fi

if [ "$PUBLISH_RELEASE" = "true" ]; then
LATEST_RELEASE_EPOCH="$(gh api --paginate "/repos/${REPOSITORY}/releases?per_page=100" | jq -sr '
[.[][] | select((.draft | not) and (.prerelease | not)) | .tag_name
| capture("^v(?<e>[0-9]{8})\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$").e | tonumber] | max // 0
')"
LATEST_FLAG="--latest"
if (( 10#$EPOCH < 10#$LATEST_RELEASE_EPOCH )); then LATEST_FLAG="--latest=false"; fi

git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
git push "https://x-access-token:${GH_TOKEN}@github.com/${REPOSITORY}.git" "refs/tags/v${NEW_VERSION}"
gh release create "v${NEW_VERSION}" --repo "$REPOSITORY" --verify-tag \
--title "v${NEW_VERSION}" --generate-notes "$LATEST_FLAG"
fi
111 changes: 103 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
# Copyright 2026 UCP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Publish to PyPI

on:
release:
types: [published]

permissions:
contents: read

concurrency:
group: pypi-release-publish
cancel-in-progress: false

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: release
url: https://pypi.org/p/ucp-sdk
Expand All @@ -18,19 +38,94 @@ jobs:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

# Installs uv (and manages Python automatically)
- name: Install uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
enable-cache: false

- name: Verify CalVer tag, manifest version, lockfile channel, and branch ancestry
id: verify
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
if [[ ! "$RELEASE_TAG" =~ ^v([0-9]{4})([0-9]{2})([0-9]{2})\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::Release tag '$RELEASE_TAG' must match canonical vYYYYMMDD.MINOR.PATCH"
exit 1
fi
DATE_STR="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
if [ "$(date -u -d "$DATE_STR" +%Y-%m-%d 2>/dev/null || true)" != "$DATE_STR" ]; then
echo "::error::Invalid calendar date '${DATE_STR}' in release tag '$RELEASE_TAG'"
exit 1
fi
EPOCH="${DATE_STR//-/}"
if (( 10#$EPOCH < 20260825 )); then
echo "::error::Release tag '$RELEASE_TAG' has epoch $EPOCH < 20260825"
exit 1
fi
EXPECTED_VERSION="${EPOCH}.${BASH_REMATCH[4]}.${BASH_REMATCH[5]}"
EXPECTED_BRANCH="release/${DATE_STR}"

PKG_VERSION="$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
if [[ "$PKG_VERSION" == 0.0.0* || "$PKG_VERSION" != "$EXPECTED_VERSION" ]]; then
echo "::error::pyproject.toml version '$PKG_VERSION' does not match expected release version '$EXPECTED_VERSION'"
exit 1
fi

[ -f ucp-lock.json ] || { echo "::error::ucp-lock.json is missing"; exit 1; }
LOCK_FIELDS="$(jq -er --arg ref "$EXPECTED_BRANCH" '
select(.channel == "release" and .ucp_ref == $ref) |
(.ucp_sha | select(type == "string" and test("^[0-9a-f]{40}$"))) as $sha |
(.ucp_schema_version | select(type == "string" and test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) as $ver |
"\($sha) \($ver)"
' ucp-lock.json)" || { echo "::error::ucp-lock.json failed release provenance validation"; exit 1; }
read -r UCP_SHA UCP_SCHEMA_VERSION <<< "$LOCK_FIELDS"

git fetch origin "+refs/heads/${EXPECTED_BRANCH}:refs/remotes/origin/${EXPECTED_BRANCH}"
git merge-base --is-ancestor HEAD "origin/${EXPECTED_BRANCH}" \
|| { echo "::error::Release commit HEAD is not an ancestor of origin/${EXPECTED_BRANCH}"; exit 1; }

rm -rf "$RUNNER_TEMP/ucp-spec"
git clone --filter=blob:none --no-checkout \
"${UCP_REMOTE_URL:-https://github.com/Universal-Commerce-Protocol/ucp.git}" "$RUNNER_TEMP/ucp-spec"
git -C "$RUNNER_TEMP/ucp-spec" show-ref --verify --quiet "refs/remotes/origin/${EXPECTED_BRANCH}" \
|| { echo "::error::Upstream branch ${EXPECTED_BRANCH} does not exist in ucp"; exit 1; }
git -C "$RUNNER_TEMP/ucp-spec" cat-file -e "${UCP_SHA}^{commit}" 2>/dev/null \
|| { echo "::error::ucp_sha '${UCP_SHA}' does not exist in ucp"; exit 1; }
git -C "$RUNNER_TEMP/ucp-spec" merge-base --is-ancestor "$UCP_SHA" "origin/${EXPECTED_BRANCH}" \
|| { echo "::error::ucp_sha '${UCP_SHA}' is not an ancestor of origin/${EXPECTED_BRANCH} in ucp"; exit 1; }
git -C "$RUNNER_TEMP/ucp-spec" checkout --detach "$UCP_SHA"
echo "ucp_schema_version=${UCP_SCHEMA_VERSION}" >> "$GITHUB_OUTPUT"

- name: Run unit tests, verify model drift, and build package
env:
UCP_SCHEMA_VERSION: ${{ steps.verify.outputs.ucp_schema_version }}
run: |
set -euo pipefail
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
base_url="https://github.com/Universal-Commerce-Protocol/ucp-schema/releases/download/v${UCP_SCHEMA_VERSION}"
curl -fsSL --retry 3 -o "$tmp_dir/ucp-schema-linux-x86_64" "${base_url}/ucp-schema-linux-x86_64"
curl -fsSL --retry 3 -o "$tmp_dir/SHA256SUMS" "${base_url}/SHA256SUMS"
(cd "$tmp_dir" && sha256sum -c --ignore-missing SHA256SUMS)
mkdir -p "$HOME/.local/bin"
install -m 0755 "$tmp_dir/ucp-schema-linux-x86_64" "$HOME/.local/bin/ucp-schema"
export PATH="$HOME/.local/bin:$PATH"

# 'uv build' automatically creates the sdist and wheel in 'dist/'
- name: Build package
run: uv build
uv run python -m unittest discover -s tests -p "test_*.py"
./generate_models.sh --from-lock --spec-dir "$RUNNER_TEMP/ucp-spec"
if [ -n "$(git status --porcelain -- src/ucp_sdk pyproject.toml ucp-lock.json)" ]; then
echo "::error::Committed models or release metadata differ from ucp-lock.json regeneration"
git status --short -- src/ucp_sdk pyproject.toml ucp-lock.json
git --no-pager diff -- src/ucp_sdk pyproject.toml ucp-lock.json
exit 1
fi
rm -rf dist && uv build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
Loading