everkm-publish 0.17.1 → 0.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
publish-npm-package.py
|
|
5
5
|
|
|
6
6
|
从 everkm/publish GitHub Release 拉取全部资产,镜像至 R2 / 七牛(pkgs/{ver}/),
|
|
7
|
-
生成 pkgs/latest.json(含上游 Release notes)。
|
|
7
|
+
生成 pkgs/latest.json 与 pkgs/{ver}/meta.json(含上游 Release notes)。
|
|
8
8
|
|
|
9
9
|
环境变量:
|
|
10
10
|
- GH_TOKEN / GITHUB_TOKEN — 读 everkm/publish Release
|
|
@@ -235,20 +235,38 @@ def npm_version_exists(version: str) -> bool:
|
|
|
235
235
|
return False
|
|
236
236
|
|
|
237
237
|
|
|
238
|
+
def latest_json_version(s3_client: Any) -> str | None:
|
|
239
|
+
latest_key = "pkgs/latest.json"
|
|
240
|
+
try:
|
|
241
|
+
resp = s3_client.get_object(Bucket=R2_BUCKET, Key=latest_key)
|
|
242
|
+
data = json.loads(resp["Body"].read())
|
|
243
|
+
except ClientError as exc:
|
|
244
|
+
code = exc.response.get("Error", {}).get("Code")
|
|
245
|
+
if code in ("404", "NoSuchKey", "NotFound"):
|
|
246
|
+
return None
|
|
247
|
+
raise
|
|
248
|
+
except (json.JSONDecodeError, TypeError):
|
|
249
|
+
return None
|
|
250
|
+
version = data.get("version")
|
|
251
|
+
return version if isinstance(version, str) and version else None
|
|
252
|
+
|
|
253
|
+
|
|
238
254
|
def cdn_assets_complete(s3_client: Any, version: str, asset_names: list[str]) -> bool:
|
|
239
255
|
if not asset_names:
|
|
240
256
|
return False
|
|
241
257
|
for name in asset_names:
|
|
242
258
|
if not object_exists(s3_client, pkg_key(version, name)):
|
|
243
259
|
return False
|
|
244
|
-
|
|
245
|
-
|
|
260
|
+
if not object_exists(s3_client, pkg_key(version, "meta.json")):
|
|
261
|
+
return False
|
|
262
|
+
if latest_json_version(s3_client) != version:
|
|
246
263
|
return False
|
|
247
264
|
return True
|
|
248
265
|
|
|
249
266
|
|
|
250
267
|
def cdn_refresh_urls(version: str, asset_names: list[str]) -> None:
|
|
251
268
|
urls = [f"{CDN_CN}/pkgs/{version}/{name}" for name in asset_names]
|
|
269
|
+
urls.append(f"{CDN_CN}/pkgs/{version}/meta.json")
|
|
252
270
|
urls.append(f"{CDN_CN}/pkgs/latest.json")
|
|
253
271
|
ak = os.environ.get("QINIU_ACCESS_KEY")
|
|
254
272
|
sk = os.environ.get("QINIU_SECRET_KEY")
|
|
@@ -324,16 +342,28 @@ def publish(
|
|
|
324
342
|
skip_if_exists=not force_cdn,
|
|
325
343
|
)
|
|
326
344
|
|
|
327
|
-
|
|
345
|
+
meta = build_latest_json(version, tag, notes, asset_names)
|
|
346
|
+
|
|
347
|
+
meta_path = work_dir / "meta.json"
|
|
348
|
+
with meta_path.open("w", encoding="utf-8") as f:
|
|
349
|
+
json.dump(meta, f, indent=2, ensure_ascii=False)
|
|
350
|
+
f.write("\n")
|
|
351
|
+
upload_file_both(
|
|
352
|
+
s3_client,
|
|
353
|
+
meta_path,
|
|
354
|
+
pkg_key(version, "meta.json"),
|
|
355
|
+
skip_if_exists=not force_cdn,
|
|
356
|
+
)
|
|
357
|
+
|
|
328
358
|
latest_path = work_dir / "latest.json"
|
|
329
359
|
with latest_path.open("w", encoding="utf-8") as f:
|
|
330
|
-
json.dump(
|
|
360
|
+
json.dump(meta, f, indent=2, ensure_ascii=False)
|
|
331
361
|
f.write("\n")
|
|
332
362
|
upload_file_both(
|
|
333
363
|
s3_client,
|
|
334
364
|
latest_path,
|
|
335
365
|
"pkgs/latest.json",
|
|
336
|
-
skip_if_exists=
|
|
366
|
+
skip_if_exists=False,
|
|
337
367
|
)
|
|
338
368
|
cdn_refresh_urls(version, asset_names)
|
|
339
369
|
|