首先,每一个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 }}.*
完成!