diff --git a/.github/actions/build-with-docker/action.yml b/.github/actions/build-with-docker/action.yml index 760f2ae7..b37b35ea 100644 --- a/.github/actions/build-with-docker/action.yml +++ b/.github/actions/build-with-docker/action.yml @@ -1,6 +1,6 @@ name: 'Build' -description: 'Build the repository in a Docker container' +description: 'Build the repository in a docker container' runs: using: 'docker' image: 'docker://abeltrano/netremote-build:latest' diff --git a/.github/actions/build-with-host/action.yml b/.github/actions/build-with-host/action.yml new file mode 100644 index 00000000..75f5a149 --- /dev/null +++ b/.github/actions/build-with-host/action.yml @@ -0,0 +1,85 @@ + +name: 'build-on-host' +description: 'Build the repository on the runner host system' +inputs: + build-type: + required: false + default: 'Debug' + description: 'The CMake build type (CMAKE_BUILD_TYPE) to run.' + install: + required: false + default: 'false' + description: 'Invoke CMake install for the project' + test: + required: false + default: 'true' + description: 'Invoke CMake CTest for the project' + package: + required: false + default: 'false' + description: 'Invoke CMake CPack for the project' + publish-artifacts: + required: false + default: 'false' + description: 'Publish build artifacts' + preset-name: + required: false + default: 'dev-windows' + description: 'The name of the preset to use for all CMake operations (configure, build, test, install, package)' + vcpkg-binarycache: + required: false + default: 'true' + description: 'Use the vcpkg binary cache' +runs: + using: 'composite' + steps: + - name: Configure vcpkg to use Github Actions Cache + if: ${{ inputs.vcpkg-binarycache == 'true' }} + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Install vcpkg dependencies with Github Actions Cache + if: ${{ inputs.vcpkg-binarycache == 'true' }} + run: vcpkg install --binarysource="clear;x-gha,readwrite" + shell: pwsh + + - name: CMake Configure + if: ${{ ! inputs.arch }} + run: cmake --preset ${{ inputs.preset-name }} --fresh -DCMAKE_BUILD_TYPE=${{ inputs.build-type }} + shell: pwsh + + - name: CMake Configure Cross-Compile ${{ inputs.arch }} + if: ${{ inputs.arch }} + run: cmake --preset ${{ inputs.preset-name }} --fresh -DCMAKE_BUILD_TYPE=${{ inputs.build-type }} -DNETREMOTE_DISABLE_TESTS=TRUE -A ${{ inputs.arch }} + shell: pwsh + + - name: CMake Build + run: cmake --build --preset ${{ inputs.preset-name }} --config ${{ inputs.build-type }} + shell: pwsh + + - name: CMake Test (ctest) + if: ${{ inputs.test == 'true' && ! inputs.arch }} + run: ctest --preset ${{ inputs.preset-name }} -C ${{ inputs.build-type }} + shell: pwsh + + - name: CMake Install + if: inputs.install == 'true' + run: cmake --build --preset ${{ inputs.preset-name }} --target install --config ${{ inputs.build-type }} + shell: pwsh + + - name: CMake Package (cpack) + if: inputs.package == 'true' + run: cpack --preset ${{ inputs.preset-name }} -C ${{ inputs.build-type }} + shell: pwsh + + - name: Publish Artifacts + if: inputs.publish-artifacts == 'true' + uses: actions/upload-artifact@v3 + with: + name: release-package-${{ runner.os }}-${{ inputs.build-type }}-${{ inputs.arch != '' && inputs.arch || runner.arch }} + path: | + ${{ github.workspace }}/out/package/${{ inputs.preset-name }}/*.tar.* + ${{ github.workspace }}/out/package/${{ inputs.preset-name }}/*.zip diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml new file mode 100644 index 00000000..a7a385cc --- /dev/null +++ b/.github/workflows/build-linux.yml @@ -0,0 +1,13 @@ + +name: 'Build Linux' + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build in container + uses: ./.github/actions/build-with-docker \ No newline at end of file diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 00000000..32afeabd --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,35 @@ + +name: 'Build Windows' + +on: + workflow_dispatch: + inputs: + build-type: + description: 'Build type' + required: true + type: choice + options: + - 'Debug' + - 'Release' + - 'RelWithDebInfo' + - 'MinSizeRel' + default: 'Debug' + +jobs: + build: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + uses: ./.github/actions/build-with-host + with: + build-type: ${{ inputs.build-type }} + preset-name: 'dev-windows' + analyze-codeql: false + build-arm64: false + install: false + test: false + package: false + publish-artifacts: false + \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9d37a45..b2ef7869 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,14 +1,127 @@ - -name: 'Build in Docker Container' - -on: [pull_request, workflow_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build in container - uses: ./.github/actions/build-with-docker - \ No newline at end of file +name: Build [CMake] + +on: + workflow_dispatch: + inputs: + analyze-codeql: + required: true + default: true + type: boolean + description: 'Peform static analysis with CodeQL' + build-arm64: + required: false + default: false + type: boolean + description: 'Build ARM64 architecture' + install: + required: true + default: false + type: boolean + description: 'Invoke CMake install for the project' + test: + required: false + default: true + type: boolean + description: 'Invoke CMake CTest for the project' + package: + required: true + default: false + type: boolean + description: 'Invoke CMake CPack for the project' + publish-artifacts: + required: true + default: false + type: boolean + description: 'Publish build artifacts' + build-types: + required: true + # Note the string here contains a JSON array. This is later converted to an array using fromJson. + default: "[ 'Debug' ]" + type: string + description: 'The CMake build types (CMAKE_BUILD_TYPE) to run (must be encoded as a JSON array)' + preset-name: + required: true + default: 'dev-windows' + type: choice + options: + - 'dev-windows' + - 'release-windows' + description: 'The name of the preset to use for all CMake operations (configure, build, test, install, package)' + workflow_call: + inputs: + build-types: + required: false + # Note the string here contains a JSON array. This is later converted to an array using fromJson. + default: "[ 'Debug' ]" + type: string + description: 'The CMake build type (CMAKE_BUILD_TYPE) to run.' + analyze-codeql: + required: false + default: true + type: boolean + build-arm64: + required: false + default: false + type: boolean + install: + required: false + default: false + type: boolean + test: + required: false + default: true + type: boolean + package: + required: false + default: false + type: boolean + publish-artifacts: + required: false + default: false + type: boolean + preset-name: + required: false + default: 'dev-windows' + type: string + +jobs: + build: + name: cmake build + strategy: + fail-fast: false + matrix: + config: + - { os: windows-2022 } + - { os: windows-2022, arch: 'ARM64' } + - { os: ubuntu-22.04 } + build-type: ${{ fromJson(inputs.build-types) }} + runs-on: ${{ matrix.config.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + if: inputs.analyze-codeql == true && contains(matrix.config.os, 'windows') + uses: github/codeql-action/init@v2 + with: + languages: 'cpp' + + - name: Build Windows + if: ${{ contains(matrix.config.os, 'windows') }} + uses: ./.github/actions/build-with-host + with: + build-type: ${{ matrix.build-type }} + install: ${{ inputs.install }} + test: ${{ inputs.test }} + package: ${{ inputs.package }} + publish-artifacts: ${{ inputs.publish-artifacts }} + preset-name: ${{ inputs.preset-name }} + + - name: Build Linux + if: ${{ contains(matrix.config.os, 'ubuntu') }} + uses: ./.github/actions/build-with-docker + + - name: Perform CodeQL Analysis + if: inputs.analyze-codeql == true && contains(matrix.config.os, 'windows') + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 00000000..62465a54 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,21 @@ +# Primary workflow that runs on each pull request and push to the primary +# branches, develop and main. + +name: CI/CD + +# Run on workflow dispatch to allow manual triggering of the workflow, and run +# on pushes and PRs to the main branches to enforce code quality and test +# coverage. +on: + workflow_dispatch: + push: + branches: [ develop, main ] + pull_request: + branches: [ develop, main ] + +jobs: + build-validation: + name: Build Validation + uses: ./.github/workflows/build.yml + with: + build-types: "[ 'Debug' ]" diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml deleted file mode 100644 index 41d7d723..00000000 --- a/.github/workflows/cmake.yml +++ /dev/null @@ -1,153 +0,0 @@ -name: Build [CMake] - -on: - workflow_dispatch: - inputs: - analyze-codeql: - required: true - default: true - type: boolean - description: 'Peform static analysis with CodeQL' - build-arm64: - required: false - default: false - type: boolean - description: 'Build ARM64 architecture' - install: - required: true - default: false - type: boolean - description: 'Invoke CMake install for the project' - test: - required: false - default: true - type: boolean - description: 'Invoke CMake CTest for the project' - package: - required: true - default: false - type: boolean - description: 'Invoke CMake CPack for the project' - publish-artifacts: - required: true - default: false - type: boolean - description: 'Publish build artifacts' - build-types: - required: true - # Note the string here contains a JSON array. This is later converted to an array using fromJson. - default: "[ 'Debug' ]" - type: string - description: 'The CMake build types (CMAKE_BUILD_TYPE) to run (must be encoded as a JSON array)' - preset-name: - required: true - default: 'dev-windows' - type: choice - options: - - 'dev-windows' - - 'release-windows' - description: 'The name of the preset to use for all CMake operations (configure, build, test, install, package)' - workflow_call: - inputs: - build-types: - required: false - # Note the string here contains a JSON array. This is later converted to an array using fromJson. - default: "[ 'Debug' ]" - type: string - description: 'The CMake build type (CMAKE_BUILD_TYPE) to run.' - analyze-codeql: - required: false - default: true - type: boolean - build-arm64: - required: false - default: false - type: boolean - install: - required: false - default: false - type: boolean - test: - required: false - default: true - type: boolean - package: - required: false - default: false - type: boolean - publish-artifacts: - required: false - default: false - type: boolean - preset-name: - required: false - default: 'dev-windows' - type: string - -jobs: - build: - name: cmake build - strategy: - fail-fast: false - matrix: - config: - - { os: windows-2022 } - - { os: windows-2022, arch: 'ARM64' } - build-type: ${{ fromJson(inputs.build-types) }} - runs-on: ${{ matrix.config.os }} - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - if: inputs.analyze-codeql == true - uses: github/codeql-action/init@v2 - with: - languages: 'cpp' - - - name: Configure vcpkg to use Github Actions Cache - uses: actions/github-script@v6 - with: - script: | - core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); - core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - - - name: Install vcpkg dependencies with Github Actions Cache - run: vcpkg install --binarysource="clear;x-gha,readwrite" - - - name: CMake Configure - if: ${{ ! matrix.config.arch }} - run: cmake --preset ${{ inputs.preset-name }} --fresh -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - - - name: CMake Configure Cross-Compile ${{ matrix.config.arch }} - if: ${{ matrix.config.arch }} - run: cmake --preset ${{ inputs.preset-name }} --fresh -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DNETREMOTE_DISABLE_TESTS=TRUE -A ${{ matrix.config.arch }} - - - name: CMake Build - run: cmake --build --preset ${{ inputs.preset-name }} --config ${{ matrix.build-type }} - - - name: CMake Test (ctest) - if: ${{ inputs.test == true && ! matrix.config.arch }} - run: ctest --preset ${{ inputs.preset-name }} -C ${{ matrix.build-type }} - - - name: CMake Install - if: inputs.install == true - run: cmake --build --preset ${{ inputs.preset-name }} --target install --config ${{ matrix.build-type }} - - - name: CMake Package (cpack) - if: inputs.package == true - run: cpack --preset ${{ inputs.preset-name }} -C ${{ matrix.build-type }} - - - name: Perform CodeQL Analysis - if: inputs.analyze-codeql == true - uses: github/codeql-action/analyze@v2 - - - name: Publish Artifacts - if: inputs.publish-artifacts == true - uses: actions/upload-artifact@v3 - with: - name: release-package-${{ runner.os }}-${{ matrix.build-type }}-${{ matrix.config.arch != '' && matrix.config.arch || runner.arch }} - path: | - ${{ github.workspace }}/out/package/${{ inputs.preset-name }}/*.tar.* - ${{ github.workspace }}/out/package/${{ inputs.preset-name }}/*.zip