优化 vcpkg 缓存机制及依赖管理配置 #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Windows Build | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: ["v*"] | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| env: | |
| BUILD_CONFIGURATION: Release | |
| INSTALL_DIR: ${{ github.workspace }}\install | |
| ZIP_NAME: MHY_Scanner_${{ github.ref_name }}.zip | |
| VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg-cache,readwrite | |
| permissions: | |
| contents: write | |
| actions: write | |
| jobs: | |
| build: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install Qt6 | |
| uses: jurplel/install-qt-action@v4 | |
| with: | |
| version: '6.8.0' | |
| host: 'windows' | |
| target: 'desktop' | |
| arch: 'win64_msvc2022_64' | |
| cache: true | |
| - name: Restore cache | |
| id: restore-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: ${{ github.workspace }}/vcpkg-cache | |
| key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} | |
| restore-keys: | | |
| vcpkg-${{ runner.os }}- | |
| - name: Setup vcpkg | |
| uses: lukka/run-vcpkg@v11 | |
| - name: Configure CMake | |
| run: | | |
| cmake -B build ` | |
| -DCMAKE_BUILD_TYPE=${{ env.BUILD_CONFIGURATION }} ` | |
| -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}\scripts\buildsystems\vcpkg.cmake ` | |
| -DVCPKG_TARGET_TRIPLET=x64-windows-static-md ` | |
| -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\install ` | |
| -DUNIT_TESTS=OFF ` | |
| -DDEV=OFF | |
| - name: Build | |
| run: | | |
| cmake --build build --config ${{ env.BUILD_CONFIGURATION }} --parallel | |
| - name: Install | |
| run: | | |
| cmake --install build --config ${{ env.BUILD_CONFIGURATION }} | |
| - name: Create ZIP | |
| run: | | |
| powershell Compress-Archive -Path "${{ env.INSTALL_DIR }}\*" -DestinationPath "${{ github.workspace }}\${{ env.ZIP_NAME }}" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ZIP_NAME }} | |
| path: ${{ github.workspace }}\${{ env.ZIP_NAME }} | |
| retention-days: 5 | |
| - name: Save cache | |
| if: steps.restore-cache.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: ${{ github.workspace }}/vcpkg-cache | |
| key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} | |
| - name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: ${{ github.ref_name }} | |
| files: ${{ github.workspace }}\${{ env.ZIP_NAME }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |