@whyour/qinglong 2.21.0 → 2.23.0

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.
Files changed (362) hide show
  1. package/.dockerignore +13 -0
  2. package/.env.example +7 -0
  3. package/AGENTS.md +2 -2
  4. package/README-en.md +24 -0
  5. package/README.md +24 -0
  6. package/back/protos/api.proto +9 -1
  7. package/back/protos/cron.proto +8 -1
  8. package/deploy/kubernetes/README.md +81 -0
  9. package/deploy/kubernetes/base/kustomization.yaml +5 -0
  10. package/deploy/kubernetes/base/qinglong.yaml +95 -0
  11. package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
  12. package/docker/Dockerfile +31 -12
  13. package/docker/Dockerfile.310 +31 -12
  14. package/docker/Dockerfile.debian +22 -14
  15. package/docker/Dockerfile.debian310 +24 -14
  16. package/docker/build-manifest.cjs +28 -0
  17. package/docker/verify-build.cjs +49 -0
  18. package/docs/development/node-cron-migration.md +49 -0
  19. package/docs/development/task-startup.md +78 -0
  20. package/docs/releases/2.22.0-validation.md +49 -0
  21. package/docs/releases/2.22.0.md +62 -0
  22. package/docs/releases/2.23.0.md +33 -0
  23. package/docs/script-history.md +53 -0
  24. package/ecosystem.config.js +10 -1
  25. package/package.json +19 -13
  26. package/sample/config.sample.sh +17 -2
  27. package/sample/notify.js +118 -0
  28. package/sample/notify.py +93 -0
  29. package/scripts/benchmark-execution.cjs +96 -0
  30. package/scripts/benchmark-script-history.cjs +39 -0
  31. package/scripts/publish-static.sh +34 -0
  32. package/scripts/sync-static.sh +20 -0
  33. package/scripts/wait-for-mirror.sh +214 -0
  34. package/scripts/write-build-info.cjs +27 -0
  35. package/shell/api.sh +96 -83
  36. package/shell/check.sh +59 -19
  37. package/shell/lang/en.sh +6 -0
  38. package/shell/lang/zh.sh +6 -0
  39. package/shell/node_path_cache.sh +136 -0
  40. package/shell/otask.sh +17 -10
  41. package/shell/preload/sitecustomize.js +11 -3
  42. package/shell/preload/sitecustomize.py +4 -2
  43. package/shell/share.sh +27 -10
  44. package/shell/start.sh +6 -3
  45. package/shell/task-timeout.sh +63 -0
  46. package/shell/task.sh +21 -9
  47. package/shell/update.sh +104 -98
  48. package/shell/upgrade.cjs +8 -0
  49. package/static/build/api/clientIp.js +42 -0
  50. package/static/build/api/config.js +9 -21
  51. package/static/build/api/cron.js +39 -3
  52. package/static/build/api/dashboard.js +50 -6
  53. package/static/build/api/env.js +17 -16
  54. package/static/build/api/health.js +2 -2
  55. package/static/build/api/index.js +4 -0
  56. package/static/build/api/log.js +39 -19
  57. package/static/build/api/open.js +2 -1
  58. package/static/build/api/retention.js +63 -0
  59. package/static/build/api/script.js +172 -25
  60. package/static/build/api/subscription.js +19 -8
  61. package/static/build/api/system.js +66 -12
  62. package/static/build/api/user.js +75 -15
  63. package/static/build/app.js +63 -54
  64. package/static/build/bootstrap/database.js +51 -0
  65. package/static/build/config/const.js +2 -0
  66. package/static/build/config/grpcCerts.js +93 -44
  67. package/static/build/config/index.js +0 -4
  68. package/static/build/config/share.js +5 -4
  69. package/static/build/config/subscription.js +19 -11
  70. package/static/build/config/util.js +142 -45
  71. package/static/build/data/cron.js +1 -0
  72. package/static/build/data/notify.js +18 -1
  73. package/static/build/data/sock.js +1 -0
  74. package/static/build/loaders/app.js +8 -6
  75. package/static/build/loaders/db.js +5 -35
  76. package/static/build/loaders/deps.js +30 -22
  77. package/static/build/loaders/express.js +46 -32
  78. package/static/build/loaders/initData.js +26 -33
  79. package/static/build/loaders/initFile.js +1 -1
  80. package/static/build/loaders/initTask.js +14 -3
  81. package/static/build/loaders/server.js +1 -1
  82. package/static/build/loaders/sock.js +72 -6
  83. package/static/build/middlewares/monitoring.js +12 -33
  84. package/static/build/middlewares/protectedPathCase.js +17 -0
  85. package/static/build/middlewares/uniqueConstraintError.js +15 -0
  86. package/static/build/protos/api.js +78 -2
  87. package/static/build/protos/cron.js +83 -5
  88. package/static/build/protos/health.js +1 -1
  89. package/static/build/schedule/addCron.js +67 -19
  90. package/static/build/schedule/api.js +5 -2
  91. package/static/build/schedule/client.js +56 -6
  92. package/static/build/schedule/delCron.js +11 -1
  93. package/static/build/schedule/health.js +72 -7
  94. package/static/build/schedule/setConcurrency.js +27 -0
  95. package/static/build/services/config.js +5 -43
  96. package/static/build/services/cron.js +389 -174
  97. package/static/build/services/dependence.js +66 -18
  98. package/static/build/services/env.js +1 -1
  99. package/static/build/services/grpc.js +4 -3
  100. package/static/build/services/health.js +4 -7
  101. package/static/build/services/http.js +9 -3
  102. package/static/build/services/log.js +2 -3
  103. package/static/build/services/metrics.js +46 -14
  104. package/static/build/services/notify.js +73 -5
  105. package/static/build/services/open.js +106 -31
  106. package/static/build/services/retention.js +123 -0
  107. package/static/build/services/schedule.js +77 -43
  108. package/static/build/services/script.js +4 -5
  109. package/static/build/services/scriptHistory.js +30 -0
  110. package/static/build/services/sshKey.js +39 -14
  111. package/static/build/services/subscription.js +161 -87
  112. package/static/build/services/system.js +116 -43
  113. package/static/build/services/user.js +255 -37
  114. package/static/build/shared/auth.js +22 -3
  115. package/static/build/shared/authMutation.js +17 -0
  116. package/static/build/shared/childProcess.js +82 -0
  117. package/static/build/shared/clientIp.js +27 -0
  118. package/static/build/shared/cronCommand.js +17 -0
  119. package/static/build/shared/cronSchedule.js +101 -0
  120. package/static/build/shared/cronScheduler.js +73 -0
  121. package/static/build/shared/errors.js +9 -0
  122. package/static/build/shared/fileAccess.js +60 -0
  123. package/static/build/shared/i18n.js +63 -4
  124. package/static/build/shared/logPath.js +15 -0
  125. package/static/build/shared/logReader.js +85 -0
  126. package/static/build/shared/logStreamManager.js +80 -60
  127. package/static/build/shared/loginThrottle.js +45 -0
  128. package/static/build/shared/pLimit.js +22 -8
  129. package/static/build/shared/password.js +30 -0
  130. package/static/build/shared/retention.js +58 -0
  131. package/static/build/shared/runCron.js +39 -17
  132. package/static/build/shared/schedulerMutationLock.js +44 -0
  133. package/static/build/shared/schedulerReadiness.js +82 -0
  134. package/static/build/shared/schemaMigrations.js +58 -0
  135. package/static/build/shared/scriptHistory.js +445 -0
  136. package/static/build/shared/shellQuote.js +11 -0
  137. package/static/build/shared/startupProcess.js +48 -0
  138. package/static/build/shared/store.js +7 -0
  139. package/static/build/shared/subscriptionMutationLock.js +34 -0
  140. package/static/build/shared/subscriptionPath.js +41 -0
  141. package/static/build/shared/subscriptionStorage.js +98 -0
  142. package/static/build/shared/trustProxy.js +119 -0
  143. package/static/build/shared/utils.js +2 -1
  144. package/static/build/token.js +3 -14
  145. package/static/build/validation/schedule.js +6 -12
  146. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  147. package/static/dist/2031.6af40025.async.js +1 -0
  148. package/static/dist/2693.51c2636b.async.js +1 -0
  149. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  150. package/static/dist/2901.2ca95295.async.js +1 -0
  151. package/static/dist/292.264757f0.async.js +1 -0
  152. package/static/dist/3512.95e41255.async.js +1 -0
  153. package/static/dist/445.a65ff63b.async.js +1 -0
  154. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  155. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  156. package/static/dist/6212.9e6d9913.async.js +1 -0
  157. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  158. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  159. package/static/dist/7231.f7e5b668.async.js +1 -0
  160. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  161. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  162. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  163. package/static/dist/8844.a0fef08e.async.js +1 -0
  164. package/static/dist/index.html +2 -2
  165. package/static/dist/layouts__index.633d3553.async.js +1 -0
  166. package/static/dist/preload_helper.01fcd534.js +1 -0
  167. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  168. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  169. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  170. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  171. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  172. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  173. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  174. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  175. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  176. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  177. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  178. package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
  179. package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
  180. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  181. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  182. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  183. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  184. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  185. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  186. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  187. package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
  188. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
  189. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
  190. package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
  191. package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
  192. package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
  193. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  194. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
  195. package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
  196. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  197. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  198. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  199. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  200. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  201. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  202. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  203. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  204. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  205. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  206. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  207. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  208. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  209. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  210. package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
  211. package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
  212. package/test/back/advisory-input-security.test.cjs +416 -0
  213. package/test/back/auth-security.test.cjs +74 -0
  214. package/test/back/build-provenance.test.cjs +150 -0
  215. package/test/back/code-scanning-security.test.cjs +189 -0
  216. package/test/back/cron-log-name.test.cjs +110 -0
  217. package/test/back/cron-macros.test.cjs +51 -0
  218. package/test/back/cron-schedule-compatibility.test.cjs +69 -0
  219. package/test/back/cron-scheduler-routing.test.cjs +59 -0
  220. package/test/back/cron-validation.test.cjs +45 -0
  221. package/test/back/dashboard-failures.test.cjs +173 -0
  222. package/test/back/database-bootstrap.test.cjs +193 -0
  223. package/test/back/dependence-cache-status.test.cjs +125 -0
  224. package/test/back/deprecated-file-routes.test.cjs +82 -0
  225. package/test/back/draft-path-security.test.cjs +235 -0
  226. package/test/back/ecosystem.test.cjs +28 -0
  227. package/test/back/env-import-security.test.cjs +91 -0
  228. package/test/back/env-name-parsing.test.cjs +96 -0
  229. package/test/back/execution-lifecycle.test.cjs +236 -0
  230. package/test/back/file-access-scope.test.cjs +180 -0
  231. package/test/back/file-access-security.test.cjs +47 -0
  232. package/test/back/fileTreeListing.test.cjs +57 -0
  233. package/test/back/grpc-cron-response.test.cjs +60 -0
  234. package/test/back/grpc-mtls-security.test.cjs +136 -0
  235. package/test/back/http-exclusive-listen.test.cjs +31 -0
  236. package/test/back/http-security.test.cjs +313 -0
  237. package/test/back/legacy-cron-recovery.test.cjs +76 -0
  238. package/test/back/linux-mirror-result.test.cjs +176 -0
  239. package/test/back/listen-security.test.cjs +68 -0
  240. package/test/back/log-path-security.test.cjs +158 -0
  241. package/test/back/logReader.test.cjs +72 -0
  242. package/test/back/manual-execution.test.cjs +85 -0
  243. package/test/back/manual-stop-claim.test.cjs +220 -0
  244. package/test/back/metrics.test.cjs +34 -0
  245. package/test/back/mirror-status.test.cjs +257 -0
  246. package/test/back/monitoring.test.cjs +73 -0
  247. package/test/back/node-cron-migration.test.cjs +65 -0
  248. package/test/back/node-path-cache.test.cjs +202 -0
  249. package/test/back/node-path-lock.test.cjs +182 -0
  250. package/test/back/npm-publication.test.cjs +70 -0
  251. package/test/back/preload-lazy-notify.test.cjs +168 -0
  252. package/test/back/primary-apm.test.cjs +24 -0
  253. package/test/back/process-exit-state.test.cjs +81 -0
  254. package/test/back/process-stop-signal.test.cjs +77 -0
  255. package/test/back/protected-path-case.test.cjs +58 -0
  256. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  257. package/test/back/queued-cron-invalidation.test.cjs +98 -0
  258. package/test/back/restart-instance-recovery.test.cjs +116 -0
  259. package/test/back/retention.test.cjs +131 -0
  260. package/test/back/role-loading.test.cjs +118 -0
  261. package/test/back/schedule-health.test.cjs +86 -0
  262. package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
  263. package/test/back/scheduler-concurrency.test.cjs +411 -0
  264. package/test/back/scheduler-file-lock.test.cjs +51 -0
  265. package/test/back/scheduler-mutation.test.cjs +312 -0
  266. package/test/back/scheduler-readiness.test.cjs +85 -0
  267. package/test/back/scheduler-reconciliation.test.cjs +206 -0
  268. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  269. package/test/back/schema-migrations.test.cjs +127 -0
  270. package/test/back/script-file-access.test.cjs +210 -0
  271. package/test/back/script-history-api.test.cjs +551 -0
  272. package/test/back/script-history.test.cjs +383 -0
  273. package/test/back/shell-api-parsing.test.cjs +184 -0
  274. package/test/back/shell-translation-output.test.cjs +16 -0
  275. package/test/back/shell-upgrade.test.cjs +312 -0
  276. package/test/back/shellApiToken.test.cjs +151 -0
  277. package/test/back/sock-polling.test.cjs +297 -0
  278. package/test/back/sock-security.test.cjs +72 -0
  279. package/test/back/ssh-config-home.test.cjs +113 -0
  280. package/test/back/start-env-preservation.test.cjs +53 -0
  281. package/test/back/static-mirror-trigger.test.cjs +441 -0
  282. package/test/back/static-mirror.test.cjs +179 -0
  283. package/test/back/stop-failure-feedback.test.cjs +158 -0
  284. package/test/back/stop-race.test.cjs +171 -0
  285. package/test/back/subscription-cleanup.test.cjs +53 -0
  286. package/test/back/subscription-mutation-lock.test.cjs +83 -0
  287. package/test/back/subscription-review-regression.test.cjs +607 -0
  288. package/test/back/subscription-stop-state.test.cjs +66 -0
  289. package/test/back/subscription-storage-regression.test.cjs +553 -0
  290. package/test/back/system-dependence-cache.test.cjs +127 -0
  291. package/test/back/system-export-history.test.cjs +119 -0
  292. package/test/back/systemTokenRenewal.test.cjs +497 -0
  293. package/test/back/task-shell-lifecycle.test.cjs +194 -0
  294. package/test/back/task-time.test.cjs +116 -0
  295. package/test/back/unique-constraint-error.test.cjs +72 -0
  296. package/test/back/upgrade-guards.test.cjs +285 -0
  297. package/test/back/upgrade-lifecycle.test.cjs +288 -0
  298. package/test/back/upgrade-transaction.test.cjs +133 -0
  299. package/test/back/user-api.test.cjs +99 -0
  300. package/test/back/user-security.test.cjs +349 -0
  301. package/test/back/worker-apm.test.cjs +84 -0
  302. package/test/back/wpush-grpc.test.cjs +116 -0
  303. package/test/fixtures/legacy-cron.json +1371 -0
  304. package/test/front/cron-log-pagination.test.cjs +214 -0
  305. package/test/front/diff-file-routing.test.cjs +126 -0
  306. package/test/front/http-auth.test.cjs +152 -0
  307. package/test/front/http-error.test.cjs +29 -0
  308. package/test/front/script-history-save.test.cjs +121 -0
  309. package/test/helpers/load-security-module.cjs +42 -0
  310. package/test/helpers/upgrade-fixture.cjs +30 -0
  311. package/version.yaml +14 -34
  312. package/CLAUDE.md +0 -43
  313. package/static/dist/1147.c420132e.async.js +0 -1
  314. package/static/dist/134.54df9e38.async.js +0 -1
  315. package/static/dist/2096.6d98fd12.async.js +0 -1
  316. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  317. package/static/dist/2286.164bb089.async.js +0 -1
  318. package/static/dist/3191.63263871.async.js +0 -1
  319. package/static/dist/4859.6592cebb.async.js +0 -1
  320. package/static/dist/4902.555f92ab.async.js +0 -1
  321. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  322. package/static/dist/6431.c50479be.async.js +0 -1
  323. package/static/dist/6707.801b886b.async.js +0 -1
  324. package/static/dist/8826.2447a104.async.js +0 -1
  325. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  326. package/static/dist/preload_helper.0431c0f3.js +0 -1
  327. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  328. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  329. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  330. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  331. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  332. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  333. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  334. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  335. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  336. package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
  337. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  338. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  339. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  340. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  341. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  342. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  343. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  344. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  345. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  346. package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
  347. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  348. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  349. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  350. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  351. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  352. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  353. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  354. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  355. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  356. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  357. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  358. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  359. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  360. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  361. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
  362. /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
