-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
130 lines (122 loc) · 4.43 KB
/
action.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
122
123
124
125
126
127
128
129
130
name: CMake Action
description: Configure, build, and test a CMake project
author: Alfi Maulana
branding:
color: gray-dark
icon: terminal
inputs:
source-dir:
description: The source directory of the CMake project
required: false
build-dir:
description: The build directory of the CMake project
required: false
generator:
description: The build system generator for the CMake project
required: false
c-compiler:
description: The preferred executable for compiling C language files
required: false
cxx-compiler:
description: The preferred executable for compiling C++ language files
required: false
c-flags:
description: Additional flags to pass when compiling C language files
required: false
cxx-flags:
description: Additional flags to pass when compiling C++ language files
required: false
options:
description: Additional options to pass during the CMake configuration
required: false
args:
description: Additional arguments to pass during the CMake configuration
required: false
run-build:
description: If enabled, it builds the project using CMake (true/false)
required: false
default: false
build-args:
description: Additional arguments to pass during the CMake build
required: false
run-test:
description: If enabled, it runs testing using CTest (true/false)
required: false
default: false
test-args:
description: Additional arguments to pass during the CTest run
required: false
runs:
using: composite
steps:
- name: Process the inputs
id: process_inputs
shell: bash
run: |
SOURCE_DIR="."
if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}"
fi
BUILD_DIR="build"
if [ -n '${{ inputs.build-dir }}' ]; then
BUILD_DIR="${{ inputs.build-dir }}"
elif [ -n "${{ inputs.source-dir }}" ]; then
BUILD_DIR="${{ inputs.source-dir }}/build"
fi
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
if [ -n '${{ inputs.generator }}' ]; then
ARGS="$ARGS -G '${{ inputs.generator }}'"
fi
if [ -n '${{ inputs.c-compiler }}' ]; then
ARGS="$ARGS -D CMAKE_C_COMPILER='${{ inputs.c-compiler }}'"
fi
if [ -n '${{ inputs.cxx-compiler }}' ]; then
ARGS="$ARGS -D CMAKE_CXX_COMPILER='${{ inputs.cxx-compiler }}'"
fi
if [ -n '${{ inputs.c-flags }}' ]; then
ARGS="$ARGS -D CMAKE_C_FLAGS='${{ inputs.c-flags }}'"
fi
if [ -n '${{ inputs.cxx-flags }}' ]; then
ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'"
fi
for OPT in ${{ inputs.options }}; do
ARGS="$ARGS -D $OPT"
done
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
fi
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
BUILD_ARGS="--build '$BUILD_DIR'"
if [ -n '${{ inputs.build-args }}' ]; then
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
fi
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi
if [ '${{ inputs.run-test }}' == 'true' ]; then
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
fi
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi
- name: Install Ninja
if: ${{ inputs.generator == 'Ninja' }}
shell: bash
run: |
case "$OSTYPE" in
darwin*) brew install ninja ;;
linux*) sudo apt install -y ninja-build ;;
*) choco install ninja ;;
esac
- name: Configure the CMake project
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
- name: Build targets
if: inputs.run-build != 'false' || inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}
- name: Run tests
if: inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}