mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-19 20:22:56 +08:00
175 lines
6.4 KiB
YAML
175 lines
6.4 KiB
YAML
name: Windows
|
||
on:
|
||
# push代码时触发workflow
|
||
push:
|
||
# 忽略README.md
|
||
paths-ignore:
|
||
- 'README.md'
|
||
- 'LICENSE'
|
||
# pull_request时触发workflow
|
||
pull_request:
|
||
# 忽略README.md
|
||
paths-ignore:
|
||
- 'README.md'
|
||
- 'LICENSE'
|
||
jobs:
|
||
build:
|
||
name: Build
|
||
# 运行平台, windows-latest目前是windows server 2019
|
||
runs-on: windows-latest
|
||
strategy:
|
||
# 矩阵配置
|
||
matrix:
|
||
qt_ver: [5.12.6]
|
||
qt_target: [desktop]
|
||
# mingw用不了
|
||
# qt_arch: [win64_msvc2017_64, win32_msvc2017, win32_mingw53,win32_mingw73]
|
||
qt_arch: [win64_msvc2017_64, win32_msvc2017]
|
||
# 额外设置msvc_arch
|
||
include:
|
||
- qt_arch: win64_msvc2017_64
|
||
msvc_arch: x64
|
||
qt_arch_install: msvc2017_64
|
||
- qt_arch: win32_msvc2017
|
||
msvc_arch: x86
|
||
qt_arch_install: msvc2017
|
||
env:
|
||
targetName: TaoQuickApp.exe
|
||
# 步骤
|
||
steps:
|
||
- name: cacheQt
|
||
id: WindowsCacheQt
|
||
uses: actions/cache@v1
|
||
with:
|
||
path: ../Qt/${{matrix.qt_ver}}/${{matrix.qt_arch_install}}
|
||
key: ${{ runner.os }}-Qt/${{matrix.qt_ver}}/${{matrix.qt_arch}}
|
||
- name: setupQt
|
||
if: steps.WindowsCacheQt.outputs.cache-hit == 'true'
|
||
shell: pwsh
|
||
env:
|
||
QtPath: ../Qt/${{matrix.qt_ver}}/${{matrix.qt_arch_install}}
|
||
run: |
|
||
$qt_Path=${env:QtPath}
|
||
echo "::set-env name=Qt5_Dir::$qt_Path"
|
||
echo "::add-path::$qt_Path/bin"
|
||
# 安装Qt
|
||
- name: Install Qt
|
||
if: steps.WindowsCacheQt.outputs.cache-hit != 'true'
|
||
# 使用外部action。这个action专门用来安装Qt
|
||
uses: jurplel/install-qt-action@v2.0.0
|
||
with:
|
||
# Version of Qt to install
|
||
version: ${{ matrix.qt_ver }}
|
||
# Target platform for build
|
||
target: ${{ matrix.qt_target }}
|
||
# Architecture for Windows/Android
|
||
arch: ${{ matrix.qt_arch }}
|
||
# 拉取代码
|
||
- uses: actions/checkout@v1
|
||
with:
|
||
fetch-depth: 1
|
||
# 编译msvc
|
||
- name: build-msvc
|
||
shell: cmd
|
||
env:
|
||
vc_arch: ${{ matrix.msvc_arch }}
|
||
run: |
|
||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch%
|
||
qmake
|
||
nmake
|
||
# tag 打包
|
||
- name: package
|
||
if: startsWith(github.event.ref, 'refs/tags/')
|
||
env:
|
||
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
|
||
archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }}
|
||
shell: pwsh
|
||
run: |
|
||
# 创建文件夹
|
||
New-Item -ItemType Directory ${env:archiveName}
|
||
# 拷贝exe
|
||
Copy-Item bin\release\${env:targetName} ${env:archiveName}\
|
||
# 拷贝依赖
|
||
windeployqt --qmldir . ${env:archiveName}\${env:targetName}
|
||
# 打包zip
|
||
Compress-Archive -Path ${env:archiveName} ${env:archiveName}'.zip'
|
||
# 记录环境变量packageName给后续step
|
||
$name = ${env:archiveName}
|
||
echo "::set-env name=packageName::$name"
|
||
# 打印环境变量packageName
|
||
Write-Host 'packageName:'${env:packageName}
|
||
# tag 查询github-Release
|
||
- name: queryReleaseWin
|
||
id: queryReleaseWin
|
||
if: startsWith(github.event.ref, 'refs/tags/')
|
||
shell: pwsh
|
||
env:
|
||
githubFullName: ${{ github.event.repository.full_name }}
|
||
ref: ${{ github.event.ref }}
|
||
run: |
|
||
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
|
||
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
|
||
$response={}
|
||
try {
|
||
$response = Invoke-RestMethod -Uri $url -Method Get
|
||
} catch {
|
||
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
|
||
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
|
||
# 没查到,输出
|
||
echo "::set-output name=needCreateRelease::true"
|
||
return
|
||
}
|
||
[string]$latestUpUrl = $response.upload_url
|
||
Write-Host 'latestUpUrl:'$latestUpUrl
|
||
if ($latestUpUrl.Length -eq 0) {
|
||
# 没查到,输出
|
||
echo "::set-output name=needCreateRelease::true"
|
||
}
|
||
# tag 创建github-Release
|
||
- name: createReleaseWin
|
||
id: createReleaseWin
|
||
if: startsWith(github.event.ref, 'refs/tags/') && steps.queryReleaseWin.outputs.needCreateRelease == 'true'
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
uses: actions/create-release@v1.0.0
|
||
with:
|
||
tag_name: ${{ github.ref }}
|
||
release_name: Release ${{ github.ref }}
|
||
body: ${{ github.event.head_commit.message }}
|
||
draft: false
|
||
prerelease: false
|
||
# 重定向upload_url到环境变量uploadUrl。
|
||
- name: getLatestTagRelease
|
||
# tag 上一步无论成功还是失败都执行
|
||
if: startsWith(github.event.ref, 'refs/tags/')
|
||
shell: pwsh
|
||
env:
|
||
githubFullName: ${{ github.event.repository.full_name }}
|
||
upUrl: ${{ steps.createReleaseWin.outputs.upload_url }}
|
||
ref: ${{ github.event.ref }}
|
||
run: |
|
||
# upUrl不为空,导出就完事
|
||
if (${env:upUrl}.Length -gt 0) {
|
||
$v=${env:upUrl}
|
||
echo "::set-env name=uploadUrl::$v"
|
||
return
|
||
}
|
||
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
|
||
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
|
||
$response = Invoke-RestMethod -Uri $url -Method Get
|
||
[string]$latestUpUrl = $response.upload_url
|
||
Write-Host 'latestUpUrl:'$latestUpUrl
|
||
echo "::set-env name=uploadUrl::$latestUpUrl"
|
||
Write-Host 'env uploadUrl:'${env:uploadUrl}
|
||
# tag 上传Release
|
||
- name: uploadRelease
|
||
id: uploadRelease
|
||
if: startsWith(github.event.ref, 'refs/tags/')
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
uses: actions/upload-release-asset@v1.0.1
|
||
with:
|
||
upload_url: ${{ env.uploadUrl }}
|
||
asset_path: ./${{ env.packageName }}.zip
|
||
asset_name: ${{ env.packageName }}.zip
|
||
asset_content_type: application/zip |