掘金 后端 ( ) • 2024-06-29 11:11

正常编译为跨平台结果就像上面的,有mac/windows/linux的安装程序,直接下载就可以安装使用,我的这个livebox桌面端仓库地址:GitHub - Sjj1024/LiveBox: livebox,里面有编译文件可以参考。今天主要讲一下遇到的问题。

官方文档的坑

按照tauri官方文档的说明:跨平台编译 | Tauri Apps,其实只要在项目的根目录创建一个 .github/workflows/build.yml 文件,然后添加内容就可以了:

但是这里需要注意:

这里cache: 'yarn' # Set this to npm, yarn or pnpm.是有问题的,不能直接使用

修改为pnpm后,就会报错:

Run actions/setup-node@v3

13Attempt to resolve LTS alias from manifest...

14Found in cache @ /Users/runner/hostedtoolcache/node/20.15.0/arm64

Environment details

19Error: Unable to locate executable file: pnpm. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

Install frontend dependencies

Build the app

Post Sync node version and setup cache

Post Rust cache

Post Checkout repository

Complete job

add tag · Sjj1024/LiveBox@07414e2 

这里需要修改为下面的逻辑:完成可用的内容

name: Release
on:
    push:
        tags:
            - 'v*'
    workflow_dispatch:

jobs:
    release:
        permissions:
            contents: write
        strategy:
            fail-fast: false
            matrix:
                platform: [macos-latest, ubuntu-20.04, windows-latest]
        runs-on: ${{ matrix.platform }}

        steps:
            - name: Checkout repository
              uses: actions/checkout@v3

            - name: Install dependencies (ubuntu only)
              if: matrix.platform == 'ubuntu-20.04'
              # You can remove libayatana-appindicator3-dev if you don't use the system tray feature.
              run: |
                  sudo apt-get update
                  sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev

            - name: Rust setup
              uses: dtolnay/rust-toolchain@stable

            - name: Rust cache
              uses: swatinem/rust-cache@v2
              with:
                  workspaces: './src-tauri -> target'

            - name: Sync node version and setup cache
              uses: actions/setup-node@v4
              with:
                  node-version: 20

            - name: Install PNPM
              run: npm i -g pnpm

            - name: Install frontend dependencies
              # If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
              run: pnpm install # Change this to npm, yarn or pnpm.

            - name: Build the app
              uses: tauri-apps/tauri-action@v0

              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              with:
                  tagName: ${{ github.ref_name }} # This only works if your workflow triggers on new tags.
                  releaseName: 'App Name v__VERSION__' # tauri-action replaces \_\_VERSION\_\_ with the app version.
                  releaseBody: 'See the assets to download and install this version.'
                  releaseDraft: true
                  prerelease: false

如果你使用的是npm的话,应该没有问题,但是我使用的pnpm,以为修改为npm就可以正常用了,但是依然报错:

Run actions/setup-node@v3
Attempt to resolve LTS alias from manifest...
Found in cache @ /Users/runner/hostedtoolcache/node/20.14.0/arm64
Environment details
/Users/runner/hostedtoolcache/node/20.14.0/arm64/bin/npm config get cache
/Users/runner/.npm
Error: Dependencies lock file is not found in /Users/runner/work/LiveBox/LiveBox. Supported file patterns: package-lock.json,npm-shrinkwrap.json,yarn.lock

这里就是说没有得到lock file,因为我使用pnpm,只会有pnpm-lock.yaml文件,所以只能使用pnpm安装。

其中文件里面的 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 是每个仓库都会默认包含的一个action环境变量,不用单独添加,可以给这个环境变量添加不同的权限:GitHub 会自动为每个运行的工作流发布 GitHub 令牌,而不需要进一步配置,这意味着不存在秘密泄漏的风险。但是,该令牌默认只具有读权限,并且在运行工作流时可能会出现“资源无法通过集成访问”错误。如果发生这种情况,您可能需要向此标记添加写权限。要做到这一点,进入您的 GitHub 项目设置,然后选择操作,向下滚动到“工作流权限”,并检查“读取和写入权限”。

mac安装包打开遇到的问题

提示:已损坏,无法打开,你应该将它移到废纸篓

提示:无法打开 “应用程序”,因为无法验证开发者。macOS 无法验证此 App 不包含恶意软件 

解决办法:

打开 “系统偏好设置…” - “安全性与隐私”,“通用” 标签页,如图勾选:允许 “任何来源” 下载的 App 运行:

如果还是报错,就可以祭出大招了,给文件赋予安全性设置。在终端粘贴复制输入命令:

sudo xattr -r -d com.apple.quarantine

然后打开 Finder进入 “应用程序” 目录,找到该软件,将其图标拖到终端窗口,获取到文件路径,最终拼接为以下命令:

sudo xattr -r -d com.apple.quarantine /Applications/livebox.app

然后执行命令,输入系统密码即可。完成上述步骤即可完美运行应用。

输入一个直播间地址试试:完美