Skip to content

Commit abe88e0

Browse files
committed
macos add publish
1 parent 0bd5aa2 commit abe88e0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/macos.yml

+83
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
os: [macos-latest]
1818
qt_ver: [5.12.6]
1919
qt_arch: [clang_64]
20+
env:
21+
targetName: HelloActions-Qt
2022
steps:
2123
- name: cacheQt
2224
id: MacosCacheQt
@@ -46,3 +48,84 @@ jobs:
4648
run: |
4749
qmake
4850
make
51+
# tag 打包
52+
- name: package
53+
if: startsWith(github.event.ref, 'refs/tags/')
54+
run: |
55+
# 拷贝依赖
56+
macdeployqt bin/${targetName}.app -qmldir=. -verbose=1 -dmg
57+
# tag 查询github-Release
58+
- name: queryRelease
59+
id: queryReleaseMacos
60+
if: startsWith(github.event.ref, 'refs/tags/')
61+
shell: pwsh
62+
env:
63+
githubFullName: ${{ github.event.repository.full_name }}
64+
ref: ${{ github.event.ref }}
65+
run: |
66+
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
67+
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
68+
$response={}
69+
try {
70+
$response = Invoke-RestMethod -Uri $url -Method Get
71+
} catch {
72+
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
73+
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
74+
# 没查到,输出
75+
echo "::set-output name=needCreateRelease::true"
76+
return
77+
}
78+
[string]$latestUpUrl = $response.upload_url
79+
Write-Host 'latestUpUrl:'$latestUpUrl
80+
if ($latestUpUrl.Length -eq 0) {
81+
# 没查到,输出
82+
echo "::set-output name=needCreateRelease::true"
83+
}
84+
# tag 创建github-Release
85+
- name: createReleaseWin
86+
id: createReleaseWin
87+
if: startsWith(github.event.ref, 'refs/tags/') && steps.queryReleaseMacos.outputs.needCreateRelease == 'true'
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
uses: actions/[email protected]
91+
with:
92+
tag_name: ${{ github.ref }}
93+
release_name: Release ${{ github.ref }}
94+
body: ${{ github.event.head_commit.message }}
95+
draft: false
96+
prerelease: false
97+
# 重定向upload_url到环境变量uploadUrl。
98+
- name: getLatestTagRelease
99+
# tag 上一步无论成功还是失败都执行
100+
if: startsWith(github.event.ref, 'refs/tags/')
101+
shell: pwsh
102+
env:
103+
githubFullName: ${{ github.event.repository.full_name }}
104+
upUrl: ${{ steps.queryReleaseMacos.outputs.upload_url }}
105+
ref: ${{ github.event.ref }}
106+
run: |
107+
# upUrl不为空,导出就完事
108+
if (${env:upUrl}.Length -gt 0) {
109+
$v=${env:upUrl}
110+
echo "::set-env name=uploadUrl::$v"
111+
return
112+
}
113+
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
114+
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
115+
$response = Invoke-RestMethod -Uri $url -Method Get
116+
[string]$latestUpUrl = $response.upload_url
117+
Write-Host 'latestUpUrl:'$latestUpUrl
118+
echo "::set-env name=uploadUrl::$latestUpUrl"
119+
Write-Host 'env uploadUrl:'${env:uploadUrl}
120+
# tag 上传Release
121+
- name: uploadRelease
122+
id: uploadRelease
123+
if: startsWith(github.event.ref, 'refs/tags/')
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
uses: actions/[email protected]
127+
with:
128+
upload_url: ${{ env.uploadUrl }}
129+
asset_path: ./bin/${{ env.targetName }}.dmg
130+
asset_name: ${{ env.targetName }}.dmg
131+
asset_content_type: application/applefile

0 commit comments

Comments
 (0)