-
Notifications
You must be signed in to change notification settings - Fork 8
121 lines (105 loc) · 4.71 KB
/
build-and-test-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Build and test workflow
on:
workflow_call:
inputs:
platform:
description: "Platform"
required: true
type: string
build_type:
description: "Build type"
required: true
type: string
jobs:
build:
# Build platform
runs-on: ${{ inputs.platform }}
name: ${{ inputs.platform }}-${{ inputs.build_type }}
# The default compiler on macos is clang, switch to gcc. Specifying the version is necessary.
# It seems like gcc and g++ are symbolic links to the default clang and clang++ compilers, respectively.
# CMAKE_CXX_COMPILER_ID will evaluate to AppleClang rather than GNU on macos.
env:
CC: gcc-12
CXX: g++-12
# Build steps
steps:
# Step: Checkout
- name: Checkout
uses: actions/checkout@v4
# Workaround for getting "git describe --tags" to work in cmake/get_version_from_git.cmake (Build step)
with:
fetch-depth: 0
- name: Set Xcode version
if: inputs.platform == 'macos-13' || inputs.platform == 'macos-13-xlarge'
run: sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer
# Step: Set paths
- name: Set paths
id: paths
run: |
echo "build_dir=${{ github.workspace }}/build" >> $GITHUB_OUTPUT
echo "ext_deps_dir=${{ github.workspace }}/external_dependencies" >> $GITHUB_OUTPUT
echo "install_dir=${{ github.workspace }}/install" >> $GITHUB_OUTPUT
- name: Install system-provided dependencies
run: |
if [ "${{ runner.os }}" == "macOS" ]; then
brew install boost doxygen
elif [ "${{ runner.os }}" == "Linux" ]; then
sudo apt-get install libboost-all-dev doxygen
fi
# Step: Restore cached user-provided dependencies
- name: Restore cached user-provided dependencies
uses: actions/cache/restore@v3
id: restore-cached-external-dependencies
with:
key: ${{ inputs.platform }}-${{ inputs.build_type }}-cache-key
restore-keys: ${{ inputs.platform }}-${{ inputs.build_type }}-cache-key
path: ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c
# Step: Build and install user-provided dependencies, executes only if no cache restored
- name: Build and install user-provided dependencies
if: steps.restore-cached-external-dependencies.outputs.cache-hit != 'true'
# NetCDF Dependencies m4, curl, and openssl are provided by the build machine
run: >
pwsh ${{ github.workspace }}/scripts/install_netcdf_static.ps1
-WorkDir ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/work
-InstallDir ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install
-BuildType '${{ inputs.build_type }}'
-ParallelJobs 10
# Step: Cache user-provided dependencies, executes only if no cache restored
- name: Cache user-provided dependencies
uses: actions/cache/save@v3
if: steps.restore-cached-external-dependencies.outputs.cache-hit != 'true'
with:
key: ${{ inputs.platform }}-${{ inputs.build_type }}-cache-key
path: ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c
# Step: CMake configuration
- name: Configure
run: >
cmake
-S ${{ github.workspace }}
-B ${{ steps.paths.outputs.build_dir }}
-DCMAKE_BUILD_TYPE=${{ inputs.build_type }}
-DCMAKE_PREFIX_PATH=${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c
-DCMAKE_INSTALL_PREFIX=${{ steps.paths.outputs.install_dir }}
# Step: CMake build
- name: Build
run: cmake --build ${{ steps.paths.outputs.build_dir }} --config ${{ inputs.build_type }} -j
# Step: Test
# Works if runner.os == 'Linux' or runner.os == 'macOS'
# if runner.os == 'Windows', /inputs.build_type needs to be inserted before /tests
- name: Test
run: |
echo -e "\n*************** MeshKernel Tests ***************\n"
${{ steps.paths.outputs.build_dir }}/libs/MeshKernel/tests/MeshKernelUnitTests
echo -e "\n\n*************** MeshKernel API Tests ***************\n"
${{ steps.paths.outputs.build_dir }}/libs/MeshKernelApi/tests/MeshKernelApiUnitTests
# Step: CMake install
- name: Install
run: cmake --install ${{ steps.paths.outputs.build_dir }}
# Step: Upload artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: meshkernel-${{ inputs.platform }}-${{ inputs.build_type }}
path: ${{ steps.paths.outputs.install_dir }}
if-no-files-found: error