Skip to content

test: 尝试发布

test: 尝试发布 #26

Workflow file for this run

name: Windows-Rust-Qt
on:
# push代码时触发workflow
push:
# 忽略README.md
paths-ignore:
- 'README.md'
- 'LICENSE'
# pull_request时触发workflow
pull_request:
# 忽略README.md
paths-ignore:
- 'README.md'
- 'LICENSE'
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build
# 运行平台, windows-latest目前是windows server 2017
runs-on: windows-latest
strategy:
# 矩阵配置
matrix:
qt_ver: [5.14.0]
qt_target: [desktop]
qt_arch: [win64_msvc2017_64]
# 额外设置msvc_arch
include:
- qt_arch: win64_msvc2017_64
msvc_arch: x64
qt_arch_install: msvc2017_64
env:
targetName: basic_form.exe
# 步骤
steps:
- uses: ilammy/msvc-dev-cmd@v1
# 安装Qt
- name: Install Qt
# 使用外部action。这个action专门用来安装Qt
uses: jurplel/install-qt-action@v3.3.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
- name: rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Setup-cmake
uses: jwlawson/actions-setup-cmake@v1.14.1
with:
cmake-version: '3.12.x'
- name: Use-cmake
run: cmake --version
# 编译msvc
- name: build-msvc
shell: cmd
env:
vc_arch: ${{ matrix.msvc_arch }}
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch%
rustup toolchain install stable-x86_64-pc-windows-msvc
rustup target add x86_64-pc-windows-msvc
rustup set default-host x86_64-pc-windows-msvc
cargo build --target x86_64-pc-windows-msvc
# tag 打包
- name: package
if: startsWith(github.event.ref, 'refs/tags/')
env:
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC'
archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }}
shell: pwsh
run: |
# 创建文件夹
New-Item -ItemType Directory ${env:archiveName}
# 拷贝exe
Copy-Item target\x86_64-pc-windows-msvc\debug\${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 "packageName=$name" >> "$GITHUB_ENV"
# echo "packageName=$name" >> "$GITHUB_ENV"
# 打印环境变量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 }}
archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }}
uses: softprops/action-gh-release@v1
with:
files: ${{ env.archiveName }}.zip