Skip to content

Commit 50daeb2

Browse files
authored
Merge pull request #7 from Lithe-IDEA/codex/2122-python-v1-release
release(python): 准备 v1.0.0 正式发布
2 parents 8b8d27a + 28d4e16 commit 50daeb2

5 files changed

Lines changed: 177 additions & 13 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- uses: actions/setup-node@v4
2222
with:
2323
node-version: 22
24+
- name: Verify release tag checks
25+
run: node --test --test-timeout=30000 scripts/ci/release/publish.test.mjs
2426
- uses: actions/download-artifact@v4
2527
with:
2628
pattern: python-support-archive-*

‎.github/workflows/release.yml‎

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
check:
1414
runs-on: ubuntu-latest
1515
timeout-minutes: 5
16+
permissions:
17+
# GitHub only exposes draft releases to callers with push access.
18+
contents: write
1619
outputs:
1720
exists: ${{ steps.release.outputs.exists }}
1821
steps:
@@ -21,11 +24,32 @@ jobs:
2124
env:
2225
GH_TOKEN: ${{ github.token }}
2326
run: |
24-
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
25-
echo "exists=true" >> "$GITHUB_OUTPUT"
26-
else
27-
echo "exists=false" >> "$GITHUB_OUTPUT"
28-
fi
27+
state=$(gh api graphql \
28+
-f query='query($owner: String!, $repo: String!, $tag: String!) {
29+
repository(owner: $owner, name: $repo) {
30+
release(tagName: $tag) { isDraft }
31+
}
32+
}' \
33+
-f owner="$GITHUB_REPOSITORY_OWNER" -f repo="${GITHUB_REPOSITORY#*/}" -f tag="$GITHUB_REF_NAME" \
34+
--jq '.data.repository |
35+
if . == null then "unavailable"
36+
elif .release == null then "missing"
37+
elif .release.isDraft == true then "draft"
38+
elif .release.isDraft == false then "published"
39+
else "unavailable"
40+
end')
41+
case "$state" in
42+
missing) echo "exists=false" >> "$GITHUB_OUTPUT" ;;
43+
published) echo "exists=true" >> "$GITHUB_OUTPUT" ;;
44+
draft)
45+
echo "::error::A draft release exists for $GITHUB_REF_NAME. Review it and resolve the draft before rerunning."
46+
exit 1
47+
;;
48+
*)
49+
echo "::error::Could not determine the release state for $GITHUB_REF_NAME."
50+
exit 1
51+
;;
52+
esac
2953
3054
package:
3155
needs: check
@@ -58,8 +82,7 @@ jobs:
5882
- name: Publish GitHub Release
5983
env:
6084
GH_TOKEN: ${{ github.token }}
61-
# v1.0.0 requires a host that advertises toolchainProviders 0 and buildSystems 1.
62-
PRERELEASE_TAGS: v0.1.0 v0.1.1 v1.0.0
85+
PRERELEASE_TAGS: v0.1.0 v0.1.1
6386
run: |
6487
release_flags=()
6588
installation='Lithe Store 会在收录后提供此版本。打开 设置 → 插件 → 插件市场,搜索 Python Support。'
@@ -83,4 +106,20 @@ jobs:
83106
(cd dist && sha256sum ./*.zip)
84107
echo '```'
85108
} > "$RUNNER_TEMP/notes.md"
86-
gh release create "$GITHUB_REF_NAME" dist/*.zip --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"
109+
110+
# The artifacts came from the event checkout even if the remote tag has since moved.
111+
packaged_commit=$(git rev-parse HEAD)
112+
if ! remote_tag=$(git ls-remote --exit-code origin "$GITHUB_REF" "$GITHUB_REF^{}"); then
113+
echo "::error::Could not resolve release tag $GITHUB_REF_NAME on origin. Check the tag before retrying."
114+
exit 1
115+
fi
116+
remote_commit=$(awk -v ref="$GITHUB_REF" '
117+
$2 == ref { object = $1 }
118+
$2 == ref "^{}" { peeled = $1 }
119+
END { print (peeled != "" ? peeled : object) }
120+
' <<< "$remote_tag")
121+
if [[ "$remote_commit" != "$packaged_commit" ]]; then
122+
echo "::error::Release tag $GITHUB_REF_NAME no longer points to the packaged commit. Use the run for the current tag."
123+
exit 1
124+
fi
125+
gh release create "$GITHUB_REF_NAME" dist/*.zip --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ Python language support plugin for Lithe (`schemaVersion: 0`, `pluginAPIVersion:
44

55
遵循 Lithe 插件契约 v1(`schemaVersion: 0`),为 Lithe 桌面端(macOS / Windows / Linux)提供开箱即用的 Python 语言支持、宿主工具链驱动的 `Pyrefly` 解释器注入、`.venv` / `.conda` / `conda` / `uv` / `pyenv` 多来源环境发现、动态 `pytest` 测试树收集与执行、`uv` / `conda` / `Ruff` 构建任务、源码级断点调试及新建项目向导。跨平台实现与验证记录详见 [docs/feature-matrix.md](docs/feature-matrix.md)。
66

7+
## 兼容性(Compatibility)
8+
9+
Python Support v1.0.0 要求 Lithe 0.8.9 或更新版本。Lithe 0.8.9 支持安装插件并处理 `.py`、`.pyi` 和 `.pyw` 文件。Lithe 0.8.10 起还能按 shebang 识别无后缀 Python 脚本。
10+
11+
Python Support v1.0.0 requires Lithe 0.8.9 or later. Lithe 0.8.9 can install the plugin and work with `.py`, `.pyi`, and `.pyw` files. Lithe 0.8.10 and later also recognize extensionless Python scripts by their shebang.
12+
713
---
814

915
## 核心能力(Capabilities)
1016

1117
1. **语言与编辑器基础(`languages: python`)**
1218
- 识别 `.py`、`.pyi`、`.pyw`,配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。
13-
- Lithe 0.8.9 可以安装此插件。支持 TextMate 首行匹配的桌面版本还会按 shebang 识别无后缀脚本,提供 Python 高亮和 Pyrefly 诊断。
19+
- 按 shebang 识别的无后缀脚本同样支持 Python 高亮、注释和 Pyrefly 诊断。
1420
2. **后端解析的语言服务器启动与解释器自动注入(`backend` + `languageServers: python` / Pyrefly `1.4.1`)**
1521
- 插件包内的 Rust 后端直接启动 Pyrefly,无需先找到 Python。宿主会传入可用于自动启动的解释器路径,缺失时由 Pyrefly 按自身规则发现项目环境。构建、测试与调试仍用宿主选择的 Python。
1622
- 构建期按平台固定版本与 SHA-256 打包 `pyrefly 1.4.1`(Unix:`bin/pyrefly`,Windows:`bin/pyrefly.exe`),每个包也包含同一目标架构的 `bin/lithe-python-backend`(Windows 为 `.exe`)。

‎docs/releases/v1.0.0.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
## 中文
22

3-
- 支持 TextMate 首行匹配的 Lithe 可按 shebang 识别无后缀 Python 脚本,提供高亮、注释和 Pyrefly 诊断。
3+
- 在 Lithe 0.8.10 及以上版本中,打开首行含 Python shebang 的无后缀脚本即可使用高亮、注释和 Pyrefly 诊断。
44
- Toolchains 可从 Conda 环境登记表、uv 自定义安装目录和其他受支持的环境位置发现 Python。项目的 `.python-version` 和 `requires-python` 参与解释器选择。
55
- Pyrefly 与宿主选定的解释器保持一致。插件包内的后端可以在尚未安装 Python 时启动 Pyrefly。
66
- Build 面板可用 pytest 收集测试,按已发现的套件和用例精确运行。运行 pytest 和 debugpy 仍需要可用的项目解释器。
77

88
### 升级与兼容性
99

10-
Lithe 0.8.9 支持安装此插件并使用普通 Python 文件功能。无后缀脚本的自动识别需要支持 TextMate 首行匹配的桌面版本。请选择对应操作系统和架构的 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。
10+
Python Support v1.0.0 要求 Lithe 0.8.9 或更新版本。Lithe 0.8.9 支持安装此插件并处理 `.py`、`.pyi` 和 `.pyw` 文件。从 0.8.10 开始,Lithe 还能按 shebang 自动识别无后缀脚本。
11+
12+
使用兼容的旧版 Lithe 时,仍可手动安装 [Python Support v0.1.1 预发布版](https://github.com/Lithe-IDEA/lithe-plugin-python/releases/tag/v0.1.1)。手动安装时请选择对应操作系统和架构的 ZIP。
1113

1214
---
1315

1416
## English
1517

16-
- On Lithe versions that support TextMate first-line matching, open extensionless Python scripts with a shebang to get highlighting, comment commands, and Pyrefly diagnostics.
18+
- With Lithe 0.8.10 or later, open extensionless scripts with a Python shebang to get highlighting, comment commands, and Pyrefly diagnostics.
1719
- Toolchains can find Python from the Conda environment registry, a custom uv installation directory, and other supported environment locations. The project's `.python-version` and `requires-python` help select an interpreter.
1820
- Pyrefly uses the interpreter selected in Lithe. The bundled backend can start Pyrefly before Python is installed.
1921
- The Build panel can collect tests with pytest and run an exact discovered suite or case. Running pytest and debugpy still requires an available project interpreter.
2022

2123
### Upgrade and compatibility
2224

23-
Lithe 0.8.9 can install this plugin and use its standard Python support. Automatic recognition of extensionless scripts requires a desktop version with TextMate first-line matching. Choose the ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe.
25+
Python Support v1.0.0 requires Lithe 0.8.9 or later. Lithe 0.8.9 can install the plugin and work with `.py`, `.pyi`, and `.pyw` files. Starting with 0.8.10, Lithe can also recognize extensionless scripts by their shebang.
26+
27+
On compatible older versions of Lithe, you can still install the [Python Support v0.1.1 prerelease](https://github.com/Lithe-IDEA/lithe-plugin-python/releases/tag/v0.1.1) manually. For manual installation, choose the ZIP for your operating system and architecture.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync, spawnSync } from "node:child_process";
3+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { join } from "node:path";
6+
import test from "node:test";
7+
8+
const workflow = readFileSync(new URL("../../../.github/workflows/release.yml", import.meta.url), "utf8");
9+
const publishStep = workflow.match(/^ {6}- name: Publish GitHub Release\n(?: {8}[^\n]*\n)*? {8}run: \|\n((?:(?: {10}[^\n]*)?\n)+)/m);
10+
assert.ok(publishStep, "Could not find the release workflow's publish step");
11+
const publishScript = publishStep[1].replace(/^ {10}/gm, "");
12+
const recordReleaseArgs = 'gh() { printf "%s\\n" "$@" > "$RELEASE_ARGS"; }\n';
13+
14+
const gitEnv = {
15+
PATH: process.env.PATH,
16+
GIT_CONFIG_GLOBAL: "/dev/null",
17+
GIT_CONFIG_NOSYSTEM: "1",
18+
GIT_TERMINAL_PROMPT: "0",
19+
GIT_AUTHOR_NAME: "Release Test",
20+
GIT_AUTHOR_EMAIL: "release@example.invalid",
21+
GIT_COMMITTER_NAME: "Release Test",
22+
GIT_COMMITTER_EMAIL: "release@example.invalid",
23+
};
24+
25+
function releaseFixture(t, tag = "v1.0.0", tagOptions = []) {
26+
const directory = mkdtempSync(join(tmpdir(), "python-release-"));
27+
t.after(() => rmSync(directory, { recursive: true, force: true }));
28+
const checkout = join(directory, "checkout");
29+
const remote = join(directory, "remote.git");
30+
const ref = `refs/tags/${tag}`;
31+
const cliLog = join(directory, "release-args");
32+
33+
function git(cwd, ...args) {
34+
return execFileSync("git", args, { cwd, env: gitEnv, encoding: "utf8", timeout: 5000 }).trim();
35+
}
36+
37+
git(directory, "init", "-q", checkout);
38+
git(directory, "init", "-q", "--bare", remote);
39+
git(checkout, "remote", "add", "origin", remote);
40+
git(checkout, "commit", "-qm", "packaged commit", "--allow-empty");
41+
const packagedCommit = git(checkout, "rev-parse", "HEAD");
42+
git(checkout, "tag", ...tagOptions, tag);
43+
git(checkout, "push", "-q", "origin", ref);
44+
45+
mkdirSync(join(checkout, "docs", "releases"), { recursive: true });
46+
mkdirSync(join(checkout, "dist"));
47+
writeFileSync(join(checkout, "docs", "releases", `${tag}.md`), "Release notes\n");
48+
writeFileSync(join(checkout, "dist", "python-support.zip"), "Test archive contents\n");
49+
50+
return {
51+
cliLog,
52+
retag() {
53+
git(checkout, "commit", "-qm", "replacement commit", "--allow-empty");
54+
git(checkout, "push", "-q", "origin", `+HEAD:${ref}`);
55+
git(checkout, "checkout", "-q", "--detach", packagedCommit);
56+
},
57+
removeTag() {
58+
git(checkout, "push", "-q", "origin", `:${ref}`);
59+
},
60+
publish() {
61+
const result = spawnSync("bash", ["--noprofile", "--norc", "-e", "-c", recordReleaseArgs + publishScript], {
62+
cwd: checkout,
63+
encoding: "utf8",
64+
timeout: 5000,
65+
env: {
66+
...gitEnv,
67+
GITHUB_REF: ref,
68+
GITHUB_REF_NAME: tag,
69+
RUNNER_TEMP: directory,
70+
PRERELEASE_TAGS: "v0.1.0 v0.1.1",
71+
RELEASE_ARGS: cliLog,
72+
},
73+
});
74+
assert.ifError(result.error);
75+
return result;
76+
},
77+
};
78+
}
79+
80+
test("publish uses the unchanged lightweight release tag", (t) => {
81+
const fixture = releaseFixture(t);
82+
const result = fixture.publish();
83+
assert.equal(result.status, 0, result.stdout + result.stderr);
84+
const args = readFileSync(fixture.cliLog, "utf8").trimEnd().split("\n");
85+
assert.deepEqual(args.slice(0, 3), ["release", "create", "v1.0.0"]);
86+
assert.ok(args.includes("--verify-tag"));
87+
assert.ok(!args.includes("--prerelease"));
88+
});
89+
90+
test("publish resolves an annotated prerelease tag to its commit", (t) => {
91+
const fixture = releaseFixture(t, "v0.1.1", ["-a", "-m", "Prerelease"]);
92+
const result = fixture.publish();
93+
assert.equal(result.status, 0, result.stdout + result.stderr);
94+
assert.match(readFileSync(fixture.cliLog, "utf8"), /^--prerelease$/m);
95+
});
96+
97+
test("publish stops when the remote tag is moved after packaging", (t) => {
98+
const fixture = releaseFixture(t);
99+
fixture.retag();
100+
const result = fixture.publish();
101+
assert.equal(result.status, 1, result.stdout + result.stderr);
102+
assert.match(result.stdout, /no longer points to the packaged commit/);
103+
assert.ok(!existsSync(fixture.cliLog), "Should stop before invoking gh release create");
104+
});
105+
106+
test("publish stops when the remote tag is deleted after packaging", (t) => {
107+
const fixture = releaseFixture(t);
108+
fixture.removeTag();
109+
const result = fixture.publish();
110+
assert.equal(result.status, 1, result.stdout + result.stderr);
111+
assert.match(result.stdout, /Could not resolve release tag/);
112+
assert.ok(!existsSync(fixture.cliLog), "Should stop before invoking gh release create");
113+
});

0 commit comments

Comments
 (0)