package/sample/notify.js CHANGED
@@ -147,16 +147,26 @@ const push_config = {
147
147
  NTFY_PASSWORD: '', // 推送用户密码,可选
148
148
  NTFY_ACTIONS: '', // 推送用户动作,可选
149
149
 
150
+ // 方式一:标准发送(更强大)
150
151
  // 官方文档: https://wxpusher.zjiecode.com/docs/
151
152
  // 管理后台: https://wxpusher.zjiecode.com/admin/
152
153
  WXPUSHER_APP_TOKEN: '', // wxpusher 的 appToken
153
154
  WXPUSHER_TOPIC_IDS: '', // wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
154
155
  WXPUSHER_UIDS: '', // wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
156
+ // 方式二:极简发送(最简单,简单好用,一键配置,更推荐)
157
+ // wxPusher 的 SPT(极简推送),扫码获取 https://wxpusher.zjiecode.com/docs/#/?id=spt
158
+ // 多个用英文逗号,分隔,最多10个;与上面的 appToken 方式二选一即可
159
+ WXPUSHER_SPT_LIST: '', // wxpusher 的 SPT(极简推送),多个用英文逗号,分隔,最多10个
155
160
 
156
161
  // 官方文档: https://openilink.com/docs/hub/apps
157
162
  OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取
158
163
  OPENILINK_HUB_URL: '', // OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
159
164
  OPENILINK_CONTEXT_TOKEN: '', // OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
165
+
166
+ // WPUSH 官方文档: https://wpush.cn/docs
167
+ WPUSH_APIKEY: '', // WPUSH 的 API Key,在 https://wpush.cn/settings 获取
168
+ WPUSH_CHANNEL: 'wechat', // 推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot
169
+ WPUSH_TOPIC_CODE: '', // 可选,Topic 广播编码
160
170
  };
