From 29057fb53c9b1586aad8e307a0f50021deb86493 Mon Sep 17 00:00:00 2001 From: Kot <1192090+koteq@users.noreply.github.com> Date: Mon, 20 Mar 2023 21:46:36 +0000 Subject: [PATCH] Add GitHub Actions workflow --- .github/workflows/build.yml | 92 +++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 8 +++- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f83c3b5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,92 @@ +# Adapted from Pamplejuce template +# https://github.com/sudara/pamplejuce/blob/580314ceb0/.github/workflows/cmake_ctest.yml + +# Reference Documentation +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions + +name: Build + +on: + workflow_dispatch: # lets you run a build from the UI + push: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +env: + PROJECT_NAME: LightHost + BUILD_TYPE: Release + BUILD_DIR: Builds + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CMAKE_BUILD_PARALLEL_LEVEL: 3 # Use up to 3 cpus to build juceaide, etc + +jobs: + build: + name: Build for ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - name: Windows + os: windows-latest + + steps: + - name: Set up Clang + if: ${{ matrix.name != 'macOS' }} + uses: egor-tensin/setup-clang@v1 + + - name: Set up Ninja + if: runner.os == 'Windows' + shell: bash + run: choco install ninja + + - name: Checkout Code + uses: actions/checkout@v3 + with: + submodules: true + + - name: Set up Environment Variables + shell: bash + run: | + VERSION_REGEX='^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$' + if [[ $GITHUB_REF =~ $VERSION_REGEX ]]; then + PROJECT_VERSION="${BASH_REMATCH[1]}" + else + PROJECT_VERSION="0.0.0.${GITHUB_RUN_NUMBER}" + fi + echo "PROJECT_VERSION=${PROJECT_VERSION}" >> $GITHUB_ENV + + - name: CMake Configure + shell: bash + run: cmake -B ${{ env.BUILD_DIR }} -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE}} . + + - name: CMake Build + shell: bash + run: cmake --build ${{ env.BUILD_DIR }} --config ${{ env.BUILD_TYPE }} + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ env.PROJECT_NAME }} + path: "${{ env.BUILD_DIR }}/${{ env.PROJECT_NAME }}_artefacts/${{ env.BUILD_TYPE }}" + + release: + if: contains(github.ref, 'tags/v') + runs-on: ubuntu-latest + needs: build + + steps: + - name: Get Artifacts + uses: actions/download-artifact@v3 + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + # download-artifact puts these files in their own dirs... + # Using globs sidesteps having to pass the version around + files: | + */*.exe + */*.zip + */*.dmg diff --git a/CMakeLists.txt b/CMakeLists.txt index fa18f61..732f771 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,14 @@ cmake_minimum_required(VERSION 3.15) # This cannot have spaces (but PRODUCT_NAME can) set(PROJECT_NAME "LightHost") +# Read project version from env variable, allowing it to be provided by CI/CD workflow +set(PROJECT_VERSION $ENV{PROJECT_VERSION}) +if(NOT PROJECT_VERSION) + set(PROJECT_VERSION 0.0.0.0) +endif() + # For simplicity, the name of the project is also the name of the target -project(${PROJECT_NAME} VERSION 1.2.2) +project(${PROJECT_NAME} VERSION ${PROJECT_VERSION}) # Allow to use deprecated MessageManager::runDispatchLoopUntil add_compile_definitions(JUCE_MODAL_LOOPS_PERMITTED)