build-app.yaml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. name: 编译
  2. on:
  3. workflow_dispatch:
  4. push:
  5. paths:
  6. - '.github/workflows/build-app.yaml'
  7. - 'client/**'
  8. - 'src/**'
  9. concurrency:
  10. group: "build"
  11. cancel-in-progress: true
  12. permissions:
  13. contents: read
  14. id-token: write
  15. jobs:
  16. get-version:
  17. name: 获取版本号
  18. runs-on: ubuntu-latest
  19. outputs:
  20. VERSION: ${{ steps.get-yaa-version.outputs.version }}
  21. steps:
  22. - name: 检出仓库
  23. uses: actions/checkout@v4
  24. - name: 获取 yaa 的版本号
  25. id: get-yaa-version
  26. run: |
  27. YAA_VERSION=$(grep '^version' ./Cargo.toml | awk -F= '{print $2}' | tr -d '" ')
  28. echo "$YAA_VERSION"
  29. build-app:
  30. name: 编译(${{ matrix.os }})
  31. runs-on: ${{ matrix.os }}
  32. env:
  33. HTML_PATH: 'client/index.html'
  34. NAME: 'yaa'
  35. ICON: 'assets/yaa_512.png'
  36. INSTALLER_LANGUAGE: zh-CN
  37. VERSION: ${{ needs.get-version.outputs.VERSION }}
  38. TARGETS: 'appimage'
  39. strategy:
  40. matrix:
  41. build: [linux, macos, windows]
  42. include:
  43. - build: linux
  44. os: ubuntu-latest
  45. - build: windows
  46. os: windows-latest
  47. - build: macos
  48. os: macos-latest
  49. steps:
  50. - name: 检出仓库
  51. uses: actions/checkout@v4
  52. - name: 安装 Node.js
  53. uses: actions/setup-node@v3
  54. with:
  55. node-version: 18
  56. - name: 为 ubuntu-latest 安装 Rust
  57. if: matrix.os == 'ubuntu-latest'
  58. uses: dtolnay/rust-toolchain@stable
  59. with:
  60. toolchain: stable
  61. target: x86_64-unknown-linux-musl
  62. - name: 为 windows-latest 安装 Rust
  63. if: matrix.os == 'windows-latest'
  64. uses: dtolnay/rust-toolchain@stable
  65. with:
  66. toolchain: stable-x86_64-msvc
  67. target: x86_64-pc-windows-msvc
  68. - name: 为 macos-latest 安装 Rust
  69. if: matrix.os == 'macos-latest'
  70. uses: dtolnay/rust-toolchain@stable
  71. with:
  72. toolchain: stable
  73. target: x86_64-apple-darwin
  74. - name: 安装依赖(仅 Ubuntu 需)
  75. if: matrix.os == 'ubuntu-24.04'
  76. uses: awalsh128/[email protected]
  77. with:
  78. packages: libsoup3.0-dev libdbus-1-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra
  79. version: 1.1
  80. - name: 安装 pake-cli
  81. run: |
  82. npm install pake-cli
  83. - name: 恢复 Rust 缓存
  84. uses: actions/cache/restore@v3
  85. id: cache_store
  86. with:
  87. path: |
  88. ~/.cargo/bin/
  89. ~/.cargo/registry/index/
  90. ~/.cargo/registry/cache/
  91. ~/.cargo/git/db/
  92. key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
  93. - name: 安装依赖
  94. run: |
  95. npm install -g shelljs
  96. npm install -g axios
  97. - name: 安装 Pake
  98. run: |
  99. npm install -g pake-cli && pake --version
  100. - name: 编译服务端
  101. run: |
  102. cargo build --release
  103. - name: 编译客户端
  104. run: |
  105. mkdir -p target/client
  106. cd target/client
  107. pake ../../${{ env.HTML_PATH }} \
  108. --name ${{ env.NAME }} \
  109. --icon ../../${{ env.ICON }} \
  110. --installer-language ${{ env.INSTALLER_LANGUAGE }} \
  111. --app-version ${{ env.VERSION }} \
  112. --targets ${{ env.TARGETS }} \
  113. --use-local-file
  114. cd ../..
  115. shell: bash
  116. - name: 收集包
  117. run: |
  118. mkdir -p yaa-${{ matrix.build }}
  119. cp -r node_modules/pake-cli/output/* yaa-${{ matrix.build }}
  120. if [ "${{ matrix.os }}" == "windows-latest" ]; then
  121. cp target/release/yaa.exe yaa-${{ matrix.build }}/
  122. else
  123. cp target/release/yaa yaa-${{ matrix.build }}/
  124. fi
  125. shell: bash
  126. - name: 上传包
  127. uses: actions/upload-artifact@v4
  128. with:
  129. name: yaa-${{ matrix.os }}.zip
  130. path: yaa-${{ matrix.build }}/**/*
  131. retention-days: 3
  132. - name: 保存 Rust 缓存
  133. uses: actions/cache/save@v3
  134. if: steps.cache_store.outputs.cache-hit != 'true'
  135. with:
  136. path: |
  137. ~/.cargo/bin/
  138. ~/.cargo/registry/index/
  139. ~/.cargo/registry/cache/
  140. ~/.cargo/git/db/
  141. key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}