几个月前写过两篇持续集成的教程,当时使用的是travis和appveyor这两个第三方网址提供的服务。
(资料图片仅供参考)
由于配置比较复杂,劝退了很多同学……
2019年8月份,github正式上线了Actions功能,提供了十分强大的CI(持续集成)/CD(持续部署)服务,
使用非常简单、方便,再加上github的Marketplace(github的应用商店)有各路大神开源的Actions模板, 完全可以抛弃那些落后的第三方服务了。
注:Actions也能在私有仓库上用(微软良心)。
这回涛哥将给大家提供一个简易的Qt项目的Action模板,让每一个有追求的Qter,都能轻松地用上强大的CI/CD功能。
(本文先说自动化编译,自动化发布下次说。)
我创建了一个新的代码仓库,地址在这:
https://github.com/jaredtao/HelloActions-Qt
先来看看效果吧
这是github的Actions页面
图中可以看到,最后一次提交的代码,在Windows、Ubuntu、MacOS、Android、IOS五个平台都编译通过了(通过显示绿色的对勾✔,未通过显示红色的叉❌)。
涛哥是个徽章爱好者,把这些徽章都链接进了README文件中。别人在预览代码仓库的时候,很容易就能看到仓库的编译状态。
当然,在commit页面,还可以详细查看每一次commit的代码,是否都编译通过
(这里假设各位读者会使用基本的git、github操作,不会的请去搜索相关教程)
下载涛哥的仓库HelloActions-Qtgit clone https://github.com/jaredtao/HelloActions-Qt
拷贝文件夹’.github’到你的代码仓库根目录 在你的仓库中commit并添加.github文件夹中的文件 push你的仓库到github push完就可以了,到你的github相应仓库页面-Actions子页面查看状态吧。
没错,复制、粘贴,就这么简单。
.github/workflows文件夹中包括写好的5个模板:
你也可以根据你的需要,只选择你需要的。
授人以鱼,不如授人以渔
这里再来介绍一些基本的原理。
可以参考 github Actions官方文档
中文文档目前翻译不全面,建议优先看英文的。
github-Actions 主要提供了windows server 2019、macos 10.15、ubuntu 18.04三个平台的docker环境,
并预装了大量开发者常用的软件,比如Java SDK、Android SDK、VisualStudio、python、golang、nodejs等,
可以在文档github Actions默认环境及预装软件 中看到详细的信息。
github-Actions和大部分docker环境一样,使用yaml/yml格式的配置文件。
同时github-Actions还提供了一些便利的功能、函数,可以参考
github Actions配置文件语法
更多细节请大家参考文档,这里就不赘述了。
每个github仓库,都有一个Actions页面,在这里可以创建、管理Actions
一般使用nodejs、python、golang等环境的项目,github提供了现成的Actions模板,可以
直接在Actions创建页面或者Marketplace(github的应用商店)进行搜索、引用。
有闲暇的开发者,也可以开发自己的Actions并提交到github商店,甚至可以赚点零花钱哦。
(Actions开发使用TypeScript)
简单总结一下Qt项目的编译流程
安装Qt环境 这一步用下文的Action模板:install-qt-action 获取项目代码 这一步用Actions官方核心模板:actions/checkout@v1 执行qmake、make 这一步用自定义脚本,可以换成qbs、cmake、gn、ninja等构建工具 执行test 这一步可以引入单元测试、自动化UI测试等。以后再说。 执行deployment 等我下一篇文章Qt项目暂时没有公开、完整的Actions模板,不过有一个安装Qt的Actions,解决了在不同平台安装不同版本Qt的问题。
install-qt-action
github的Actions有一个非常强大的功能,就是引用外部模板。
比如要引入这个install-qt-Actions模板,只要在配置文件中添加两行即可:
... - name: Install Qt uses: jurplel/install-qt-action@v2...
Qt的安装路径、版本、目标平台、目标架构都有默认配置,当然你也可以手动配置
... - name: Install Qt uses: jurplel/install-qt-action@v2 with: # 安装目录,默认当前路径 #dir: # optional # 版本,默认最新的LTS(5.12.6) version: 5.12.6 # 编译平台。一般不修改。 #host: # optional # 目标平台。默认desktop,可选android、ios target: desktop # 架构 arch: win64_msvc2017_64...
这个Actions模板的实现,是按照Actions的工作原理(TypeScript),调用另一个python仓库aqtinstall,
把配置参数传递过去,由该库完成Qt的安装。
aqtinstall由一位日本的程序员使用python开发,直接访问Qt官方的发布仓库
http://download.qt.io/online/qtsdkrepository/ , 下载指定平台的各模块压缩包,并解压到指定目录。
直接绕过了我们平常使用的Qt安装器。
aqtinstall没有实现‘只安装指定模块’,默认全安装。希望后续能做支持,毕竟Qt全安装太大了。
涛哥还发现一个开源的action,并没有进商店,功能是适配所有平台的Qt环境变量
https://github.com/Skycoder42/action-setup-qt
可以在该作者的’Json序列化库’中,看到实际应用
https://github.com/Skycoder42/QtJsonSerializer
目前是固定在Qt5.13.2版本,包含winrt、wasm等所有平台。
接下来,说一下涛哥提供的模板,对各平台的配置。
以方便那些,需要对模板做修改的同学。
涛哥在这个配置文件中,写了一些注释。
# windows.ymlname: Windowson: # 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.9.8,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] # 从矩阵中除外的配置 exclude: # 不存在5.9.8-win32_msvc2017的版本 - qt_ver: 5.9.8 qt_arch: win32_msvc2017 # mingw用不了 # - qt_ver: 5.9.8 # qt_arch: win32_mingw73 # - qt_ver: 5.12.6 # qt_arch: win32_mingw53 # 额外设置msvc_arch include: - qt_arch: win64_msvc2017_64 msvc_arch: x64 - qt_arch: win32_msvc2017 msvc_arch: x86 # 步骤 steps: # 安装Qt - name: Install Qt # 使用外部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
大部分配置都是显而易见的,这里对一些特殊情况做一些说明吧。
windows平台优先推荐用msvc编译,不过有些情况不得不用mingw。
github-Actions提供的Windows Server 2019环境,预装Mingw为8.1.0,版本太高了。
Qt5.9需要的mingw版本是5.3,而5.12则需要7.3,涛哥试过简单的HelloWorld程序,都会报链接失败。
所以需要使用MinGW的同学,需要自己安装了。
github-Actions在Windows平台默认的shell是PowerShell,其它平台是bash。
使用msvc命令行编译项目时,一般要先调用’vcvarsxxx.bat’脚本来设置环境变量。
Powershell虽然强大,却不太方便直接调用这个bat。要么安装Powershell扩展Pcsx,要么
用一些取巧的方式:
https://stackoverflow.com/questions/2124753/how-can-i-use-powershell-with-the-visual-studio-command-prompt
github-Actions当然也可以直接指定使用cmd。
... # 编译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...
Ubuntu 平台看配置吧。
# ubuntu.ymlname: Ubuntu# Qt官方没有linux平台的x86包on: push: paths-ignore: - "README.md" - "LICENSE" pull_request: paths-ignore: - "README.md" - "LICENSE"jobs: build: name: Build runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-16.04,ubuntu-18.04] qt_ver: [5.9.8,5.12.6] steps: - name: Install Qt uses: jurplel/install-qt-action@v2.0.0 with: version: ${{ matrix.qt_ver }} - name: ubuntu install GL library run: sudo apt-get install -y libglew-dev libglfw3-dev - uses: actions/checkout@v1 with: fetch-depth: 1 - name: build ubuntu run: | qmake make
MacOS平台和Ubuntu差别不大
# macos.ymlname: MacOSon: push: paths-ignore: - "README.md" - "LICENSE" pull_request: paths-ignore: - "README.md" - "LICENSE"jobs: build: name: Build runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest] qt_ver: [5.9.8,5.12.6] steps: - name: Install Qt uses: jurplel/install-qt-action@v2.0.0 with: version: ${{ matrix.qt_ver }} - uses: actions/checkout@v1 with: fetch-depth: 1 - name: build macos run: | qmake make
Android使用ubuntu编译,Windows那个ndk似乎没装,未尝试。
如果只使用Qt5.12.6,默认的配置可以直接用,编译前设置环境变量 ANDROID_SDK_ROOT
和ANDROID_NDK_ROOT就可以了。
Qt5.9.8要指定低版本的NDK、SDK才行,这里涛哥没有进一步尝试。
# android.ymlname: Androidon: push: paths-ignore: - "README.md" - "LICENSE" pull_request: paths-ignore: - "README.md" - "LICENSE" jobs: build: name: Build runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest] # 5.9.8 版本低,需要额外设置工具链。这里暂不支持。 qt_ver: [5.12.6] qt_target: [android] # android_arm64_v8a 暂时不支持. install-qt-action 依赖的aqtinstall版本为0.5*,需要升级 # qt_arch: [android_x86,android_armv7,android_arm64_v8a] qt_arch: [android_x86,android_armv7] # exclude: # - qt_ver: 5.9.8 # qt_arch: android_arm64_v8a steps: - name: Install Qt # if: steps.cacheqt.outputs.cache-hit != "true" 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 - name: build android run: | export ANDROID_SDK_ROOT=$ANDROID_HOME export ANDROID_NDK_ROOT=$ANDROID_HOME/ndk-bundle qmake make
ios只能使用MacOS编译。
qmake的时候要指定平台、release模式等。
#ios.ymlname: IOSon: push: paths-ignore: - "README.md" pull_request: paths-ignore: - "README.md"jobs: build: name: Build runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest] qt_ver: [5.12.6] qt_target: [ios] steps: - name: Install Qt # if: steps.cacheqt.outputs.cache-hit != "true" 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 }} - uses: actions/checkout@v1 with: fetch-depth: 1 - name: build ios run: | qmake -r -spec macx-ios-clang CONFIG+=release CONFIG+=iphoneos make
【领 QT开发教程 学习资料, 点击下方链接莬费领取↓↓ ,先码住不迷路~】
点击这里:
前言几个月前写过两篇持续集成的教程,当时使用的是travis和appveyo...
四川经济网巴中讯(记者何菊)促进消费回暖升级,今年初,巴中市聚...
剑桥科技:拟与中新产发投签署《合资协议》设立合资公司:剑桥科技...
》》》天津盘山游玩(地点+时间)入园时间每天07:30--17:00景区地址...
海报直击丨郑州共享厨房合伙人:当时那钱就不应该接收,厨房,义工,豪...
何峰主任医师北京积水潭医院病情分析:这种情况的发生通常见于早泄
将红牛引入中国并发展壮大的华彬集团在第三届消博会上参展,旗下运...
预售50万起AITO问界M9开启预订余承东:500万以内最好不是我们目标
鹤壁市住房公积金管理中心官网消息,近日,该中心发布关于调整住房...
2023年4月6日,由陈晓、陈建斌主演的《尘封十三载》在网上播出,一...
直播吧4月17日讯今天上午10:30,NBA季后赛G1,掘金主场迎战森林狼。...
楸树花开时,繁花万千层。在郑州市金水区黄河北街两侧种植的楸树陆...
4月17日,安徽森泰木塑集团股份有限公司(下称“森泰股份”,SZ:301...
《光遇》是一款是由游戏制作人陈星汉及其团队Thatgamecompany开发的
北京卫蓝新能源:高能量密度动力电池将量产:据上证报,记者今日从...
导语:现代生活水平不断的提高,越来越多的人开始追求优质的生活,...
1、如果是用液化气就可能是液化气瓶上的减压阀失效,造成燃气进气压...
【文 观察者网王世纯】近期一些国家一系列推进本币结算和“去美元...
今天来聊聊关于环保手抄报文字大全,环保手抄报文字资料的文章,现...
林肯冒险家(参数|询价)是一款融合了奢华和实用性的SUV,其豪华内饰...
近日,中国人民银行惠州市中心支行等联合印发《2023年惠州金融支持...
你想变成有钱人吗?几乎人人都想,但你认真了解过金钱吗?金钱是门...
“我的生活,我的故事”(MLMS)项目于2013年通过退伍军人健康管理局...
1、不仅 反而 表示递进关系;例如:土豆不仅...
新华社北京4月17日电中国篮球协会17日发布公告,认定上海队在2022-2...
网传学生因抢洗衣机砍人学校回应今天的热度非常高,现在也是在热搜...
1、这个问题应该放在游戏的分类吧我们这里是保险的分类“鬼七枷社”...
4月17日电,据纽约时报消息,三星电子据悉考虑将其设备上的默认搜索...
随Switch一起发售的《塞尔达传说:旷野之息》以对开放世界游戏的重...
抓取不同大小、形状和纹理的物体对人类来说很容易,但对机器人来说...