161
171
 
162
172
  for (const key in push_config) {
@@ -1431,6 +1441,112 @@ function wxPusherNotify(text, desp) {
1431
1441
  });
1432
1442
  }
1433
1443
 
1444
+ function wxPusherSptNotify(text, desp) {
1445
+ return new Promise((resolve) => {
1446
+ const { WXPUSHER_SPT_LIST } = push_config;
1447
+ if (WXPUSHER_SPT_LIST) {
1448
+ // 处理 SPT,将逗号分隔的字符串转为数组
1449
+ const spts = WXPUSHER_SPT_LIST.split(',')
1450
+ .map((spt) => spt.trim())
1451
+ .filter((spt) => spt);
1452
+
1453
+ if (!spts.length) {
1454
+ console.log('wxpusher SPT 不能为空!!');
1455
+ return resolve();
1456
+ }
1457
+ if (spts.length > 10) {
1458
+ console.log('wxpusher SPT 最多支持 10 个!!');
1459
+ return resolve();
1460
+ }
1461
+
1462
+ const body = {
1463
+ content: `<h1>${text}</h1><br/><div style='white-space: pre-wrap;'>${desp}</div>`,
1464
+ summary: text,
1465
+ contentType: 2,
1466
+ // 单个 SPT 用 spt,多个用 sptList
1467
+ ...(spts.length === 1 ? { spt: spts[0] } : { sptList: spts }),
1468
+ };
1469
+
1470
+ const options = {
1471
+ url: 'https://wxpusher.zjiecode.com/api/send/message/simple-push',
1472
+ body: JSON.stringify(body),
1473
+ headers: {
1474
+ 'Content-Type': 'application/json',
1475
+ },
1476
+ timeout,
1477
+ };
1478
+
1479
+ $.post(options, (err, resp, data) => {
1480
+ try {
1481
+ if (err) {
1482
+ console.log('wxpusher SPT 发送通知消息失败!\n', err);
1483
+ } else {
1484
+ if (data.code === 1000) {
1485
+ console.log('wxpusher SPT 发送通知消息完成!');
1486
+ } else {
1487
+ console.log(`wxpusher SPT 发送通知消息异常:${data.msg}`);
1488
+ }
1489
+ }
1490
+ } catch (e) {
1491
+ $.logErr(e, resp);
1492
+ } finally {
1493
+ resolve(data);
1494
+ }
1495
+ });
1496
+ } else {
1497
+ resolve();
1498
+ }
1499
+ });
1500
+ }
1501
+
1502
+
1503
+
1504
+ function wpushNotify(text, desp) {
1505
+ return new Promise((resolve) => {
1506
+ const { WPUSH_APIKEY, WPUSH_CHANNEL, WPUSH_TOPIC_CODE } = push_config;
1507
+ if (WPUSH_APIKEY) {
1508
+ const body = {
1509
+ apikey: `${WPUSH_APIKEY}`,
1510
+ title: `${text}`,
1511
+ content: `${desp}`,
1512
+ channel: `${WPUSH_CHANNEL || 'wechat'}`,
1513
+ };
1514
+ if (WPUSH_TOPIC_CODE) {
1515
+ body.topic_code = WPUSH_TOPIC_CODE;
1516
+ }
1517
+ const options = {
1518
+ url: `https://api.wpush.cn/api/v1/send`,
1519
+ body: JSON.stringify(body),
1520
+ headers: {
1521
+ 'Content-Type': 'application/json',
1522
+ },
1523
+ timeout,
1524
+ };
1525
+ $.post(options, (err, resp, data) => {
1526
+ try {
1527
+ if (err) {
1528
+ console.log('WPUSH 发送通知消息失败!\n', err);
1529
+ } else {
1530
+ if (data.code === 0) {
1531
+ console.log('WPUSH 发送通知消息成功!');
1532
+ } else {
1533
+ console.log(
1534
+ `WPUSH 发送通知消息异常:${data.message || JSON.stringify(data)}`,
1535
+ );
1536
+ }
1537
+ }
1538
+ } catch (e) {
1539
+ $.logErr(e, resp);
1540
+ } finally {
1541
+ resolve(data);
1542
+ }
1543
+ });
1544
+ } else {
1545
+ resolve();
1546
+ }
1547
+ });
1548
+ }
1549
+
1434
1550
  function openiLinkNotify(text, desp) {
1435
1551
  return new Promise((resolve) => {
1436
1552
  const { OPENILINK_APP_TOKEN, OPENILINK_HUB_URL, OPENILINK_CONTEXT_TOKEN } =
@@ -1609,7 +1725,9 @@ async function sendNotify(text, desp, params = {}) {
1609
1725
  qmsgNotify(text, desp), // 自定义通知
1610
1726
  ntfyNotify(text, desp), // Ntfy
1611
1727
  wxPusherNotify(text, desp), // wxpusher
1728
+ wxPusherSptNotify(text, desp), // wxpusher SPT
1612
1729
  openiLinkNotify(text, desp), // OpeniLink
1730
+ wpushNotify(text, desp), // WPUSH
1613
1731
  ]);
1614
1732
  }
1615
1733
 
package/sample/notify.py CHANGED
@@ -133,13 +133,25 @@ push_config = {
133
133
  'NTFY_PASSWORD': '', # 推送用户密码,可选
134
134
  'NTFY_ACTIONS': '', # 推送用户动作,可选
135
135
 
136
+ ### 方式一:标准发送(更强大)
137
+ #### 官方文档: https://wxpusher.zjiecode.com/docs/
138
+ #### 管理后台: https://wxpusher.zjiecode.com/admin/
136
139
  'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
137
140
  'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
138
141
  'WXPUSHER_UIDS': '', # wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
142
+ ### 方式二:极简发送(最简单,简单好用,一键配置,更推荐)
143
+ #### wxPusher 的 SPT(极简推送),扫码获取 https://wxpusher.zjiecode.com/docs/#/?id=spt
144
+ #### 多个用英文逗号,分隔,最多10个;与上面的 appToken 方式二选一即可
145
+ 'WXPUSHER_SPT_LIST': '', # wxpusher 的 SPT(极简推送),多个用英文逗号,分隔,最多10个 官方文档: https://wxpusher.zjiecode.com/docs/#/?id=spt
139
146
 
140
147
  'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps
141
148
  'OPENILINK_HUB_URL': '', # OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
142
149
  'OPENILINK_CONTEXT_TOKEN': '', # OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
150
+
151
+ # WPUSH 官方文档: https://wpush.cn/docs
152
+ 'WPUSH_APIKEY': '', # WPUSH 的 API Key,在 https://wpush.cn/settings 获取
153
+ 'WPUSH_CHANNEL': 'wechat', # 推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot
154
+ 'WPUSH_TOPIC_CODE': '', # 可选,Topic 广播编码
143
155
  }
144
156
  # fmt: on
145
157
 
@@ -902,6 +914,83 @@ def wxpusher_bot(title: str, content: str) -> None:
902
914
  print(f"wxpusher 推送失败!错误信息:{response.get('msg')}")
903
915
 
904
916
 
917
+ def wxpusher_spt(title: str, content: str) -> None:
918
+ """
919
+ 通过 wxpusher 极简推送(SPT)推送消息。
920
+ 支持的环境变量:
921
+ - WXPUSHER_SPT_LIST: SPT, 多个用英文逗号,分隔, 最多10个
922
+ """
923
+ if not push_config.get("WXPUSHER_SPT_LIST"):
924
+ return
925
+
926
+ # 处理 SPT,将逗号分隔的字符串转为数组
927
+ spts = [
928
+ spt.strip()
929
+ for spt in push_config.get("WXPUSHER_SPT_LIST").split(",")
930
+ if spt.strip()
931
+ ]
932
+
933
+ if not spts:
934
+ print("wxpusher 服务的 WXPUSHER_SPT_LIST 不能为空!!")
935
+ return
936
+ if len(spts) > 10:
937
+ print("wxpusher 服务的 WXPUSHER_SPT_LIST 最多支持 10 个!!")
938
+ return
939
+
940
+ print("wxpusher SPT 服务启动")
941
+
942
+ url = "https://wxpusher.zjiecode.com/api/send/message/simple-push"
943
+
944
+ data = {
945
+ "content": f"<h1>{title}</h1><br/><div style='white-space: pre-wrap;'>{content}</div>",
946
+ "summary": title,
947
+ "contentType": 2,
948
+ }
949
+ # 单个 SPT 用 spt,多个用 sptList
950
+ if len(spts) == 1:
951
+ data["spt"] = spts[0]
952
+ else:
953
+ data["sptList"] = spts
954
+
955
+ headers = {"Content-Type": "application/json"}
956
+ response = requests.post(url=url, json=data, headers=headers).json()
957
+
958
+ if response.get("code") == 1000:
959
+ print("wxpusher SPT 推送成功!")
960
+ else:
961
+ print(f"wxpusher SPT 推送失败!错误信息:{response.get('msg')}")
962
+
963
+
964
+
965
+ def wpush(title: str, content: str) -> None:
966
+ """
967
+ 通过 WPUSH 推送消息。
968
+ 官方文档: https://wpush.cn/docs
969
+ """
970
+ if not push_config.get("WPUSH_APIKEY"):
971
+ return
972
+
973
+ print("WPUSH 服务启动")
974
+
975
+ url = "https://api.wpush.cn/api/v1/send"
976
+ data = {
977
+ "apikey": push_config.get("WPUSH_APIKEY"),
978
+ "title": title,
979
+ "content": content,
980
+ "channel": push_config.get("WPUSH_CHANNEL") or "wechat",
981
+ }
982
+ if push_config.get("WPUSH_TOPIC_CODE"):
983
+ data["topic_code"] = push_config.get("WPUSH_TOPIC_CODE")
984
+
985
+ headers = {"Content-Type": "application/json"}
986
+ response = requests.post(url=url, json=data, headers=headers, timeout=15).json()
987
+
988
+ if response.get("code") == 0:
989
+ print("WPUSH 推送成功!")
990
+ else:
991
+ print(f'WPUSH 推送失败!错误信息:{response.get("message") or response}')
992
+
993
+
905
994
  def openilink(title: str, content: str) -> None:
906
995
  """
907
996
  通过 OpeniLink 推送消息。
@@ -1104,8 +1193,12 @@ def add_notify_function():
1104
1193
  push_config.get("WXPUSHER_TOPIC_IDS") or push_config.get("WXPUSHER_UIDS")
1105
1194
  ):
1106
1195
  notify_function.append(wxpusher_bot)
1196
+ if push_config.get("WXPUSHER_SPT_LIST"):
1197
+ notify_function.append(wxpusher_spt)
1107
1198
  if push_config.get("OPENILINK_APP_TOKEN"):
1108
1199
  notify_function.append(openilink)
1200
+ if push_config.get("WPUSH_APIKEY"):
1201
+ notify_function.append(wpush)
1109
1202
  if not notify_function:
1110
1203
  print(f"无推送渠道,请检查通知变量是否正确")
1111
1204
  return notify_function
@@ -0,0 +1,96 @@
1
+ // Microbenchmark of the process observer, not a container or scheduler benchmark.
2
+ const fs = require('node:fs');
3
+ const os = require('node:os');
4
+ const crypto = require('node:crypto');
5
+ const { spawn, execFileSync } = require('node:child_process');
6
+ const { performance } = require('node:perf_hooks');
7
+ const { observeChildProcess } = require('../back/shared/childProcess');
8
+
9
+ const args = process.argv.slice(2).filter((arg) => arg !== '--');
10
+ const runsArg = args.find((arg) => arg.startsWith('--runs='));
11
+ const runs = runsArg ? Number(runsArg.slice(7)) : 30;
12
+ if (!Number.isInteger(runs) || runs < 3 || runs > 10000)
13
+ throw new Error('runs must be between 3 and 10000');
14
+ const output = args.find((arg) => arg.startsWith('--output='))?.slice(9);
15
+ const git = (...args) => execFileSync('git', args, { encoding: 'utf8' }).trim();
16
+ const scenarios = [
17
+ { name: 'empty-node', command: '' },
18
+ {
19
+ name: 'log-1MiB',
20
+ command: 'process.stdout.write("x".repeat(1024 * 1024))',
21
+ bytes: 1024 * 1024,
22
+ },
23
+ { name: 'spawn-failure', shell: '/nonexistent-ql-benchmark-shell' },
24
+ ];
25
+
26
+ (async () => {
27
+ const report = {
28
+ schema: 1,
29
+ observerSha256: crypto
30
+ .createHash('sha256')
31
+ .update(fs.readFileSync('back/shared/childProcess.ts'))
32
+ .digest('hex'),
33
+ benchmarkSha256: crypto
34
+ .createHash('sha256')
35
+ .update(fs.readFileSync(__filename))
36
+ .digest('hex'),
37
+ scope:
38
+ 'local process observer only; parent CPU excludes child CPU; no panel/container load measured',
39
+ sourceCommit: git('rev-parse', 'HEAD'),
40
+ dirty: git('status', '--porcelain') !== '',
41
+ lockfileSha256: crypto
42
+ .createHash('sha256')
43
+ .update(fs.readFileSync('pnpm-lock.yaml'))
44
+ .digest('hex'),
45
+ node: process.version,
46
+ platform: process.platform,
47
+ arch: process.arch,
48
+ cpu: os.cpus()[0]?.model,
49
+ cores: os.cpus().length,
50
+ timestamp: new Date().toISOString(),
51
+ runs,
52
+ scenarios: [],
53
+ };
54
+ for (const scenario of scenarios) {
55
+ const samples = [];
56
+ const cpuStart = process.cpuUsage();
57
+ for (let index = 0; index < runs; index++) {
58
+ const start = performance.now();
59
+ let bytes = 0;
60
+ const child = scenario.shell
61
+ ? spawn('true', { shell: scenario.shell })
62
+ : spawn(process.execPath, ['-e', scenario.command]);
63
+ const result = await observeChildProcess(child, {
64
+ onStdout: async (chunk) => {
65
+ bytes += Buffer.byteLength(chunk);
66
+ },
67
+ }).completed;
68
+ if (scenario.shell ? !result.error : result.error || result.code !== 0)
69
+ throw new Error(`Unexpected result: ${scenario.name}`);
70
+ if (bytes !== (scenario.bytes || 0))
71
+ throw new Error(`Output loss: ${scenario.name}`);
72
+ samples.push({
73
+ wallMs: performance.now() - start,
74
+ bytes,
75
+ code: result.code,
76
+ error: result.error?.message,
77
+ });
78
+ }
79
+ const sorted = samples.map((sample) => sample.wallMs).sort((a, b) => a - b);
80
+ const percentile = (p) => sorted[Math.ceil(sorted.length * p) - 1];
81
+ report.scenarios.push({
82
+ name: scenario.name,
83
+ parentCpuMicros: process.cpuUsage(cpuStart),
84
+ p50Ms: percentile(0.5),
85
+ p95Ms: percentile(0.95),
86
+ ...(runs >= 100 ? { p99Ms: percentile(0.99) } : {}),
87
+ samples,
88
+ });
89
+ }
90
+ const json = JSON.stringify(report, null, 2) + '\n';
91
+ if (output) fs.writeFileSync(output, json);
92
+ else process.stdout.write(json);
93
+ })().catch((error) => {
94
+ console.error(error);
95
+ process.exitCode = 1;
96
+ });
@@ -0,0 +1,39 @@
1
+ // Reproducible storage comparison, without touching actual script history.
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const zlib = require('node:zlib');
5
+ for (const file of ['sample/notify.js', 'shell/task.sh']) {
6
+ const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
7
+ const versions = Array.from({ length: 20 }, (_, i) => ({
8
+ content: source + '\n// edit ' + i,
9
+ }));
10
+ const raw = Buffer.from(JSON.stringify(versions));
11
+ const strategies = {
12
+ gzipSeparate: () =>
13
+ versions.reduce(
14
+ (sum, version) => sum + zlib.gzipSync(version.content).length,
15
+ 0,
16
+ ),
17
+ gzipBundle: () => zlib.gzipSync(raw).length,
18
+ brotliBundle: () =>
19
+ zlib.brotliCompressSync(raw, {
20
+ params: {
21
+ [zlib.constants.BROTLI_PARAM_QUALITY]: 4,
22
+ [zlib.constants.BROTLI_PARAM_LGWIN]: 22,
23
+ },
24
+ }).length,
25
+ };
26
+ for (const [strategy, compress] of Object.entries(strategies)) {
27
+ const start = performance.now();
28
+ const bytes = compress();
29
+ console.log(
30
+ JSON.stringify({
31
+ file,
32
+ strategy,
33
+ rawBytes: raw.length,
34
+ bytes,
35
+ ms: +(performance.now() - start).toFixed(2),
36
+ }),
37
+ );
38
+ }
39
+ }
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ destination=$1
4
+ ref=$2
5
+ ref_type=$3
6
+ git check-ref-format "refs/heads/$ref"
7
+ script_dir=$(cd "$(dirname "$0")" && pwd)
8
+ # Publish only a complete artifact from the checked-out source commit.
9
+ node "$script_dir/../docker/verify-build.cjs"
10
+ if [[ "$ref_type" == 'tag' ]]; then
11
+ version=$(awk '$1 == "version:" { print $2; exit }' version.yaml)
12
+ if [[ "$ref" != "v$version" ]]; then
13
+ echo "::error::Release tag $ref does not match version.yaml ($version)"
14
+ exit 1
15
+ fi
16
+ elif [[ "$ref_type" != 'branch' ]]; then
17
+ echo "::error::Unsupported ref type: $ref_type"
18
+ exit 1
19
+ fi
20
+ workspace=$(mktemp -d)
21
+ trap 'rm -rf "$workspace"' EXIT
22
+ cp -a static/. "$workspace/"
23
+ git init -b "$ref" "$workspace"
24
+ git -C "$workspace" config user.name 'github-actions[bot]'
25
+ git -C "$workspace" config user.email 'github-actions[bot]@users.noreply.github.com'
26
+ git -C "$workspace" add -f .
27
+ git -C "$workspace" commit --allow-empty -m "Build static from $(git rev-parse HEAD)"
28
+ refs=("refs/heads/$ref:refs/heads/$ref")
29
+ if [[ "$ref_type" == 'tag' ]]; then
30
+ # Keep version branches for existing archive URLs and publish real Git tags.
31
+ git -C "$workspace" tag "$ref"
32
+ refs+=("refs/tags/$ref:refs/tags/$ref")
33
+ fi
34
+ git -C "$workspace" push --force --quiet "$destination" "${refs[@]}"
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+ # Static branches are orphan snapshots. Fetch complete commits for the branch
3
+ # that was built: a shallow/default-branch clone is rejected by mirror servers.
4
+ set -euo pipefail
5
+ destination=$1
6
+ branch=$2
7
+ ref_type=${3:-branch}
8
+ git check-ref-format "refs/heads/$branch"
9
+ workspace=$(mktemp -d)
10
+ trap 'rm -rf "$workspace"' EXIT
11
+ git init --bare "$workspace"
12
+ fetch_refs=("+refs/heads/$branch:refs/heads/$branch")
13
+ push_refs=("refs/heads/$branch:refs/heads/$branch")
14
+ if [[ "$ref_type" == 'tag' ]]; then
15
+ fetch_refs+=("+refs/tags/$branch:refs/tags/$branch")
16
+ push_refs+=("refs/tags/$branch:refs/tags/$branch")
17
+ fi
18
+ git -C "$workspace" fetch --no-tags "${QL_STATIC_SOURCE:-https://github.com/whyour/qinglong-static.git}" \
19
+ "${fetch_refs[@]}"
20
+ git -C "$workspace" push --force "$destination" "${push_refs[@]}"
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env bash
2
+ # Observe Pull mirrors; optionally notify them through a small GitHub push.
3
+ set -euo pipefail
4
+
5
+ if [[ $# -lt 3 || $# -gt 4 ]]; then
6
+ echo 'Usage: wait-for-mirror.sh SOURCE MIRROR REF [branch|tag]' >&2
7
+ exit 2
8
+ fi
9
+ source=$1
10
+ mirror=$2
11
+ ref=$3
12
+ ref_type=${4:-branch}
13
+ wait_seconds=${QL_MIRROR_WAIT_SECONDS:-600}
14
+ poll_interval=${QL_MIRROR_POLL_INTERVAL:-30}
15
+ query_timeout=${QL_MIRROR_QUERY_TIMEOUT:-20}
16
+ include_version_branch=${QL_MIRROR_INCLUDE_VERSION_BRANCH:-false}
17
+ notify_repo=${QL_MIRROR_NOTIFY_REPO:-}
18
+ retry_after=${QL_MIRROR_RETRY_AFTER_SECONDS:-310}
19
+ notify_on_start=${QL_MIRROR_NOTIFY_ON_START:-true}
20
+
21
+ timings=("$wait_seconds" "$poll_interval" "$query_timeout")
22
+ if [[ -n "$notify_repo" ]]; then timings+=("$retry_after"); fi
23
+ for value in "${timings[@]}"; do
24
+ if [[ ! "$value" =~ ^[1-9][0-9]{0,4}$ ]] || (( value > 86400 )); then
25
+ echo 'Mirror timing values must be integers between 1 and 86400 seconds' >&2
26
+ exit 2
27
+ fi
28
+ done
29
+ case "$ref_type" in
30
+ branch) refs=("refs/heads/$ref") ;;
31
+ tag)
32
+ refs=("refs/tags/$ref")
33
+ if [[ "$include_version_branch" == true ]]; then
34
+ refs+=("refs/heads/$ref")
35
+ fi
36
+ ;;
37
+ *) echo 'Mirror ref type must be branch or tag' >&2; exit 2 ;;
38
+ esac
39
+ if [[ "$include_version_branch" != true && "$include_version_branch" != false ]]; then
40
+ echo 'QL_MIRROR_INCLUDE_VERSION_BRANCH must be true or false' >&2
41
+ exit 2
42
+ fi
43
+ if [[ "$notify_on_start" != true && "$notify_on_start" != false ]]; then
44
+ echo 'QL_MIRROR_NOTIFY_ON_START must be true or false' >&2
45
+ exit 2
46
+ fi
47
+ for requested_ref in "${refs[@]}"; do
48
+ git check-ref-format "$requested_ref"
49
+ done
50
+ command -v timeout >/dev/null || { echo 'GNU timeout is required' >&2; exit 2; }
51
+ if [[ -n "$notify_repo" ]]; then
52
+ if [[ ! "$notify_repo" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then
53
+ echo 'QL_MIRROR_NOTIFY_REPO must be a GitHub owner/repository' >&2
54
+ exit 2
55
+ fi
56
+ command -v gh >/dev/null || { echo 'GitHub CLI is required for notifications' >&2; exit 2; }
57
+ fi
58
+ export GIT_TERMINAL_PROMPT=0
59
+ polling=false
60
+
61
+ notification_command() {
62
+ local budget=$((notification_deadline - SECONDS))
63
+ if (( budget <= 0 )); then return 1; fi
64
+ if (( budget > 10 )); then budget=10; fi
65
+ timeout --signal=KILL "${budget}s" "$@"
66
+ }
67
+
68
+ notify_static_mirror() {
69
+ local notification_deadline=$((SECONDS + 30))
70
+ if [[ "$polling" == true ]] && (( notification_deadline > wait_seconds )); then
71
+ notification_deadline=$wait_seconds
72
+ fi
73
+ local trigger_ref=refs/heads/gitee-sync-trigger
74
+ local attempt remote_refs source_sha parent tree commit delay remaining
75
+ local commit_args
76
+ if ! remote_refs=$(notification_command git ls-remote --refs "$source" "${refs[0]}"); then
77
+ echo '::warning::Could not read the published source; continuing mirror verification'
78
+ return 1
79
+ fi
80
+ source_sha=${remote_refs%%$'\t'*}
81
+ if [[ ! "$source_sha" =~ ^[0-9a-f]{40}$ ]]; then
82
+ echo "::error::Published source ref ${refs[0]} does not exist"
83
+ return 2
84
+ fi
85
+ for attempt in 1 2 3; do
86
+ if (( attempt > 1 )); then
87
+ delay=$((attempt * 2 - 2))
88
+ remaining=$((notification_deadline - SECONDS))
89
+ if (( remaining <= delay )); then break; fi
90
+ sleep "$delay"
91
+ fi
92
+ # Refresh the parent on every attempt. REST avoids the Git push endpoint's
93
+ # transient 500s, and non-forced updates preserve concurrent notifications.
94
+ if parent=$(notification_command gh api "repos/$notify_repo/git/ref/heads/gitee-sync-trigger" --jq '.object.sha' 2>&1); then
95
+ if ! tree=$(notification_command gh api "repos/$notify_repo/git/commits/$parent" --jq '.tree.sha'); then
96
+ echo "::warning::Could not read notification history (attempt $attempt)"
97
+ continue
98
+ fi
99
+ elif [[ "$parent" == *'(HTTP 404)'* ]]; then
100
+ parent=''
101
+ # A new notification branch starts with one tiny marker, never artifacts.
102
+ # Later commits reuse this tree and have no changed files in the webhook.
103
+ if ! tree=$(printf '%s' '{"tree":[{"path":".gitee-sync-trigger","mode":"100644","type":"blob","content":"Gitee Pull mirror notifications.\n"}]}' |
104
+ notification_command gh api --method POST "repos/$notify_repo/git/trees" --input - --jq '.sha'); then
105
+ echo "::warning::Could not create notification tree (attempt $attempt)"
106
+ continue
107
+ fi
108
+ else
109
+ echo "::warning::Could not read notification ref (attempt $attempt)"
110
+ continue
111
+ fi
112
+ commit_args=(-f "tree=$tree" -f "message=Trigger Gitee mirror for ${refs[0]} at $source_sha")
113
+ if [[ -n "$parent" ]]; then commit_args+=(-f "parents[]=$parent"); fi
114
+ if ! commit=$(notification_command gh api --method POST "repos/$notify_repo/git/commits" "${commit_args[@]}" --jq '.sha'); then
115
+ echo "::warning::Could not create notification commit (attempt $attempt)"
116
+ continue
117
+ fi
118
+ if [[ -n "$parent" ]]; then
119
+ if notification_command gh api --method PATCH "repos/$notify_repo/git/refs/heads/gitee-sync-trigger" -f "sha=$commit" -F force=false --silent; then
120
+ echo '::notice::Sent a small GitHub push event via REST to trigger the Gitee Pull mirror'
121
+ return 0
122
+ fi
123
+ elif notification_command gh api --method POST "repos/$notify_repo/git/refs" -f "ref=$trigger_ref" -f "sha=$commit" --silent; then
124
+ echo '::notice::Sent a small GitHub push event via REST to trigger the Gitee Pull mirror'
125
+ return 0
126
+ fi
127
+ echo "::warning::Mirror notification update failed (attempt $attempt)"
128
+ done
129
+ echo '::warning::Could not send the mirror notification; continuing mirror verification'
130
+ return 1
131
+ }
132
+
133
+ if [[ -n "$notify_repo" && "$notify_on_start" == true ]]; then
134
+ if notify_static_mirror; then :; elif [[ $? -eq 2 ]]; then exit 1; fi
135
+ fi
136
+
137
+ SECONDS=0
138
+ polling=true
139
+ attempt=0
140
+ retried=false
141
+ last_source='(not read)'
142
+ last_mirror='(not read)'
143
+ while (( SECONDS < wait_seconds )); do
144
+ attempt=$((attempt + 1))
145
+ outputs=()
146
+ ready=true
147
+ # Re-read the source after the mirror so a moving source cannot pass with
148
+ # the previous SHA. --refs compares annotated tag objects as well as branches.
149
+ urls=("$source" "$mirror" "$source")
150
+ labels=('source' 'mirror' 'source confirmation')
151
+ for index in 0 1 2; do
152
+ remaining=$((wait_seconds - SECONDS))
153
+ if (( remaining <= 0 )); then
154
+ ready=false
155
+ break
156
+ fi
157
+ budget=$query_timeout
158
+ if (( budget > remaining )); then budget=$remaining; fi
159
+ if ! output=$(timeout --signal=KILL "${budget}s" git ls-remote --refs \
160
+ "${urls[$index]}" "${refs[@]}" | LC_ALL=C sort); then
161
+ echo "::warning::Could not read ${labels[$index]} refs on attempt $attempt; retrying"
162
+ ready=false
163
+ break
164
+ fi
165
+ if (( index == 0 )); then last_source=$output; fi
166
+ if (( index == 1 )); then last_mirror=$output; fi
167
+ for requested_ref in "${refs[@]}"; do
168
+ found=false
169
+ while IFS=$'\t' read -r sha returned_ref; do
170
+ if [[ "$returned_ref" == "$requested_ref" && "$sha" =~ ^[0-9a-f]{40}([0-9a-f]{24})?$ ]]; then
171
+ found=true
172
+ fi
173
+ done <<< "$output"
174
+ if [[ "$found" == false ]]; then
175
+ echo "::notice::${labels[$index]} is missing $requested_ref; waiting"
176
+ ready=false
177
+ break
178
+ fi
179
+ done
180
+ if [[ "$ready" == false ]]; then break; fi
181
+ outputs+=("$output")
182
+ # Only confirm a source when the initial source and mirror reads match.
183
+ if (( index == 1 )) && [[ "${outputs[0]}" != "${outputs[1]}" ]]; then
184
+ ready=false
185
+ break
186
+ fi
187
+ done
188
+ if [[ "$ready" == true && "${outputs[0]}" == "${outputs[2]}" ]]; then
189
+ echo "::notice::Mirror matches the latest source refs after ${SECONDS}s"
190
+ printf '%s\n' "${outputs[2]}"
191
+ exit 0
192
+ fi
193
+ echo "Waiting for mirror (attempt $attempt, ${SECONDS}/${wait_seconds}s)"
194
+ remaining=$((wait_seconds - SECONDS))
195
+ if (( remaining <= 0 )); then break; fi
196
+ # Gitee requires five minutes between sync requests. Retry once after that
197
+ # interval without restarting the polling deadline.
198
+ if [[ -n "$notify_repo" && "$retried" == false ]] && (( SECONDS >= retry_after )); then
199
+ echo '::notice::Retrying the GitHub notification after the Gitee sync interval'
200
+ if notify_static_mirror; then :; elif [[ $? -eq 2 ]]; then exit 1; fi
201
+ retried=true
202
+ continue
203
+ fi
204
+ delay=$poll_interval
205
+ if (( delay > remaining )); then delay=$remaining; fi
206
+ if [[ -n "$notify_repo" && "$retried" == false ]] && (( SECONDS < retry_after && delay > retry_after - SECONDS )); then
207
+ delay=$((retry_after - SECONDS))
208
+ fi
209
+ sleep "$delay"
210
+ done
211
+
212
+ echo "::error::Mirror did not match the latest source refs within ${wait_seconds}s"
213
+ printf 'Last source refs:\n%s\nLast mirror refs:\n%s\n' "$last_source" "$last_mirror"
214
+ exit 1