Skip to content

Commit 5e5c973

Browse files
authored
Merge pull request #17 from Lithe-IDEA/codex/plugin-delta-updates
feat(release): 为 Python Support 生成增量包
2 parents bd1ac13 + 7c5c79a commit 5e5c973

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
needs: [check, package]
6363
if: needs.check.outputs.exists == 'false'
6464
runs-on: ubuntu-latest
65-
timeout-minutes: 5
65+
timeout-minutes: 10
6666
permissions:
6767
contents: write
6868
steps:
@@ -79,6 +79,9 @@ jobs:
7979
env:
8080
LITHE_EXPECT_ALL_ARCHIVES: "1"
8181
run: node --test --test-timeout=60000 scripts/package/*.test.mjs
82+
- name: Set up optional delta generation
83+
continue-on-error: true
84+
run: command -v zstd || sudo apt-get install -y zstd
8285
- name: Publish GitHub Release
8386
env:
8487
GH_TOKEN: ${{ github.token }}
@@ -93,6 +96,19 @@ jobs:
9396
break
9497
fi
9598
done
99+
if (( ${#release_flags[@]} == 0 )); then
100+
if curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' \
101+
--max-time 20 --max-filesize 5242880 \
102+
-o "$RUNNER_TEMP/store-index.json" \
103+
https://raw.githubusercontent.com/Lithe-IDEA/Lithe-store/HEAD/lithe-plugin-index.json &&
104+
bash scripts/package/release-deltas.sh "$RUNNER_TEMP/store-index.json" dist "${GITHUB_REF_NAME#v}"; then
105+
echo "Checked for optional plugin deltas."
106+
else
107+
echo "::warning::Could not prepare optional patches; publishing full ZIPs."
108+
fi
109+
fi
110+
shopt -s nullglob
111+
patches=(dist/*.zip.zst)
96112
notes="docs/releases/$GITHUB_REF_NAME.md"
97113
test -s "$notes"
98114
{
@@ -122,4 +138,4 @@ jobs:
122138
echo "::error::Release tag $GITHUB_REF_NAME no longer points to the packaged commit. Use the run for the current tag."
123139
exit 1
124140
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[@]}"
141+
gh release create "$GITHUB_REF_NAME" dist/*.zip "${patches[@]}" --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ PYTEST_PYTHON=/path/to/python3.12 node scripts/e2e-host.mjs --run '^TestPythonSu
177177
1. 修改 `io.github.lithe-idea.python-support/plugin.json` 的 `version`:修复升修订号,加功能升次版本号,特别大的革新才升主版本号。
178178
依赖还没发布的宿主能力时照样升次版本号,作为预发布版本发布。写好 `docs/releases/v<版本>.md`,合入 `main`。
179179
2. 推送同名标签,例如 `git tag v1.2.0 && git push origin v1.2.0`。
180-
3. `Release` 工作流核对标签与版本,打六个平台的包并发布 Release,说明里附 SHA-256 和 `docs/releases/v<版本>.md`。
180+
3. `Release` 工作流核对标签与版本,打六个平台的包并发布 Release,说明里附 SHA-256 和 `docs/releases/v<版本>.md`。 正式发布还会对照 Lithe Store 的上一个同平台版本生成可选增量包。校验成功、且补丁最多为完整包的 75% 时才随 Release 发布。
181181
`release.yml` 的 `PRERELEASE_TAGS` 里的版本标为预发布,目前是 `v0.1.0`、`v0.1.1` 和 `v1.2.0`。
182182
4. Lithe Store 的自动追踪会为稳定版本开合并请求,合并后用户即可更新。
183183

‎scripts/package/release-deltas.sh‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# Packages optional patches from the newest Store-listed release per platform.
3+
set -euo pipefail
4+
5+
if [[ $# -ne 3 ]]; then
6+
printf 'usage: %s STORE_INDEX ZIP_DIRECTORY TARGET_VERSION\n' "$0" >&2
7+
exit 2
8+
fi
9+
index=$1
10+
dist=$2
11+
version=$3
12+
plugin_id=io.github.lithe-idea.python-support
13+
max_zip=67108864
14+
version_pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
15+
[[ "$version" =~ $version_pattern ]]
16+
17+
scratch=$(mktemp -d)
18+
trap 'python3 -c "import shutil, sys; shutil.rmtree(sys.argv[1])" "$scratch"' EXIT
19+
20+
shopt -s nullglob
21+
for target in "$dist"/python-support-"$version"-*.zip; do
22+
platform=${target##*/python-support-"$version"-}
23+
platform=${platform%.zip}
24+
[[ "$platform" =~ ^(darwin|linux|windows)-(arm64|x64)$ ]] || continue
25+
size=$(wc -c < "$target")
26+
(( size > 0 && size <= max_zip )) || continue
27+
28+
# The index is already ordered newest first. Compare the numeric parts to
29+
# ignore a concurrent newer release and release reruns.
30+
base=$(jq -r --arg id "$plugin_id" --arg platform "$platform" --arg target "$version" '
31+
def semver: split(".") | map(tonumber);
32+
first(
33+
.plugins[] | select(.id == $id) | .versions[]
34+
| select((.version | semver) < ($target | semver))
35+
| .version as $version
36+
| .downloads[] | select(.platforms | index($platform))
37+
| [$version, .downloadURL, .sha256] | @tsv
38+
) // empty
39+
' "$index")
40+
[[ -n "$base" ]] || continue
41+
IFS=$'\t' read -r previous url digest <<< "$base"
42+
if [[ ! "$previous" =~ $version_pattern ||
43+
! "$url" =~ ^https://github\.com/Lithe-IDEA/lithe-plugin-python/releases/download/[^/]+/[^/]+\.zip$ ||
44+
! "$digest" =~ ^[a-f0-9]{64}$ ]]; then
45+
printf 'Skipping delta for %s: invalid Store archive identity.\n' "$platform" >&2
46+
continue
47+
fi
48+
if ! curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' \
49+
--max-time 25 --max-filesize "$max_zip" -o "$scratch/base.zip" "$url" ||
50+
! actual=$(sha256sum "$scratch/base.zip") || [[ "${actual%% *}" != "$digest" ]]; then
51+
printf 'Skipping delta for %s: Store base could not be verified.\n' "$platform" >&2
52+
continue
53+
fi
54+
55+
patch="$scratch/patch.zst"
56+
if ! zstd -f -q -M128MB --patch-from="$scratch/base.zip" -o "$patch" -- "$target"; then
57+
printf 'Skipping delta for %s: compression failed.\n' "$platform" >&2
58+
continue
59+
fi
60+
(( $(wc -c < "$patch") <= size * 3 / 4 )) || continue
61+
if ! zstd -q -dc -M128MB --patch-from="$scratch/base.zip" -- "$patch" | cmp -s "$target" -; then
62+
printf 'Skipping delta for %s: reconstruction did not match target.\n' "$platform" >&2
63+
continue
64+
fi
65+
mv "$patch" "${target%.zip}.from-$previous.zip.zst"
66+
done

0 commit comments

Comments
 (0)