当前位置:   article > 正文

Tauri开发的程序,使用github action快速跨平台编译并发布流程,包括Windows、mac、m芯片、linux等,以及常见报错_tauri github action

tauri github action

背景

Tauri 严重依赖原生库和工具链,因此目前无法在某一平台实现交叉编译。最佳选择是使用托管在 GitHub ActionAzure PipelinesGitLab 或其他选项上的 CI/CD 管道进行编译。管道可以同时为每个平台运行编译,使编译和发布过程更加容易。

为了便于设置,官方目前提供 Tauri Action。这是一个 GitHub Action,可在所有支持的平台上运行,编译软件,生成应用程序安装包,并将发布到 GitHub Releases

GitHub Action

从构思到生产,自动化工作流程

利用 GitHub Actions,在你的仓库中自动化、定制和执行你的软件开发工作流程。你可以发现、创建和共享操作,以执行你想要的任何工作,包括 CI/CD,并在一个完全定制的工作流程中组合操作。

使用 Action

创建 release.yml

在项目根路径下创建 .github/workflows 目录,在 .github/workflows 下创建 release.yml(文件名自定义) 文件。将以下内容复制到文件中:

  1. # 可选,将显示在 GitHub 存储库的“操作”选项卡中的工作流名称
  2. name: Release CI
  3. # 指定此工作流的触发器
  4. on:
  5. push:
  6. # 匹配特定标签 (refs/tags)
  7. tags:
  8. - 'v*' # 推送事件匹配 v*, 例如 v1.0,v20.15.10 等来触发工作流
  9. # 需要运行的作业组合
  10. jobs:
  11. # 任务:创建 release 版本
  12. create-release:
  13. runs-on: ubuntu-latest
  14. outputs:
  15. RELEASE_UPLOAD_ID: ${{ steps.create_release.outputs.id }}
  16. steps:
  17. - uses: actions/checkout@v2
  18. # 查询版本号(tag)
  19. - name: Query version number
  20. id: get_version
  21. shell: bash
  22. run: |
  23. echo "using version tag ${GITHUB_REF:10}"
  24. echo ::set-output name=version::"${GITHUB_REF:10}"
  25. # 根据查询到的版本号创建 release
  26. - name: Create Release
  27. id: create_release
  28. uses: actions/create-release@v1
  29. env:
  30. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  31. with:
  32. tag_name: '${{ steps.get_version.outputs.VERSION }}'
  33. release_name: 'app ${{ steps.get_version.outputs.VERSION }}'
  34. body: 'See the assets to download this version and install.'
  35. # 编译 Tauri
  36. build-tauri:
  37. needs: create-release
  38. strategy:
  39. fail-fast: false
  40. matrix:
  41. platform: [macos-latest, ubuntu-latest, windows-latest]
  42. runs-on: ${{ matrix.platform }}
  43. steps:
  44. - uses: actions/checkout@v2
  45. # 安装 Node.js
  46. - name: Setup node
  47. uses: actions/setup-node@v1
  48. with:
  49. node-version: 16
  50. # 安装 Rust
  51. - name: Install Rust stable
  52. uses: actions-rs/toolchain@v1
  53. with:
  54. toolchain: stable
  55. # 使用 Rust 缓存,加快安装速度
  56. - uses: Swatinem/rust-cache@v1
  57. - name: install dependencies (ubuntu only)
  58. if: matrix.platform == 'ubuntu-latest'
  59. run: |
  60. sudo apt-get update
  61. sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
  62. # 可选,如果需要将 Rust 编译为 wasm,则安装 wasm-pack
  63. - uses: jetli/wasm-pack-action@v0.3.0
  64. with:
  65. # Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest')
  66. version: v0.9.1
  67. # 可选,如果需要使用 rsw 构建 wasm,则安装 rsw
  68. - name: Install rsw
  69. run: cargo install rsw
  70. # 获取 yarn 缓存路径
  71. - name: Get yarn cache directory path
  72. id: yarn-cache-dir-path
  73. run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
  74. # 使用 yarn 缓存
  75. - name: Yarn cache
  76. uses: actions/cache@v2
  77. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  78. with:
  79. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  80. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  81. restore-keys: |
  82. ${{ runner.os }}-yarn-
  83. # 安装依赖执行构建,以及推送 github release
  84. - name: Install app dependencies and build it
  85. # 这里的pubhome要修改为你package.json里面配置的编译命令
  86. run: yarn && yarn pubhome
  87. - uses: tauri-apps/tauri-action@v0.3
  88. env:
  89. GITHUB_TOKEN: ${{ secrets.TOKEN }}
  90. with:
  91. releaseId: ${{ needs.create-release.outputs.RELEASE_UPLOAD_ID }}

触发 Action

使用 GitHub Tag 来触发 Action

  1. # 创建 tag
  2. git tag v0.1.0
  3. # 推送 tag
  4. git push --tag

 然后到工作流页面:

然后到releases页面就可以看到下载包:

注意注意!!!!!常见报错原因

1.yaml文件里面的配置要正确,要和package.json结合使用

比如你的package.json里面的脚本长这样,其中前四个是tauri脚手架生成项目后自带的,千万不要试图修改,不然会报很多错误,最后一个pubhome是我自己编写,你也可以换成你自己写的

但是换完之后,就要同步修改yarm里面的配置:

如果你试图修改了前四个,或者没有更换最后一个为你自己的,你会遇到一下报错:

这个错误是因为我在使用pubhome之前,是publish这个词,结果和yarn关键词冲突导致的error No token found and can't prompt for login when running with --non-interactive.

[1/4] Resolving packages...

11[2/4] Fetching packages...

12[3/4] Linking dependencies...

13warning " > sass-loader@13.2.0" has unmet peer dependency "webpack@^5.0.0".

14warning " > style-loader@3.3.2" has unmet peer dependency "webpack@^5.0.0".

15[4/4] Building fresh packages...

16Done in 61.95s.

17yarn publish v1.22.19

18warning package.json: No license field

19warning package.json: No license field

20[1/4] Bumping version...

21info Current version: 0.0.0

22[2/4] Logging in...

23error No token found and can't prompt for login when running with --non-interactive.

24info Visit yarn publish | Yarn for documentation about this command.

25Error: Process completed with exit code 1.

还有这个错误:error: unexpected argument 'build' found,是因为我之前的package.json里面修改了官方的tauri命令,原来是"tauri": "tauri",我修改为了"tauri": "tauri dev" 导致的

running yarn [ 'tauri', 'build' ]

16yarn run v1.22.19

17warning package.json: No license field

18$ tauri dev build

19 Running BeforeDevCommand (`yarn dev`)

20warning package.json: No license field

21$ vite

22

23 VITE v4.2.0 ready in 662 ms

24

25 ➜ Local: http://localhost:1420/

26 ➜ Network: use --host to expose

27error: unexpected argument 'build' found

28

29Usage: cargo.exe build [OPTIONS]

30

31For more information, try '--help'.

32 Info Watching D:\a\Vue3TsHome\Vue3TsHome\src-tauri for changes...

33error Command failed with exit code 1.

34info Visit yarn run | Yarn for documentation about this command.

35Error: Command failed with exit code 1: yarn tauri build

还有这个错误:No artifacts were found.是因为yaml文件里面- uses: tauri-apps/tauri-action@v0导致的,修改为官方最新的uses: tauri-apps/tauri-action@v0.3就好了

$ vue-tsc --noEmit && vite build

20vite v4.1.4 building for production...

21transforming...

22✓ 1049 modules transformed.

23rendering chunks...

24computing gzip size...

25dist/index.html 0.46 kB

26dist/assets/index-d56eeb64.css 600.06 kB │ gzip: 70.17 kB

27dist/assets/index-e1747f8c.js 1,154.01 kB │ gzip: 371.05 kB

28

29(!) Some chunks are larger than 500 kBs after minification. Consider:

30- Using dynamic import() to code-split the application

31- Use build.rollupOptions.output.manualChunks to improve chunking: Configuration Options | Rollup

32- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.

33 Compiling tauri_some v0.0.0 (/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri)

34 Finished release [optimized] target(s) in 39.61s

35 Bundling 1024_0.0.1_amd64.deb (/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/deb/1024_0.0.1_amd64.deb)

36 Bundling 1024_0.0.1_amd64.AppImage (/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/appimage/1024_0.0.1_amd64.AppImage)

37 Finished 2 bundles at:

38 /home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/deb/1024_0.0.1_amd64.deb

39 /home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/appimage/1024_0.0.1_amd64.AppImage

40

41Done in 145.47s.

42Expected artifacts paths:

43/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/deb/102_0.0.1_amd64.deb

44/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/appimage/_0.0.1_amd64.AppImage

45/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/appimage/_0.0.1_amd64.AppImage.tar.gz

46/home/runner/work/Vue3TsHome/Vue3TsHome/src-tauri/target/release/bundle/appimage/_0.0.1_amd64.AppImage.tar.gz.sig

47Error: No artifacts were found.

上面这个错误,大概率只会导致linux编译失败 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/795117
推荐阅读
相关标签
  

闽ICP备14008679号