33
33
- qt_arch : win32_msvc2017
34
34
msvc_arch : x86
35
35
qt_arch_install : msvc2017
36
+ env :
37
+ targetName : HelloActions-Qt.exe
36
38
# 步骤
37
39
steps :
38
40
- name : cacheQt
75
77
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch%
76
78
qmake
77
79
nmake
80
+ # tag 打包
81
+ - name : package
82
+ if : startsWith(github.event.ref, 'refs/tags/')
83
+ env :
84
+ VCINSTALLDIR : ' C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
85
+ archiveName : ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }}
86
+ shell : pwsh
87
+ run : |
88
+ # 创建文件夹
89
+ New-Item -ItemType Directory ${env:archiveName}
90
+ # 拷贝exe
91
+ Copy-Item bin\${env:targetName} ${env:archiveName}\
92
+ # 拷贝依赖
93
+ windeployqt --qmldir . ${env:archiveName}\${env:targetName}
94
+ # 打包zip
95
+ Compress-Archive -Path ${env:archiveName} ${env:archiveName}'.zip'
96
+ # 记录环境变量packageName给后续step
97
+ $name = ${env:archiveName}
98
+ echo "::set-env name=packageName::$name"
99
+ # 打印环境变量packageName
100
+ Write-Host 'packageName:'${env:packageName}
101
+ # tag 查询github-Release
102
+ - name : queryReleaseWin
103
+ id : queryReleaseWin
104
+ if : startsWith(github.event.ref, 'refs/tags/')
105
+ shell : pwsh
106
+ env :
107
+ githubFullName : ${{ github.event.repository.full_name }}
108
+ ref : ${{ github.event.ref }}
109
+ run : |
110
+ [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
111
+ [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
112
+ $response={}
113
+ try {
114
+ $response = Invoke-RestMethod -Uri $url -Method Get
115
+ } catch {
116
+ Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
117
+ Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
118
+ # 没查到,输出
119
+ echo "::set-output name=needCreateRelease::true"
120
+ return
121
+ }
122
+ [string]$latestUpUrl = $response.upload_url
123
+ Write-Host 'latestUpUrl:'$latestUpUrl
124
+ if ($latestUpUrl.Length -eq 0) {
125
+ # 没查到,输出
126
+ echo "::set-output name=needCreateRelease::true"
127
+ }
128
+ # tag 创建github-Release
129
+ - name : createReleaseWin
130
+ id : createReleaseWin
131
+ if : startsWith(github.event.ref, 'refs/tags/') && steps.queryReleaseWin.outputs.needCreateRelease == 'true'
132
+ env :
133
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
134
+
135
+ with :
136
+ tag_name : ${{ github.ref }}
137
+ release_name : Release ${{ github.ref }}
138
+ body : ${{ github.event.head_commit.message }}
139
+ draft : false
140
+ prerelease : false
141
+ # 重定向upload_url到环境变量uploadUrl。
142
+ - name : getLatestTagRelease
143
+ # tag 上一步无论成功还是失败都执行
144
+ if : startsWith(github.event.ref, 'refs/tags/')
145
+ shell : pwsh
146
+ env :
147
+ githubFullName : ${{ github.event.repository.full_name }}
148
+ upUrl : ${{ steps.createReleaseWin.outputs.upload_url }}
149
+ ref : ${{ github.event.ref }}
150
+ run : |
151
+ # upUrl不为空,导出就完事
152
+ if (${env:upUrl}.Length -gt 0) {
153
+ $v=${env:upUrl}
154
+ echo "::set-env name=uploadUrl::$v"
155
+ return
156
+ }
157
+ [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
158
+ [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
159
+ $response = Invoke-RestMethod -Uri $url -Method Get
160
+ [string]$latestUpUrl = $response.upload_url
161
+ Write-Host 'latestUpUrl:'$latestUpUrl
162
+ echo "::set-env name=uploadUrl::$latestUpUrl"
163
+ Write-Host 'env uploadUrl:'${env:uploadUrl}
164
+ # tag 上传Release
165
+ - name : uploadRelease
166
+ id : uploadRelease
167
+ if : startsWith(github.event.ref, 'refs/tags/')
168
+ env :
169
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
170
+
171
+ with :
172
+ upload_url : ${{ env.uploadUrl }}
173
+ asset_path : ./${{ env.packageName }}.zip
174
+ asset_name : ${{ env.packageName }}.zip
175
+ asset_content_type : application/zip
0 commit comments