Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rebuild development scripts and release workflow #84

Merged
merged 29 commits into from
Dec 12, 2023

Conversation

northword
Copy link
Collaborator

@northword northword commented Dec 10, 2023

Refactoring development scripts

bandicam.2023-12-10.22-04-58-107.-.Compressed.with.FlexClip.mp4

in this pr, the main npm scripts are start, build, stop, lint, and release

  • build: build the plugin

    • Create/empty build/.
    • Copy addon/** to build/addon/**.
    • Replace placeholders
    • Prepare locale files
      • Rename **/*.flt to **/${addonRef}-*.flt.
      • Prefix each fluent message with addonRef-.
    • (Production mode only) Packaging the plugin
    • ( Production only ) Prepare update.json or update-beta.json.
  • start: start a development server.

    • Build the plugin in development mode
    • Start Zotero
    • Open devtool
    • Watch src/** and addon/**.
      • If src/** changed, run esbuild and reload
      • If addon/** has changed, build the plugin (in development mode)
  • stop: terminate Zotero process (and server)

  • When the server terminates, zotero is automatically terminated.

  • When server terminates, zotero is automatically terminated.

  • Not implemented: when starting server, if there is already a running instance of zotero, server is not automatically terminated when zotero is shut down; (zotero is still automatically terminated when server is terminated)

  • After refactoring, performance is greatly improved, with builds completed in milliseconds when only src is changed, and in 0.3s when addon is modified. Before refactoring, it took 0.6s for a full build anyway.(tested against Linter for Zotero plugin)

在此pr中,npm脚本主要有startbuildstoplintrelease

  • build:构建插件

    • 建立/清空 build/
    • addon/** 复制到 build/addon/**
    • 替换预留占位符
    • 准备locale files
      • **/*.flt 重命名为 **/${addonRef}-*.flt
      • 为每一个fluent message 添加addonRef-前缀
    • (仅生产模式下) 打包插件
    • (仅生产模式下) 准备 update.jsonupdate-beta.json
  • start:启动一个开发服务器

    • 在开发模式下,构建插件
    • 启动 Zotero
    • 打开 devtool
    • 监听 src/**addon/**
      • 如果 src/** 有更改,则运行esbuild并reload
      • 如果 addon/** 有更改,则构建插件(开发模式下)
  • stop:终止 Zotero 进程(和 server)

  • 当 server 终止时,zotero 会被自动结束

  • 当 zotero 被终止时,server 也会终止

  • 未实现:当 启动server时,如果已经存在了正在运行的zotero实例,则zotero关闭时,server不会自动终止;(server终止时仍会自动结束zotero)

  • 重构后,性能得到极大提高,当仅 src 变化时,可以在毫秒级完成构建,当 addon修改时,可以在0.3s内完成构建。重构前,无论如何都是完整构建,耗时 0.6s。(以 Linter for Zotero 插件为基准进行测试)

Release XPI via GitHub Action

说明:
1702269647714

release-it 本地配置
1702269883743

release-it action 配置
1702269908502

本地运行 release 截图:手动选择版本、推送提交和标签到 GitHub,(不上传xpi)
1702269957273

当有标签提交时,GitHub Action 被触发,build xpi,并将 xpi 上传到 GitHub Release:
1702269997510

@northword northword marked this pull request as ready for review December 10, 2023 14:01
@volatile-static
Copy link
Contributor

建议补充点注释?有点看不懂

@northword
Copy link
Collaborator Author

northword commented Dec 11, 2023

建议补充点注释?有点看不懂

更新了 README 和 PR body

补充说明:本地运行npm run release,release-it 读取本地配置 .release-it.json,在这个配置文件中,设置了 github.release=false,即正常 bump version,build(为了更新 update.json 并确保 CI 端可以成功构建),commit (update.json 和 package.json),tag(v${version}),push,结束。

Action 收到 v${version} 模式的 git.tags 时,触发 release.yml,通过命令行参数覆盖 .release-it.json 中的配置,命令行中设置

  • --no-increment:关闭 bump version
  • --no-git:关闭 git 相关操作 (commit tag push)
  • --github.release:启用发布到 GitHub
  • --ci:CI 模式,不交互,直接按配置文件和默认值运行
  • --verbose:显示输出

好处是,release-it 不在本地发布到 GitHub 后,可以不用在本地设置 GITHUB_TOKEN (Action 上运行时会自动生成一个 GITHUB_TOKEN,workflow 中设置了 contents: write 让他有权限操作 release),也可以更快一些;
坏处是,没法处理本地依赖等。

CC @volatile-static

@northword northword changed the title Performance: refactor development scripts refactor: rebuild development scripts and release workflow Dec 11, 2023
scripts/start.mjs Outdated Show resolved Hide resolved
@northword
Copy link
Collaborator Author

done ——

  • 处理了 reload 时 server 因无法写入日志退出的问题
  • 移除了 update-beta.json,用户首次发布 prerelease 时再生成,并在 readme 添加说明

@windingwind windingwind merged commit fb9109d into windingwind:main Dec 12, 2023
@northword northword deleted the refactor branch December 12, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants