Repository navigation
ci(release): add CalVer release guards and cut-sdk-release workflow #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+342
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ecf76b
ci(release): add CalVer release guards and cut-sdk-release workflow
gsmith85 b62b9ff
ci(release): allow 2026-08-25 CalVer release epoch floor
gsmith85 8b2fd24
ci(release): harden tag collision guard, concurrency, and tomllib par…
gsmith85 2d49d7c
ci(release): add publish-existing mode, upstream ancestry, and releas…
gsmith85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 pushesNEW_VERSION(${EPOCH}.0.0or the bumped patch/minor version) toorigin/${RELEASE_BRANCH}without creating the tag/release. There is currently no way to subsequently publish that prepared version viacut-sdk-release.yml: re-runningbump=initialfails at L116–119 because${RELEASE_BRANCH}already exists, while runningbump=patchincrements to.0.1(L147) and permanently skips.0.0.Consider adding a
publish-existing/noneoption (or allowingbump=initialwhenorigin/${RELEASE_BRANCH}is at${EPOCH}.0.0andrefs/tags/v${EPOCH}.0.0does not exist yet), and failing loudly at L280 ifgit diff --cached --quietis unexpectedly empty during a version bump.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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-existingoption tobumpthat verifies the prepared commit and lockfile on the release branch and tags/publishes it without bumping past.0.0, and madeinitial/patch/minorbumps fail loudly if the staged diff is empty.