build-server.yaml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. name: 编译服务端
  2. on:
  3. workflow_dispatch:
  4. push:
  5. paths:
  6. - '.github/workflows/build-server.yaml'
  7. - 'src/**'
  8. concurrency:
  9. group: "server"
  10. cancel-in-progress: true
  11. permissions:
  12. contents: read
  13. id-token: write
  14. jobs:
  15. build-server:
  16. name: 编译服务端(${{ matrix.os }})
  17. runs-on: ${{ matrix.os }}
  18. strategy:
  19. matrix:
  20. build: [linux, macos, windows]
  21. include:
  22. - build: linux
  23. os: ubuntu-latest
  24. - build: windows
  25. os: windows-latest
  26. - build: macos
  27. os: macos-latest
  28. steps:
  29. - name: 检出仓库
  30. uses: actions/checkout@v4
  31. - name: 为 ubuntu-latest 安装 Rust
  32. if: matrix.os == 'ubuntu-latest'
  33. uses: dtolnay/rust-toolchain@stable
  34. with:
  35. toolchain: stable
  36. target: x86_64-unknown-linux-musl
  37. - name: 为 windows-latest 安装 Rust
  38. if: matrix.os == 'windows-latest'
  39. uses: dtolnay/rust-toolchain@stable
  40. with:
  41. toolchain: stable-x86_64-msvc
  42. target: x86_64-pc-windows-msvc
  43. - name: 为 macos-latest 安装 Rust
  44. if: matrix.os == 'macos-latest'
  45. uses: dtolnay/rust-toolchain@stable
  46. with:
  47. toolchain: stable
  48. target: x86_64-apple-darwin
  49. - name: 恢复 Rust 缓存
  50. uses: actions/cache/restore@v3
  51. id: cache_store
  52. with:
  53. path: |
  54. ~/.cargo/bin/
  55. ~/.cargo/registry/index/
  56. ~/.cargo/registry/cache/
  57. ~/.cargo/git/db/
  58. key: ${{ matrix.os }}-cargo-${{ hashFiles('./Cargo.lock') }}
  59. - name: 编译服务端
  60. run: |
  61. cargo build --release
  62. - name: 收集包
  63. run: |
  64. mkdir -p yaa_server_${{ matrix.build }}
  65. if [ "${{ matrix.os }}" == "windows-latest" ]; then
  66. cp target/release/yaa.exe yaa_server_${{ matrix.build }}/
  67. else
  68. cp target/release/yaa yaa_server_${{ matrix.build }}/
  69. fi
  70. shell: bash
  71. - name: 上传包
  72. uses: actions/upload-artifact@v4
  73. with:
  74. name: yaa_server_${{ matrix.os }}.zip
  75. path: yaa_server_${{ matrix.build }}/**/*
  76. retention-days: 3
  77. - name: 保存 Rust 缓存
  78. uses: actions/cache/save@v3
  79. if: steps.cache_store.outputs.cache-hit != 'true'
  80. with:
  81. path: |
  82. ~/.cargo/bin/
  83. ~/.cargo/registry/index/
  84. ~/.cargo/registry/cache/
  85. ~/.cargo/git/db/
  86. key: ${{ matrix.os }}-cargo-${{ hashFiles('./Cargo.lock') }}