Skip to content

Commit

Permalink
update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mangoeffect committed Jul 28, 2021
1 parent 9bc43e2 commit 102588c
Showing 1 changed file with 20 additions and 79 deletions.
99 changes: 20 additions & 79 deletions .github/workflows/build_on_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,90 +20,31 @@ jobs:
run: cmake --build build --config Release --parallel 10
- name: install-release
run: cmake --install build --config Release
# tag 打包
# 打包
- name: package
if: startsWith(github.event.ref, 'refs/tags/')
shell: pwsh
run: |
# 打包zip
Compress-Archive -Path install Gaclib_vc16_x64.zip
# 记录环境变量packageName给后续step
$name = "Gaclib_vc16_x64"
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'
id: package
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/create-release@v1.0.0
with:
tag_name: ${{ github.ref }}
release_name: Gaclib ${{ 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/')
archiveName: Gaclib_vc16_x64
msvcArch: x64
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}
# 压缩
Compress-Archive -Path ./install ${env:archiveName}'.zip'
# 记录packageName给后续step
$name = ${env:archiveName}
echo "::set-output name=packageName::$name"
# 上传artifacts
- uses: actions/upload-artifact@v2
with:
name: ${{ steps.package.outputs.packageName }}
path: ${{ steps.package.outputs.packageName }}.zip
# 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
uses: svenstaro/upload-release-action@v2
with:
upload_url: ${{ env.uploadUrl }}
asset_path: ./${{ env.packageName }}.zip
asset_name: ${{ env.packageName }}.zip
asset_content_type: application/zip
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.package.outputs.packageName }}.zip
asset_name: ${{ steps.package.outputs.packageName }}.zip
tag: ${{ github.ref }}
overwrite: true

0 comments on commit 102588c

Please sign in to comment.