Github action安装Qt(详解)

本文描述了一个GitHub工作流,当代码推送到仓库时,自动在Ubuntu、macOS和Windows上安装Qt,编译并打包应用程序,最后将不同平台的包上传到仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,每一个yml文件都要有一个名字,并且名字应该要和文件名相同(不然它好像不会运行)

name: QT
#冒号后有一个空格

然后是代码的触发条件

on: 
  # push代码时触发workflow
  push:
    # 忽略README.md
    paths-ignore:
      - 'README.md'
      - 'LICENSE'
  # pull_request时触发workflow
  pull_request:
    # 忽略README.md
    paths-ignore:
      - 'README.md'
      - 'LICENSE'

这是推送和拉取请求时运行。

之后是action运行的内容

jobs:
  build:
    runs-on: ${{ matrix.os }}#运行平台
    strategy:
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
      fail-fast: false
    name: ${{ matrix.os }}
    steps:
    - name: Git checkout
      uses: actions/checkout@v3#拉取代码
    - name: Install Qt windows #安装Qt
      if: matrix.os == 'windows-latest'
      uses: jurplel/install-qt-action@v3
      with:
        version: '6.2.2'
        arch: 'win64_mingw'
    - name: Install Qt linux 
      if: matrix.os == 'ubuntu-latest'
      uses: jurplel/install-qt-action@v3
      with:
        version: '6.2.*'
        target: 'desktop'
    - name: Install Qt mac
      if: matrix.os == 'macOS-latest'
      uses: jurplel/install-qt-action@v3
      with:
        version: '6.2.*'
        target: 'desktop'
    - name: Set up MinGW
      if: matrix.os == 'windows-latest'
      uses: egor-tensin/setup-mingw@v2#安装windows的MinGW
      with:
          platform: x64
    - name: compile qmake#生成makefile
      run:  qmake
    - name: compile make mac#编译
      if: matrix.os == 'macOS-latest'
      run:  make
    - name: compile make linux
      if: matrix.os == 'ubuntu-latest'
      run:  make
    - name: compile make win
      if: matrix.os == 'windows-latest'
      shell: cmd
      run: |
        mingw32-make
    - name: pack win exe #复制
      if: matrix.os == 'windows-latest'
      run: |
        mkdir app
        cp release/class-manager.exe app
        cd app
        windeployqt class-manager.exe
    - name: pack linux app
      if: matrix.os == 'ubuntu-latest'
      run: |
        mkdir app
        cp class-manager app
    - name: pack mac app
      if: matrix.os == 'macOS-latest'
      run: |
        mkdir app
        cp class-manager.app/Contents/MacOS/class-manager app
    - name: gzip #压缩
      run: |
        tar -czvf app-${{ matrix.os }}.tar.gz app
    - name: Upload app #发布
      uses: actions/upload-artifact@v3
      with:
        name: app-${{ matrix.os }}
        path: app-${{ matrix.os }}.*

 完成!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值