Files
qwen-code/.github/workflows/release-sdk-python.yml
易良andQwen-Coder 64dd058c9c ci(pnpm): install with pnpm everywhere and retire package-lock.json (#11859)
* ci(pnpm): install dependencies with pnpm in CI and release

CI tests the graph release ships only if both install it the same way, so
this moves both, keeping every `npm run` script and `npm publish` as they are.

- ci.yml (7), release.yml (3) and release-vscode-companion.yml (2) install
  with `corepack pnpm install --frozen-lockfile`; release keeps
  --ignore-scripts plus its explicit postinstall and generate steps.
- setup-node drops the npm cache and sets package-manager-cache: false,
  which setup-node v5+ needs once package.json declares a pnpm
  packageManager.
- A composite action caches the pnpm store on the three always-hosted jobs;
  the ECS pool keeps its store on local disk.
- version.js no longer lets npm reify node_modules: --no-workspaces-update on
  both `npm version` calls, and a package-lock-only refresh in step 9.
- The notices generator, prepare-package's sharp pin and the standalone
  release's native package specs read the installed tree or pnpm-lock.yaml
  instead of package-lock.json keys.
- New size baselines for the three workflows, which were already over them.

* chore(vscode): regenerate NOTICES from the pnpm-installed tree

Generated in CI (pnpm Worktree Smoke on ubuntu-latest) by the ported
generator. Same entry set as before except the five packages npm and pnpm
resolve differently: fdir 6.5.0, picomatch 4.0.5, mdurl 2.1.0,
@types/node 22.20.1 and mime-db 1.52.0 (form-data's pinned copy). No entry
lacks a license text or repository.

* fix(pnpm): resolve undeclared zod peers to the repo's zod, as npm does

The first CI run on this branch failed the export renderer's size budget:
1,930,015 bytes against 1,930,000, where the same commit built on npm's
tree comes to 1,858,186. Comparing both trees' esbuild metafiles and
prebuilt bundles put the whole difference in web-shell's transcript.js
(+100,903 bytes pre-minify), and the added code is zod 4 plus the
@modelcontextprotocol/ext-apps schemas; the sdk daemon bundle is identical.

web-shell bundles ext-apps, whose zod and MCP SDK are peers, and declares
no zod itself, so pnpm filled the peer with the highest locked zod (4.4.3)
while npm serves the hoisted 3.25.76. Declaring zod 3.25.76 as a root
devDependency makes pnpm resolve every such peer to it
(resolve-peers-from-workspace-root is on by default), which is npm's
hoisting behaviour. mobile-mcp keeps its own zod 4.4.3, as under npm; the
npm tree does not change.

* fix(pnpm): keep npm's root @types/node so root-level typechecks match

The no-AK integration gate typechecks integration-tests/, which takes
Node's types from the root node_modules. npm hoists @types/node 20.19.1
there, because acp-bridge and core pin it; pnpm, with no root declaration,
hoisted 22.20.1, whose spawnSync overloads type process-registry.ts's
stdout as string | NonSharedBuffer and fail TS2322. The same code passes on
every npm-installed PR.

Declaring 20.19.1 as a root devDependency puts npm's copy back where a
root-level tsconfig looks. The npm tree does not change.

* ci(pnpm): install with pnpm in the remaining workflows

The follow-up to switching CI and release: every other workflow that
installs the root workspace now uses the pinned pnpm with
--frozen-lockfile, so no job tests a graph that release does not ship.

- e2e, tui-parity, repo-hygiene, web-shell-visuals, serve-ab, sdk-java,
  windows-runner-smoke, qwen-autofix, the SDK releases, finalize-release,
  sync-release-to-oss, the root install in desktop-release and
  cd-cua-driver, and the sandbox Dockerfile.
- setup-node drops the root npm cache (package-manager-cache: false); hosted
  jobs restore the pnpm store through the shared composite action, and
  qwen-autofix keeps af-012's rule that the persistent pool restores no
  remote cache.
- serve-ab and web-shell-visuals install a separate base checkout that can
  predate pnpm-lock.yaml, so those installs fall back to npm ci there.
- Out of scope, unchanged: packages with their own lockfile (cua-driver's
  TypeScript SDK, desktop-shell, live-host, mobile-mcp), and the triage
  lanes with npm-cache.yml and the npm audit gate, which move with the
  package-lock.json retirement.
- New size baselines for the touched workflows; qwen-autofix stays under
  the 470000-byte gate.

* fix(pnpm): link the workspace packages that root-level code imports

npm links every workspace package into the root node_modules, so
integration-tests/ and scripts/, which are not workspace packages
themselves, can import @qwen-code/* by name. pnpm links a workspace
package only where it is a declared dependency, and the root declared
none, so the no-AK integration gate could not find
@qwen-code/qwen-code-core.

The root now declares the seven packages that root-level code imports at
runtime as file: devDependencies: acp-bridge, channel-base, the CLI,
core, sdk, web-shell and web-templates. npm already links them, so its
tree does not change (letting npm re-resolve the lock reproduces the
same root entry); .pnpmfile.mjs rewrites them to workspace:*, which pnpm
links at the root.

* ci(pnpm): move triage, the store producer and the root audit to pnpm

- qwen-triage's verify and tmux-testing lanes install the PR with
  `corepack pnpm install --frozen-lockfile` from a restored pnpm store.
  The one retry clears node_modules first, because pnpm install, unlike
  npm ci, keeps it.
- npm-cache.yml becomes pnpm-store.yml, keyed on pnpm-lock.yaml.
- security-checks audits the root workspace with `pnpm audit`, which reads
  the lockfile, so the root install step goes. The vendored lockfiles keep
  npm, and the retry recognises pnpm's endpoint error too.
- qwen-autofix drops the hosted-only store cache: its heavy jobs forbid
  local `uses: './...'` actions, and the file sits at the size gate.
- cd-cua-driver: setup-node@v4 has no package-manager-cache input.
- package-assets fixtures install sharp rather than listing it in
  package-lock.json, matching how prepare-package now resolves it.
- AGENTS.md, CONTRIBUTING.md and the npm workspace guide install with pnpm.

* feat(review): install pnpm repos in qwen review's build/test

qwen review installed dependencies only for a repo with package-lock.json
and reported a pnpm repo as unsupported, so reviews of qwen-code would
lose their build and test once its npm lockfile goes.

- lockfileInstaller() picks npm or pnpm from the committed lockfile. With
  both, `packageManager: pnpm@...` chooses pnpm; anything else keeps npm.
- A pnpm repo installs with `corepack pnpm install --frozen-lockfile`
  through the same disk, budget and sandbox path as `npm ci`, and counts
  as installed once node_modules/.modules.yaml exists.
- Scripts still run through `npm run`, and the npm path is unchanged.

* ci(pnpm): retire the root package-lock.json

pnpm-lock.yaml is now the only root lockfile.

- check-lockfile keeps the pnpm integrity check and Playwright parity,
  which now reads pnpm importers and snapshots. The npm-vs-pnpm agreement
  and build-approval checks go: pnpm 11's strictDepBuilds and every CI
  install's --frozen-lockfile enforce what they covered.
- pnpm-lock-freshness.yml goes; it regenerated pnpm-lock.yaml from
  package-lock.json.
- Release: version.js drops its package-lock refresh, the release commit
  stages pnpm-lock.yaml and the SDK release stages no lockfile, so neither
  `git add` fails on the missing file. `npm version` in the SDK and
  mobile-mcp releases passes --no-workspaces-update so it cannot reinstall
  the root with npm.
- cd-mobile-mcp installs from the root pnpm lockfile. setup-node in
  cd-mobile-mcp, qwen-code-pr-review and desktop-release no longer keys an
  npm cache on the root lockfile.
- check-desktop-isolation reads pnpm importers; build.js, build_sandbox.js
  and preflight install with pnpm.
- pnpm-lock.yaml, pnpm-workspace.yaml and .pnpmfile.mjs join the autofix
  supply-chain class and repo-hygiene's deny list; pnpm-lock.yaml joins
  autofix's generated-diff exclusions, sdk-java's path filter and the
  platform-sensitivity manifests.
- .gitignore lists /package-lock.json so an npm install cannot commit it
  back. Tests and docs follow.

* fix(standalone): read the node-pty versions from the pnpm lockfile

* chore(vscode-ide-companion): regenerate NOTICES.txt after the lockfile swap

* chore(vscode-ide-companion): regenerate NOTICES.txt from the pnpm dependency tree

The committed NOTICES.txt was generated from an npm install and does not
match the tree produced by the pnpm install the release pipeline now uses
(659 resolved dependencies, differing @types/node and mime-db versions).
Regenerating with the pinned pnpm install makes the freshness check
reproducible.

* fix(ci): drop the npm cache from the daily dependency audit

actions/setup-node's npm cache keys off the root package-lock.json, which this branch retires, so the scheduled job would fail at Set up Node before the audit ran. No pull_request run reaches this workflow to catch it. The root tree is never installed here either: pnpm audit reads pnpm-lock.yaml directly.

Matches the sibling workflows that already set package-manager-cache: false; scripts/tests/security-workflows.test.js now pins it.

* chore(ci): stop banking main-side drift in the workflow size ratchet

The ratchet exists to turn a workflow's growth into one reviewed line. This branch re-recorded entries for 17 workflows it never touches, several upward by 0.4-2.8 KB - drift that happened on main, banked into the manifest without review.

Restore those to their merge-base values, so .size-baseline changes only for the 22 workflows this branch actually edits. The entries were not needed to go green: ci.yml passes the PR's base commit, so a file that drifted on main and is otherwise untouched earns a warning, not a failure.

* fix(release): initialize standalone state before main

* test(browser-use): read Playwright pin from pnpm lock

* fix(ci): address pnpm migration review blockers

* fix(desktop): stop reading the retired root lockfile

---------

Co-authored-by: Qwen-Coder <[email protected]>
2026-09-20 02:11:25 +00:00

524 lines
22 KiB
YAML

name: 'Release Python SDK'
on:
workflow_dispatch:
inputs:
version:
description: 'The version to release (e.g., v0.1.0 for stable, v0.1.1-preview.0 for preview).'
required: false
type: 'string'
ref:
description: 'The protected branch ref to release SDK from. This privileged workflow only permits main.'
required: true
type: 'string'
default: 'main'
dry_run:
description: 'Run the release flow without publishing to PyPI or creating persistent release branches/tags.'
required: true
type: 'boolean'
default: true
create_nightly_release:
description: 'Auto-apply the nightly release tag. Input version is ignored.'
required: false
type: 'boolean'
default: false
create_preview_release:
description: 'Auto-apply the preview release tag. Input version is ignored unless explicitly provided.'
required: false
type: 'boolean'
default: false
force_skip_tests:
description: 'Skip Python checks and smoke test. Production releases should keep this disabled.'
required: false
type: 'boolean'
default: false
concurrency:
group: "${{ github.workflow }}-${{ github.event.inputs.create_nightly_release == 'true' && 'nightly' || github.event.inputs.create_preview_release == 'true' && 'preview' || 'stable' }}"
cancel-in-progress: false
jobs:
release-sdk-python:
runs-on: 'ubuntu-latest'
environment:
name: 'production-release'
url: '${{ github.server_url }}/${{ github.repository }}/releases'
if: |-
${{ github.repository == 'QwenLM/qwen-code' }}
permissions:
contents: 'write'
id-token: 'write'
issues: 'write'
pull-requests: 'write'
steps:
- name: 'Validate release inputs'
env:
CREATE_NIGHTLY_RELEASE: '${{ github.event.inputs.create_nightly_release }}'
CREATE_PREVIEW_RELEASE: '${{ github.event.inputs.create_preview_release }}'
DRY_RUN_INPUT: '${{ github.event.inputs.dry_run }}'
FORCE_SKIP_TESTS: '${{ github.event.inputs.force_skip_tests }}'
MANUAL_VERSION: '${{ inputs.version }}'
REQUESTED_REF: '${{ github.event.inputs.ref || github.sha }}'
WORKFLOW_REF: '${{ github.ref }}'
run: |
if [[ "${CREATE_NIGHTLY_RELEASE}" == "true" && "${CREATE_PREVIEW_RELEASE}" == "true" ]]; then
echo "create_nightly_release and create_preview_release cannot both be true" >&2
exit 1
fi
if [[ -n "${MANUAL_VERSION}" ]]; then
if [[ ! "${MANUAL_VERSION}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-preview\.[0-9]+)?$ ]]; then
echo "Invalid version format: ${MANUAL_VERSION}" >&2
exit 1
fi
fi
case "${WORKFLOW_REF}" in
refs/heads/main)
;;
*)
echo "This privileged workflow must be launched from the protected main workflow branch." >&2
exit 1
;;
esac
case "${REQUESTED_REF}" in
main|refs/heads/main)
;;
*)
echo "This privileged workflow must use the protected main ref." >&2
exit 1
;;
esac
if [[ "${DRY_RUN_INPUT}" != "true" ]]; then
if [[ "${FORCE_SKIP_TESTS}" == "true" ]]; then
echo "force_skip_tests cannot be used when dry_run is false" >&2
exit 1
fi
fi
- name: 'Checkout'
uses: 'actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10' # v6.0.3
with:
ref: '${{ github.event.inputs.ref || github.sha }}'
fetch-depth: 0
- name: 'Set booleans for simplified logic'
env:
CREATE_NIGHTLY_RELEASE: '${{ github.event.inputs.create_nightly_release }}'
CREATE_PREVIEW_RELEASE: '${{ github.event.inputs.create_preview_release }}'
DRY_RUN_INPUT: '${{ github.event.inputs.dry_run }}'
id: 'vars'
run: |
is_nightly="false"
if [[ "${CREATE_NIGHTLY_RELEASE}" == "true" ]]; then
is_nightly="true"
fi
echo "is_nightly=${is_nightly}" >> "${GITHUB_OUTPUT}"
is_preview="false"
if [[ "${CREATE_PREVIEW_RELEASE}" == "true" ]]; then
is_preview="true"
fi
echo "is_preview=${is_preview}" >> "${GITHUB_OUTPUT}"
is_dry_run="false"
if [[ "${DRY_RUN_INPUT}" == "true" ]]; then
is_dry_run="true"
fi
echo "is_dry_run=${is_dry_run}" >> "${GITHUB_OUTPUT}"
- name: 'Capture checked-out commit'
id: 'checkout_sha'
run: |
echo "sha=$(git rev-parse HEAD)" >> "${GITHUB_OUTPUT}"
- name: 'Setup Node.js'
uses: 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e' # v6.4.0
with:
node-version-file: '.nvmrc'
package-manager-cache: false
- name: 'Get the version'
id: 'version'
run: |
set -euo pipefail
VERSION_ARGS=()
if [[ "${IS_NIGHTLY}" == "true" ]]; then
VERSION_ARGS+=(--type=nightly)
elif [[ "${IS_PREVIEW}" == "true" ]]; then
VERSION_ARGS+=(--type=preview)
if [[ -n "${MANUAL_VERSION}" ]]; then
VERSION_ARGS+=("--preview_version_override=${MANUAL_VERSION}")
fi
else
VERSION_ARGS+=(--type=stable)
if [[ -n "${MANUAL_VERSION}" ]]; then
VERSION_ARGS+=("--stable_version_override=${MANUAL_VERSION}")
fi
fi
VERSION_JSON=$(node packages/sdk-python/scripts/get-release-version.js "${VERSION_ARGS[@]}")
extract_field() {
local value
value=$(echo "$VERSION_JSON" | jq -r ".$1")
if [[ "${value}" == "null" ]]; then
echo "Failed to extract $1 from version JSON: ${VERSION_JSON}" >&2
exit 1
fi
echo "${value}"
}
RELEASE_TAG=$(extract_field releaseTag)
RELEASE_VERSION=$(extract_field releaseVersion)
PACKAGE_VERSION=$(extract_field packageVersion)
PUBLISH_CHANNEL=$(extract_field publishChannel)
PREVIOUS_RELEASE_TAG=$(extract_field previousReleaseTag)
RESUME_EXISTING_RELEASE=$(extract_field resumeExistingRelease)
echo "RELEASE_TAG=${RELEASE_TAG}" >> "$GITHUB_OUTPUT"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
echo "PUBLISH_CHANNEL=${PUBLISH_CHANNEL}" >> "$GITHUB_OUTPUT"
echo "PREVIOUS_RELEASE_TAG=${PREVIOUS_RELEASE_TAG}" >> "$GITHUB_OUTPUT"
echo "RESUME_EXISTING_RELEASE=${RESUME_EXISTING_RELEASE}" >> "$GITHUB_OUTPUT"
echo "========================================"
echo "Python SDK Release Version Info"
echo "========================================"
echo "Release Tag: ${RELEASE_TAG}"
echo "Release Version: ${RELEASE_VERSION}"
echo "Package Version: ${PACKAGE_VERSION}"
echo "Publish Channel: ${PUBLISH_CHANNEL}"
echo "Previous Release: ${PREVIOUS_RELEASE_TAG}"
echo "Resume Existing: ${RESUME_EXISTING_RELEASE}"
echo "========================================"
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
IS_NIGHTLY: '${{ steps.vars.outputs.is_nightly }}'
IS_PREVIEW: '${{ steps.vars.outputs.is_preview }}'
MANUAL_VERSION: '${{ inputs.version }}'
- name: 'Setup Python'
uses: 'actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405' # v6.2.0
with:
# Keep in sync with packages/sdk-python/pyproject.toml [project] requires-python.
python-version: '3.11'
- name: 'Install Dependencies'
run: |
corepack pnpm install --frozen-lockfile --prefer-offline --reporter=append-only
python -m pip install --upgrade pip
python -m pip install -e 'packages/sdk-python[dev]' build
- name: 'Build qwen CLI bundle'
if: |-
${{ github.event.inputs.force_skip_tests != 'true' }}
run: |
npm run build
npm run bundle
- name: 'Set Python package version (local only)'
env:
PACKAGE_VERSION: '${{ steps.version.outputs.PACKAGE_VERSION }}'
run: |
python - <<'PY'
from pathlib import Path
import os
import re
pyproject = Path('packages/sdk-python/pyproject.toml')
content = pyproject.read_text()
updated, count = re.subn(
r'^version = "[^"]+"$',
f'version = "{os.environ["PACKAGE_VERSION"]}"',
content,
flags=re.MULTILINE,
)
if count != 1:
raise SystemExit(
f'pyproject.toml version rewrite matched {count} lines, expected 1'
)
pyproject.write_text(updated)
PY
- name: 'Run Python quality gates'
if: |-
${{ github.event.inputs.force_skip_tests != 'true' }}
run: |
python -m ruff check --config packages/sdk-python/pyproject.toml packages/sdk-python
python -m ruff format --check --config packages/sdk-python/pyproject.toml packages/sdk-python
python -m mypy --config-file packages/sdk-python/pyproject.toml packages/sdk-python/src
python -m pytest -c packages/sdk-python/pyproject.toml packages/sdk-python/tests -q
- name: 'Run real smoke test'
if: |-
${{ github.event.inputs.force_skip_tests != 'true' }}
env:
OPENAI_API_KEY: '${{ secrets.OPENAI_API_KEY }}'
OPENAI_BASE_URL: '${{ secrets.OPENAI_BASE_URL }}'
OPENAI_MODEL: '${{ secrets.OPENAI_MODEL }}'
run: |
python packages/sdk-python/scripts/smoke_real.py --qwen "${GITHUB_WORKSPACE}/dist/cli.js" --cwd "${GITHUB_WORKSPACE}" --json-only
- name: 'Configure Git User'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: 'Create and switch to a release branch'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' }}
id: 'release_branch'
env:
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
RESUME_EXISTING_RELEASE: '${{ steps.version.outputs.RESUME_EXISTING_RELEASE }}'
run: |
set -euo pipefail
BRANCH_NAME="release/sdk-python/${RELEASE_TAG}"
VERSIONED_PYPROJECT="$(mktemp)"
cp packages/sdk-python/pyproject.toml "${VERSIONED_PYPROJECT}"
git restore --staged --worktree packages/sdk-python/pyproject.toml
if git ls-remote --exit-code --heads origin "${BRANCH_NAME}" >/dev/null 2>&1; then
git fetch origin "${BRANCH_NAME}"
if git show-ref --verify --quiet "refs/heads/${BRANCH_NAME}"; then
git switch "${BRANCH_NAME}"
else
git switch -c "${BRANCH_NAME}" --track "origin/${BRANCH_NAME}"
fi
git reset --hard "origin/${BRANCH_NAME}"
echo "REMOTE_BRANCH_EXISTS=true" >> "${GITHUB_OUTPUT}"
else
if [[ "${RESUME_EXISTING_RELEASE}" == "true" ]]; then
echo "Published version ${RELEASE_TAG} exists without a persisted release branch ${BRANCH_NAME}. To resolve: (1) re-trigger with a different version, or (2) manually create branch ${BRANCH_NAME} from the original release commit." >&2
exit 1
fi
git switch -c "${BRANCH_NAME}"
echo "REMOTE_BRANCH_EXISTS=false" >> "${GITHUB_OUTPUT}"
fi
cp "${VERSIONED_PYPROJECT}" packages/sdk-python/pyproject.toml
rm -f "${VERSIONED_PYPROJECT}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> "${GITHUB_OUTPUT}"
- name: 'Commit and push package version'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' }}
id: 'persist_source'
env:
BRANCH_NAME: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
CHECKED_OUT_SHA: '${{ steps.checkout_sha.outputs.sha }}'
REMOTE_BRANCH_EXISTS: '${{ steps.release_branch.outputs.REMOTE_BRANCH_EXISTS }}'
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
run: |
set -euo pipefail
git add packages/sdk-python/pyproject.toml
if git diff --staged --quiet; then
echo "No version changes to commit"
if [[ "${REMOTE_BRANCH_EXISTS}" == "true" ]]; then
echo "HAS_PERSISTED_SOURCE=true" >> "${GITHUB_OUTPUT}"
echo "RELEASE_TARGET_SHA=$(git rev-parse HEAD)" >> "${GITHUB_OUTPUT}"
else
echo "HAS_PERSISTED_SOURCE=false" >> "${GITHUB_OUTPUT}"
echo "RELEASE_TARGET_SHA=${CHECKED_OUT_SHA}" >> "${GITHUB_OUTPUT}"
fi
else
git commit -m "chore(release): sdk-python ${RELEASE_TAG}"
echo "HAS_PERSISTED_SOURCE=true" >> "${GITHUB_OUTPUT}"
echo "RELEASE_TARGET_SHA=$(git rev-parse HEAD)" >> "${GITHUB_OUTPUT}"
if [[ "${REMOTE_BRANCH_EXISTS}" == "true" ]]; then
git push origin "${BRANCH_NAME}"
else
git push --set-upstream origin "${BRANCH_NAME}"
fi
fi
- name: 'Build Python package'
working-directory: 'packages/sdk-python'
run: |
rm -rf dist
python -m build
- name: 'Publish qwen-code-sdk to PyPI'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' }}
uses: 'pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b' # ratchet:pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: 'packages/sdk-python/dist'
# skip-existing handles resumed releases where some artifacts were already uploaded
skip-existing: '${{ steps.version.outputs.RESUME_EXISTING_RELEASE }}'
- name: 'Show publish artifacts for dry-run'
if: |-
${{ steps.vars.outputs.is_dry_run == 'true' }}
run: |
ls -la packages/sdk-python/dist
- name: 'Create GitHub release and tag'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
PACKAGE_VERSION: '${{ steps.version.outputs.PACKAGE_VERSION }}'
PREVIOUS_RELEASE_TAG: '${{ steps.version.outputs.PREVIOUS_RELEASE_TAG }}'
RELEASE_TARGET_SHA: '${{ steps.persist_source.outputs.RELEASE_TARGET_SHA }}'
IS_NIGHTLY: '${{ steps.vars.outputs.is_nightly }}'
IS_PREVIEW: '${{ steps.vars.outputs.is_preview }}'
run: |
set -euo pipefail
TAG_NAME="sdk-python-${RELEASE_TAG}"
if gh release view "${TAG_NAME}" --json tagName >/dev/null 2>&1; then
echo "::warning::GitHub release ${TAG_NAME} already exists; skipping create."
exit 0
fi
if git rev-parse "${TAG_NAME}" >/dev/null 2>&1; then
EXISTING_TAG_SHA="$(git rev-list -n 1 "${TAG_NAME}")"
if [[ "${EXISTING_TAG_SHA}" != "${RELEASE_TARGET_SHA}" ]]; then
echo "Existing tag ${TAG_NAME} points to ${EXISTING_TAG_SHA}, expected ${RELEASE_TARGET_SHA}." >&2
exit 1
fi
fi
NOTES_FILE=$(mktemp)
{
echo "## Published Package"
echo ""
echo "- PyPI package: \`qwen-code-sdk\`"
echo "- Package version: \`${PACKAGE_VERSION}\`"
echo ""
echo "---"
echo ""
} > "${NOTES_FILE}"
GH_RELEASE_ARGS=()
if [[ -n "${PREVIOUS_RELEASE_TAG}" ]]; then
PREVIOUS_TAG_NAME="sdk-python-${PREVIOUS_RELEASE_TAG}"
# Verify the previous tag exists in Git before using --notes-start-tag.
# If a prior release published to PyPI but failed to create a GitHub
# release/tag, the tag won't exist — fall back to static notes to
# avoid failing gh release create after PyPI publish.
if git rev-parse "${PREVIOUS_TAG_NAME}" >/dev/null 2>&1; then
GH_RELEASE_ARGS+=(--generate-notes --notes-start-tag "${PREVIOUS_TAG_NAME}")
else
echo "::warning::Previous tag ${PREVIOUS_TAG_NAME} not found; skipping --generate-notes."
echo "See commit history for changes." >> "${NOTES_FILE}"
fi
else
# PREVIOUS_RELEASE_TAG is empty for preview/nightly (not computed)
# and for the very first stable release (no prior stable on PyPI).
# Skip --generate-notes to avoid including non-SDK commits.
echo "See commit history for changes." >> "${NOTES_FILE}"
fi
if [[ "${IS_NIGHTLY}" == "true" || "${IS_PREVIEW}" == "true" ]]; then
GH_RELEASE_ARGS+=(--prerelease)
fi
gh release create "${TAG_NAME}" \
--target "${RELEASE_TARGET_SHA}" \
--title "SDK Python Release ${RELEASE_TAG}" \
--notes-file "${NOTES_FILE}" \
"${GH_RELEASE_ARGS[@]}"
rm -f "${NOTES_FILE}"
- name: 'Delete prerelease release branch'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' && (steps.vars.outputs.is_nightly == 'true' || steps.vars.outputs.is_preview == 'true') }}
env:
BRANCH_NAME: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
run: |
set -euo pipefail
if git ls-remote --exit-code --heads origin "${BRANCH_NAME}" >/dev/null 2>&1; then
if ! git push origin --delete "${BRANCH_NAME}"; then
echo "::warning::Failed to delete prerelease release branch ${BRANCH_NAME}; release already exists, so remove the branch manually if it still exists."
fi
else
echo "No prerelease release branch to delete for ${BRANCH_NAME}."
fi
- name: 'Create PR to merge release branch into main'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' && steps.vars.outputs.is_nightly == 'false' && steps.vars.outputs.is_preview == 'false' && steps.persist_source.outputs.HAS_PERSISTED_SOURCE == 'true' }}
id: 'pr'
env:
GITHUB_TOKEN: '${{ secrets.CI_BOT_PAT }}'
RELEASE_BRANCH: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
run: |
set -euo pipefail
pr_url="$(gh pr list --head "${RELEASE_BRANCH}" --base main --json url --jq '.[0].url')"
if [[ -z "${pr_url}" ]]; then
# `gh pr create` runs right after the branch push and release
# creation; wait so GitHub doesn't reject the burst with its
# "was submitted too quickly" secondary rate limit.
sleep 30
pr_url="$(gh pr create \
--base main \
--head "${RELEASE_BRANCH}" \
--label 'skip-changelog' \
--title "chore(release): sdk-python ${RELEASE_TAG}" \
--body "Automated release PR for sdk-python ${RELEASE_TAG}.")"
fi
echo "PR_URL=${pr_url}" >> "${GITHUB_OUTPUT}"
- name: 'Enable auto-merge for release PR'
if: |-
${{ steps.vars.outputs.is_dry_run == 'false' && steps.vars.outputs.is_nightly == 'false' && steps.vars.outputs.is_preview == 'false' && steps.persist_source.outputs.HAS_PERSISTED_SOURCE == 'true' }}
env:
GITHUB_TOKEN: '${{ secrets.CI_BOT_PAT }}'
PR_URL: '${{ steps.pr.outputs.PR_URL }}'
run: |
set -euo pipefail
# No --delete-branch: main has a merge queue and gh rejects the flag
# when one is enabled (the queue owns the merge; head-branch deletion
# follows the repo's "Automatically delete head branches" setting).
gh pr merge "${PR_URL}" --squash --auto
- name: 'Create issue on failure'
if: |-
${{ failure() && github.event.inputs.dry_run != 'true' }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
RELEASE_TAG: "${{ steps.version.outputs.RELEASE_TAG || 'N/A' }}"
PACKAGE_VERSION: "${{ steps.version.outputs.PACKAGE_VERSION || 'N/A' }}"
PUBLISH_CHANNEL: "${{ steps.version.outputs.PUBLISH_CHANNEL || 'N/A' }}"
RESUME_EXISTING_RELEASE: "${{ steps.version.outputs.RESUME_EXISTING_RELEASE || 'N/A' }}"
BRANCH_NAME: "${{ steps.release_branch.outputs.BRANCH_NAME || 'N/A' }}"
HAS_PERSISTED_SOURCE: "${{ steps.persist_source.outputs.HAS_PERSISTED_SOURCE || 'N/A' }}"
RELEASE_TARGET_SHA: "${{ steps.persist_source.outputs.RELEASE_TARGET_SHA || 'N/A' }}"
PR_URL: "${{ steps.pr.outputs.PR_URL || 'N/A' }}"
DETAILS_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
run: |
set -euo pipefail
BODY=$(cat <<BODY
The Python SDK release workflow failed.
| Field | Value |
|-------|-------|
| Release Tag | \`${RELEASE_TAG}\` |
| Package Version | \`${PACKAGE_VERSION}\` |
| Publish Channel | \`${PUBLISH_CHANNEL}\` |
| Resume Existing | \`${RESUME_EXISTING_RELEASE}\` |
| Release Branch | \`${BRANCH_NAME}\` |
| Persisted Source | \`${HAS_PERSISTED_SOURCE}\` |
| Target SHA | \`${RELEASE_TARGET_SHA}\` |
| PR URL | ${PR_URL} |
See the full run for details: ${DETAILS_URL}
BODY
)
gh issue create \
--repo "${GITHUB_REPOSITORY}" \
--title "Python SDK release failed for ${RELEASE_TAG} on $(date +'%Y-%m-%d')" \
--body "${BODY}"