Skip to content

Commit

Permalink
Merge pull request #63 from microsoft/vcpkgbinarycaching
Browse files Browse the repository at this point in the history
Add action for building directly on the host with cmake.
  • Loading branch information
abeltrano authored Dec 10, 2023
2 parents 32e5f41 + d93c918 commit 9890a9d
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-with-docker/action.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
85 changes: 85 additions & 0 deletions .github/actions/build-with-host/action.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -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

141 changes: 127 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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

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
21 changes: 21 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -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' ]"
Loading

0 comments on commit 9890a9d

Please sign in to comment.