当前位置:   article > 正文

tauri使用github进行打包和自动更新教程_tauri github update

tauri github update

之前的几篇文章介绍了tauri的基本安装,本地打包等方法。本文将接着就前几篇文章进行继续阐述,着重介绍tauri介绍tauri以github为后台服务进行打包、更新,以及tauri配置启动图。

一、tauri使用github进行打包

1、首先在项目的根目录下创建生成.github>workflows>release.yml文件:

release.yml文件内容:

  1. name: Release
  2. on:
  3. push:
  4. tags:
  5. - 'v*'
  6. jobs:
  7. release:
  8. strategy:
  9. fail-fast: false
  10. matrix:
  11. platform: [macos-latest, ubuntu-latest, windows-latest]
  12. runs-on: ${{ matrix.platform }}
  13. steps:
  14. - name: Checkout repository
  15. uses: actions/checkout@v2
  16. - name: Install Node
  17. uses: actions/setup-node@v1
  18. with:
  19. node-version: 16
  20. - name: Install Rust stable
  21. uses: actions-rs/toolchain@v1
  22. with:
  23. toolchain: stable
  24. - name: Install Dependencies (ubuntu only)
  25. if: matrix.platform == 'ubuntu-latest'
  26. run: |
  27. sudo apt-get update
  28. sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
  29. - run: yarn
  30. - name: Build Tauri
  31. uses: tauri-apps/tauri-action@v0
  32. env:
  33. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  34. TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
  35. TAURI_KEY_PASSWORD: '' TAURI_KEY_PASSWORD: "" # 密钥的加密文本,与seecrts时输入的密码一致即可。如果未输入密码,则此处留空,如果输入了密码,则也需要添加到 secrets 中,然后使用 ${{ secrets.TAURI_PRIVATE_KEY_PASSWORD }} 这种形式
  36. with:
  37. tagName: v__VERSION__
  38. releaseName: v__VERSION__
  39. update:
  40. needs: release
  41. runs-on: macos-latest
  42. steps:
  43. - name: Checkout repository
  44. uses: actions/checkout@v2
  45. - name: Install Node
  46. uses: actions/setup-node@v1
  47. with:
  48. node-version: 16
  49. - run: yarn
  50. - name: Create Update
  51. run: yarn update
  52. env:
  53. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2、生成tauri公、私钥

全局安装tauri

  1. yarn global add @tauri-apps/cli

or 

cnpm install  @tauri-apps/cli -g

生成公私钥命令:

tauri signer generate -w ~/.tauri/myapp.key

 注释 :如果设置密码的话,需要记住密码。

如果生成了公私钥就要可以进行签名打包,并进行更新。但是需要进行配置以后才能使用。

在项目当中的tauri.conf.json当中配置公钥和更新路径

 然后在github项目环境中配置私钥:

 在本地项目当中创建文件scripts>update.mjs,文件内容:

  1. // @ts-nocheck
  2. import fetch from 'node-fetch';
  3. import { getOctokit, context } from '@actions/github';
  4. const UPDATE_TAG_NAME = 'updater';
  5. const UPDATE_FILE_NAME = 'update.json';
  6. const getSignature = async (url) => {
  7. const response = await fetch(url, {
  8. method: 'GET',
  9. headers: { 'Content-Type': 'application/octet-stream' }
  10. });
  11. return response.text();
  12. };
  13. const updateData = {
  14. name: '',
  15. pub_date: new Date().toISOString(),
  16. platforms: {
  17. win64: { signature: '', url: '' },
  18. linux: { signature: '', url: '' },
  19. darwin: { signature: '', url: '' },
  20. 'linux-x86_64': { signature: '', url: '' },
  21. 'windows-x86_64': { signature: '', url: '' }
  22. }
  23. };
  24. const octokit = getOctokit(process.env.GITHUB_TOKEN);
  25. const options = { owner: context.repo.owner, repo: context.repo.repo };
  26. const { data: release } = await octokit.rest.repos.getLatestRelease(options);
  27. updateData.name = release.tag_name;
  28. // eslint-disable-next-line camelcase
  29. for (const { name, browser_download_url } of release.assets) {
  30. if (name.endsWith('.msi.zip')) {
  31. // eslint-disable-next-line camelcase
  32. updateData.platforms.win64.url = browser_download_url;
  33. // eslint-disable-next-line camelcase
  34. updateData.platforms['windows-x86_64'].url = browser_download_url;
  35. } else if (name.endsWith('.msi.zip.sig')) {
  36. // eslint-disable-next-line no-await-in-loop
  37. const signature = await getSignature(browser_download_url);
  38. updateData.platforms.win64.signature = signature;
  39. updateData.platforms['windows-x86_64'].signature = signature;
  40. } else if (name.endsWith('.app.tar.gz')) {
  41. // eslint-disable-next-line camelcase
  42. updateData.platforms.darwin.url = browser_download_url;
  43. } else if (name.endsWith('.app.tar.gz.sig')) {
  44. // eslint-disable-next-line no-await-in-loop
  45. const signature = await getSignature(browser_download_url);
  46. updateData.platforms.darwin.signature = signature;
  47. } else if (name.endsWith('.AppImage.tar.gz')) {
  48. // eslint-disable-next-line camelcase
  49. updateData.platforms.linux.url = browser_download_url;
  50. // eslint-disable-next-line camelcase
  51. updateData.platforms['linux-x86_64'].url = browser_download_url;
  52. } else if (name.endsWith('.AppImage.tar.gz.sig')) {
  53. // eslint-disable-next-line no-await-in-loop
  54. const signature = await getSignature(browser_download_url);
  55. updateData.platforms.linux.signature = signature;
  56. updateData.platforms['linux-x86_64'].signature = signature;
  57. }
  58. }
  59. const { data: updater } = await octokit.rest.repos.getReleaseByTag({
  60. ...options,
  61. tag: UPDATE_TAG_NAME
  62. });
  63. for (const { id, name } of updater.assets) {
  64. if (name === UPDATE_FILE_NAME) {
  65. // eslint-disable-next-line no-await-in-loop
  66. await octokit.rest.repos.deleteReleaseAsset({ ...options, asset_id: id });
  67. break;
  68. }
  69. }
  70. await octokit.rest.repos.uploadReleaseAsset({
  71. ...options,
  72. release_id: updater.id,
  73. name: UPDATE_FILE_NAME,
  74. data: JSON.stringify(updateData)
  75. });

配置完成后,提交代码到github代码仓库。

二、为github项目打tag

在update.mjs文件中,有两个常量:

  1. const UPDATE_TAG_NAME = 'updater';
  2. const UPDATE_FILE_NAME = 'update.json';

这是为了拼接更新路径而设置,因此需要在github项目下生成一个update.json.这就需要在项目下首先打上一个updater的tag。

  1. git tag updater
  2. git push --tags

 然后release这个updater tag:

 然后再提交版本tag进行打包:

  1. git tag v1.0.0
  2. git push tags

然后github的action就进入打包状态,完成后的结果

最终生成的安装包就是:

 

 这个时候在访问tauri.conf.mjs文件当中的endpoints字段的链接,就会出现下载update.json的情况。至此,github的打包更新就会完成。

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

闽ICP备14008679号