I am new to github actions, I have a good idea on how they work but I am having troubles creating releases for multiple branches. Is it possible to create multiple releases from multiple branches in a single workflow?
I currently having working workflow that generates and deploys releases for my main branch. I now want to create releases for a second branch that is slightly similar but has varying functionality.
My problem and my question is:
- How does the github workflow differentiate between the main branch and the other branch to create the releases from the .yml file in the main branch? I know you can use
if: github.refbut I am not sure how to go about doing it. - Should I create a seperate .yml in the second branch, with a separate workflow and create different tag?
- Should I create another entry in my matrix that only relies on the second branch?
Below is my .yml in my main branch:
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}}