diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 3fee518..8bfcc85 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -59,7 +59,6 @@ jobs: # 打包 - name: Package run: | - ls cd ./${QtApplicationName} # mv ./${QtApplicationName}/${QtApplicationName}.app . echo '------------------' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 14ee755..2da9db9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -6,14 +6,16 @@ on: - 'App/**' - 'Tester/**' - '.github/workflows/windows.yml' + - 'scripts/**' pull_request: paths: - 'App/**' - 'Tester/**' - - '.github/workflows/windows.yml' + - '.github/workflows/windows.yml' + - 'scripts/**' jobs: build: - name: Build + name: Windows-CI-CD # 运行平台, windows-latest目前是windows server 2019 # 参考文档 https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md runs-on: windows-2019 @@ -27,7 +29,8 @@ jobs: msvc_arch: x64 qt_arch_install: msvc2019_64 env: - targetName: PolyChatApp.exe + # 在 Qt pro 文件中的 + QtApplicationName: App.exe # 步骤 steps: # 安装Qt @@ -46,60 +49,63 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 1 - # msvc编译 - - name: msvc-build - id: build + # msvc测试 + - name: msvc-test + id: test shell: cmd run: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.msvc_arch }} - cd ./App - qmake + cd ./Tester + qmake CONFIG+=debug nmake echo winSdkDir=%WindowsSdkDir% >> %GITHUB_ENV% echo winSdkVer=%WindowsSdkVersion% >> %GITHUB_ENV% echo vcToolsInstallDir=%VCToolsInstallDir% >> %GITHUB_ENV% echo vcToolsRedistDir=%VCToolsRedistDir% >> %GITHUB_ENV% - test: - needs: build - name: Test - # 运行平台, windows-latest目前是windows server 2019 - # 参考文档 https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md - runs-on: windows-2019 - strategy: - # 矩阵配置 - matrix: - include: - # 6.2.2 - - qt_ver: 6.2.2 - qt_arch: win64_msvc2019_64 - msvc_arch: x64 - qt_arch_install: msvc2019_64 - env: - targetName: PolyChatTester.exe - # 步骤 - steps: - # 安装Qt - - name: Install Qt - uses: jurplel/install-qt-action@v3 - with: - version: ${{ matrix.qt_ver }} - arch: ${{ matrix.qt_arch }} - cached: 'false' - aqtversion: '==2.0.5' - # 拉取代码 - - uses: actions/checkout@v2 - with: - fetch-depth: 1 # msvc编译 - - name: msvc-test - id: test + - name: msvc-build + id: build shell: cmd run: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.msvc_arch }} - cd ./Tester - qmake CONFIG+=debug + cd ./${QtApplicationName} + qmake nmake echo winSdkDir=%WindowsSdkDir% >> %GITHUB_ENV% echo winSdkVer=%WindowsSdkVersion% >> %GITHUB_ENV% echo vcToolsInstallDir=%VCToolsInstallDir% >> %GITHUB_ENV% echo vcToolsRedistDir=%VCToolsRedistDir% >> %GITHUB_ENV% + ls + tree /F + # 打包 + - name: package + id: package + env: + archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }} + msvcArch: ${{ matrix.msvc_arch }} + shell: pwsh + run: | + # 目前处于工程根目录 + tree D: /F + echo '------- Run scripts\windows-publish.ps1' + & scripts\windows-publish.ps1 ${env:archiveName} ${env:QtApplicationName} + echo '------- Finish scripts windows-publish.ps1' + # 记录packageName给后续step + $name = ${env:archiveName} + echo "::set-output name=packageName::$name" + # tag 查询github-Release + # 上传artifacts + - uses: actions/upload-artifact@v2 + with: + name: ${{ steps.package.outputs.packageName }} + path: ${{ steps.package.outputs.packageName }} + # tag 上传Release + - name: uploadRelease + if: startsWith(github.event.ref, 'refs/tags/') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ steps.package.outputs.packageName }}.zip + asset_name: ${{ steps.package.outputs.packageName }}.zip + tag: ${{ github.ref }} + overwrite: true diff --git a/scripts/windows-publish.ps1 b/scripts/windows-publish.ps1 new file mode 100644 index 0000000..2f62a47 --- /dev/null +++ b/scripts/windows-publish.ps1 @@ -0,0 +1,64 @@ +[CmdletBinding()] +param ( + [string] $archiveName, [string] $targetName +) +# 外部环境变量包括: +# archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_arch }} +# winSdkDir: ${{ steps.build.outputs.winSdkDir }} +# winSdkVer: ${{ steps.build.outputs.winSdkVer }} +# vcToolsInstallDir: ${{ steps.build.outputs.vcToolsInstallDir }} +# vcToolsRedistDir: ${{ steps.build.outputs.vcToolsRedistDir }} +# msvcArch: ${{ matrix.msvc_arch }} + + +# winSdkDir: C:\Program Files (x86)\Windows Kits\10\ +# winSdkVer: 10.0.19041.0\ +# vcToolsInstallDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\ +# vcToolsRedistDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.28.29325\ +# archiveName: 5.9.9-win32_msvc2015 +# msvcArch: x86 + +$scriptDir = $PSScriptRoot +$currentDir = Get-Location +Write-Host "currentDir" $currentDir +Write-Host "scriptDir" $scriptDir + +function Main() { + + New-Item -ItemType Directory $archiveName + + # 拷贝exe + Copy-Item .\App\release\$targetName $archiveName\ + Write-Host "[INFO] Copy-Item from .\App\release\" $targetName " to " $archiveName "done" + + # 拷贝依赖 + windeployqt --qmldir . --plugindir $archiveName\plugins --no-translations --compiler-runtime $archiveName\$targetName + Write-Host "[INFO] windeployqt done" + + # 删除不必要的文件 + $excludeList = @("*.qmlc", "*.ilk", "*.exp", "*.lib", "*.pdb") + Remove-Item -Path $archiveName -Include $excludeList -Recurse -Force + Write-Host "[INFO] Remove-Item done" + + # 拷贝vcRedist dll + $redistDll="{0}{1}\*.CRT\*.dll" -f $env:vcToolsRedistDir.Trim(),$env:msvcArch + Copy-Item $redistDll $archiveName\ + Write-Host "[INFO] Copy-Item vcRedist dll done" + + # 拷贝WinSDK dll + $sdkDll="{0}Redist\{1}ucrt\DLLs\{2}\*.dll" -f $env:winSdkDir.Trim(),$env:winSdkVer.Trim(),$env:msvcArch + Copy-Item $sdkDll $archiveName\ + Write-Host "[INFO] Copy-Item WinSDK dll done" + + # 打包zip + Compress-Archive -Path $archiveName $archiveName'.zip' + Write-Host "[INFO] Compress-Archive done" +} + +if ($null -eq $archiveName || $null -eq $targetName) { + Write-Host "args missing, archiveName is" $archiveName ", targetName is" $targetName + return +} +Main + +