我刚开始接触 Github Actions,对其工作原理有一定的了解,但是我在为多个分支创建发布时遇到了问题。我想在一个工作流程中从多个分支中创建多个版本。是否可以实现这个功能?
目前我已经有一个有效的工作流程,可以生成和部署我的主要分支的发布版本。现在我想创建一个类似的、但具有不同功能的第二个分支的发布版本。
我的问题和疑问如下:
- Github 工作流程如何区分主分支和其他分支,从主分支的 .yml 文件中创建发布版本?我知道可以使用
if: github.ref
,但不确定如何使用它。 - 我是否应该在第二个分支中创建一个单独的 .yml 文件,使用单独的工作流程并创建不同的标签?
- 我是否应该在矩阵中创建另一个条目,只依赖于第二个分支?
以下是我在主分支中的 .yml 文件:
name: "CI/CD"
on:
push:
branches: [ main, example ]
pull_request:
branches: [ main, example ]
env:
QT_VERSION: 5.15.2
BUILD_TYPE: Release
packageGlob: justAnExample-continuous-*.*
jobs:
main_build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Linux-amd64"
, os: ubuntu-18.04
, QT_INST_DIR: /opt
, install_ninja: "sudo apt-get install -qq ninja-build"
, install_pkgs: "sudo apt-get -qq install libgstreamer-plugins-base1.0-0"
, bcInstallPrefix: /usr
, build_justAnExample: "DESTDIR=./appdir ninja install; find ./appdir; mv default.png ./appdir/usr/share/"
, rename_package: "mv justAnExample-*.tar.xz justAnExample-continuous-linux-x86_64.tar.xz"
}
- {
name: "Windows-x64", WIN_ARCH: "x64"
, os: windows-latest
, QT_INST_DIR: "C:/", QTDIR: "C:/Qt/5.15.2/msvc2019_64", QT_ARCH: win64_msvc2019_64
, install_ninja: "choco install ninja"
, bcInstallPrefix: justAnExample-continuous
, build_justAnExample: "ninja install"
, rename_package: "mv justAnExample-*.zip justAnExample-continuous-win64.zip && mv justAnExample-*.exe justAnExample-continuous-win64-installer.exe"
}
- {
name: "Windows-x86"
, os: windows-latest, WIN_ARCH: "amd64_x86"
, QT_INST_DIR: "C:/", QTDIR: "C:/Qt/5.15.2/msvc2019", QT_ARCH: win32_msvc2019
, install_ninja: "choco install ninja"
, bcInstallPrefix: justAnExample-continuous
, build_justAnExample: "ninja install"
, rename_package: "ls -R && mv justAnExample-*.zip justAnExample-continuous-win32.zip && mv justAnExample-*.exe justAnExample-continuous-win32-installer.exe"
}
steps:
- uses: actions/checkout@v2
- name: Env Script (Windows)
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
with:
arch: ${{matrix.config.WIN_ARCH}}
- name: Install Ninja
run: ${{matrix.config.install_ninja}}
- name: Install Packages
if: runner.os == 'Linux'
run: ${{matrix.config.install_pkgs}}
- name: Install Qt
uses: jurplel/install-qt-action@v2.14.0
with:
dir: ${{matrix.config.QT_INST_DIR}}
arch: ${{matrix.config.QT_ARCH}}
version: ${{env.QT_VERSION}}
- name: Build justAnExample
id: main_build
run: |
cmake -S. -G Ninja -DCMAKE_INSTALL_PREFIX=${{matrix.config.bcInstallPrefix}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
${{matrix.config.build_justAnExample}}
- name: CPack
run: cpack
- name: Build AppImage (Linux)
if: runner.os == 'Linux'
run: |
wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage"
export VERSION=continuous
chmod a+x linuxdeployqt*.AppImage
unset QTDIR; unset QT_PLUGIN_PATH; unset LD_LIBRARY_PATH
./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -appimage -extra-plugins=iconengines,platformthemes/libqxdgdesktopportal.so
- name: Prepare Upload
shell: bash
run: ${{matrix.config.rename_package}}
- name: Upload
uses: actions/upload-artifact@v2
with:
path: ${{ github.workspace }}/${{env.packageGlob}}
release_assets:
name: Release
needs: main_Build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Download Files
uses: actions/download-artifact@v2
- name: Move Files
run: |
mv artifact/* ${{github.workspace}}
- name: Deploy Package
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.DEPLOYTOKEN }}"
automatic_release_tag: "continuous-main"
prerelease: false
title: "Continuous Build"
files: ${{env.packageGlob}}