| 1 | name: MSVC |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [master] |
| 6 | pull_request: |
| 7 | branches: [master] |
| 8 | |
| 9 | concurrency: |
| 10 | group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | cancel-in-progress: true |
| 12 | |
| 13 | jobs: |
| 14 | build-and-test: |
| 15 | permissions: |
| 16 | contents: read |
| 17 | runs-on: windows-2022 |
| 18 | strategy: |
| 19 | fail-fast: false |
| 20 | matrix: |
| 21 | include: |
| 22 | - arch: amd64 |
| 23 | cmake_arch: x64 |
| 24 | package_suffix: x64 |
| 25 | can_run_binaries: true |
| 26 | - arch: amd64_x86 |
| 27 | cmake_arch: Win32 |
| 28 | package_suffix: x86 |
| 29 | can_run_binaries: true |
| 30 | - arch: amd64_arm64 |
| 31 | cmake_arch: ARM64 |
| 32 | package_suffix: arm64 |
| 33 | can_run_binaries: false |
| 34 | steps: |
| 35 | - uses: actions/checkout@v5 |
| 36 | with: |
| 37 | fetch-depth: 0 |
| 38 | - name: Compute version |
| 39 | id: version |
| 40 | shell: bash |
| 41 | run: | |
| 42 | VERSION=$(bash scripts/compute-version.sh) |
| 43 | echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 44 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 45 | echo "Computed version: $VERSION" |
| 46 | - uses: ilammy/msvc-dev-cmd@v1 |
| 47 | with: |
| 48 | arch: ${{ matrix.arch }} |
| 49 | |
| 50 | - name: Build release package tree |
| 51 | if: ${{ matrix.can_run_binaries }} |
| 52 | shell: pwsh |
| 53 | run: | |
| 54 | cmake -S . -B build-release ` |
| 55 | -A "${{ matrix.cmake_arch }}" ` |
| 56 | -DCMAKE_BUILD_TYPE=Release ` |
| 57 | -DBUILD_OPENCC_JIEBA_PLUGIN=ON ` |
| 58 | -DCMAKE_INSTALL_PREFIX:PATH="${{ github.workspace }}\dist\opencc-msvc-${{ matrix.package_suffix }}" |
| 59 | cmake --build build-release --config Release --target install |
| 60 | |
| 61 | - name: Build ARM64 compile-only targets |
| 62 | if: ${{ !matrix.can_run_binaries }} |
| 63 | shell: pwsh |
| 64 | run: | |
| 65 | cmake -S . -B build-release ` |
| 66 | -A "${{ matrix.cmake_arch }}" ` |
| 67 | -DCMAKE_BUILD_TYPE=Release ` |
| 68 | -DBUILD_OPENCC_JIEBA_PLUGIN=ON |
| 69 | cmake --build build-release --config Release --target libopencc opencc opencc_dict opencc_phrase_extract opencc_jieba |
| 70 | |
| 71 | - name: Build and test debug |
| 72 | if: ${{ matrix.can_run_binaries }} |
| 73 | shell: pwsh |
| 74 | run: | |
| 75 | cmake -S . -B build-debug ` |
| 76 | -A "${{ matrix.cmake_arch }}" ` |
| 77 | -DCMAKE_BUILD_TYPE=Debug ` |
| 78 | -DBUILD_OPENCC_JIEBA_PLUGIN=ON ` |
| 79 | -DENABLE_GTEST:BOOL=ON |
| 80 | cmake --build build-debug --config Debug |
| 81 | ctest --test-dir build-debug --build-config Debug --output-on-failure | Tee-Object -FilePath build-debug\ctest.log |
| 82 | |
| 83 | - name: Create portable zip artifact |
| 84 | if: ${{ matrix.can_run_binaries }} |
| 85 | shell: pwsh |
| 86 | run: | |
| 87 | $packageRoot = "dist\opencc-msvc-${{ matrix.package_suffix }}" |
| 88 | $zipPath = "dist\OpenCC-msvc-${{ matrix.package_suffix }}.zip" |
| 89 | if (Test-Path $zipPath) { Remove-Item -Force $zipPath } |
| 90 | Compress-Archive -Path $packageRoot -DestinationPath $zipPath -CompressionLevel Optimal |
| 91 | |
| 92 | - name: Test standalone plugin build |
| 93 | if: ${{ matrix.can_run_binaries }} |
| 94 | shell: pwsh |
| 95 | run: | |
| 96 | cmake -S plugins\jieba -B build-standalone ` |
| 97 | -A "${{ matrix.cmake_arch }}" ` |
| 98 | -DCMAKE_BUILD_TYPE=Release ` |
| 99 | -DOpenCC_DIR="${{ github.workspace }}\dist\opencc-msvc-${{ matrix.package_suffix }}\lib\cmake\opencc" |
| 100 | cmake --build build-standalone --config Release |
| 101 | |
| 102 | - name: List packaged files |
| 103 | if: ${{ always() }} |
| 104 | shell: pwsh |
| 105 | run: | |
| 106 | Write-Host "=== Contents of dist package root ===" |
| 107 | if (Test-Path "dist\opencc-msvc-${{ matrix.package_suffix }}") { |
| 108 | Get-ChildItem "dist\opencc-msvc-${{ matrix.package_suffix }}" -Recurse | Select-Object FullName |
| 109 | } |
| 110 | Write-Host "`n=== Contents of build-debug Testing directory ===" |
| 111 | if (Test-Path build-debug\Testing) { Get-ChildItem build-debug\Testing -Recurse | Select-Object FullName } |
| 112 | Write-Host "`n=== Contents of build-release output directories ===" |
| 113 | if (Test-Path build-release\src) { Get-ChildItem build-release\src -Recurse | Select-Object FullName } |
| 114 | |
| 115 | - name: upload artifacts |
| 116 | if: ${{ always() }} |
| 117 | uses: actions/upload-artifact@v7 |
| 118 | with: |
| 119 | name: opencc-${{ env.VERSION }}-msvc-${{ matrix.arch }} |
| 120 | path: | |
| 121 | dist/OpenCC-msvc-${{ matrix.package_suffix }}.zip |
| 122 | dist/opencc-msvc-${{ matrix.package_suffix }}/** |
| 123 | build-release/src/Release/** |
| 124 | build-release/src/tools/Release/** |
| 125 | build-debug/ctest.log |
| 126 | build-debug/Testing/** |