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

您所在的位置:网站首页 0x80004002错误原因 Tauri开发的程序,使用github action快速跨平台编译并发布流程,包括Windows、mac、m芯片、linux等,以及常见报错

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

2023-03-22 21:28| 来源: 网络整理| 查看: 265

背景

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

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

GitHub Action

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

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

使用 Action 创建 release.yml

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

# 可选,将显示在 GitHub 存储库的“操作”选项卡中的工作流名称 name: Release CI # 指定此工作流的触发器 on: push: # 匹配特定标签 (refs/tags) tags: - 'v*' # 推送事件匹配 v*, 例如 v1.0,v20.15.10 等来触发工作流 # 需要运行的作业组合 jobs: # 任务:创建 release 版本 create-release: runs-on: ubuntu-latest outputs: RELEASE_UPLOAD_ID: ${{ steps.create_release.outputs.id }} steps: - uses: actions/checkout@v2 # 查询版本号(tag) - name: Query version number id: get_version shell: bash run: | echo "using version tag ${GITHUB_REF:10}" echo ::set-output name=version::"${GITHUB_REF:10}" # 根据查询到的版本号创建 release - name: Create Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: '${{ steps.get_version.outputs.VERSION }}' release_name: 'app ${{ steps.get_version.outputs.VERSION }}' body: 'See the assets to download this version and install.' # 编译 Tauri build-tauri: needs: create-release strategy: fail-fast: false matrix: platform: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 # 安装 Node.js - name: Setup node uses: actions/setup-node@v1 with: node-version: 16 # 安装 Rust - name: Install Rust stable uses: actions-rs/toolchain@v1 with: toolchain: stable # 使用 Rust 缓存,加快安装速度 - uses: Swatinem/rust-cache@v1 - name: install dependencies (ubuntu only) if: matrix.platform == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf # 可选,如果需要将 Rust 编译为 wasm,则安装 wasm-pack - uses: jetli/[email protected] with: # Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest') version: v0.9.1 # 可选,如果需要使用 rsw 构建 wasm,则安装 rsw - name: Install rsw run: cargo install rsw # 获取 yarn 缓存路径 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn config get cacheFolder)" # 使用 yarn 缓存 - name: Yarn cache uses: actions/cache@v2 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- # 安装依赖执行构建,以及推送 github release - name: Install app dependencies and build it # 这里的pubhome要修改为你package.json里面配置的编译命令 run: yarn && yarn pubhome - uses: tauri-apps/[email protected] env: GITHUB_TOKEN: ${{ secrets.TOKEN }} with: releaseId: ${{ needs.create-release.outputs.RELEASE_UPLOAD_ID }} 触发 Action

使用 GitHub Tag 来触发 Action

# 创建 tag git tag v0.1.0 # 推送 tag 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 " > [email protected]" has unmet peer dependency "webpack@^5.0.0".

14warning " > [email protected]" 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/[email protected]就好了

$ 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编译失败 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3