Skip to content

Commit 12261a6

Browse files
committed
save workflow scripts in files
1 parent 1b29501 commit 12261a6

File tree

5 files changed

+162
-184
lines changed

5 files changed

+162
-184
lines changed

.github/scripts/build.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/local/bin/cmake -P
2+
3+
set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ")
4+
5+
if ("$ENV{RUNNER_OS}" STREQUAL "Windows" AND NOT "x$ENV{ENVIRONMENT_SCRIPT}" STREQUAL "x")
6+
file(STRINGS environment_script_output.txt output_lines)
7+
foreach(line IN LISTS output_lines)
8+
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
9+
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
10+
endif()
11+
endforeach()
12+
endif()
13+
14+
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}" ccache_basedir)
15+
set(ENV{CCACHE_BASEDIR} "${ccache_basedir}")
16+
set(ENV{CCACHE_DIR} "${ccache_basedir}/.ccache")
17+
set(ENV{CCACHE_COMPRESS} "true")
18+
set(ENV{CCACHE_COMPRESSLEVEL} "6")
19+
set(ENV{CCACHE_MAXSIZE} "400M")
20+
if ("$ENV{CXX}" STREQUAL "cl")
21+
set(ENV{CCACHE_MAXSIZE} "600M")
22+
endif()
23+
24+
execute_process(COMMAND ccache -p)
25+
execute_process(COMMAND ccache -z)
26+
27+
execute_process(
28+
COMMAND cmake --build build --config $ENV{BUILD_TYPE}
29+
RESULT_VARIABLE result
30+
OUTPUT_VARIABLE output
31+
ERROR_VARIABLE output
32+
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE
33+
)
34+
if (NOT result EQUAL 0)
35+
string(REGEX MATCH "FAILED:.*$" error_message "${output}")
36+
string(REPLACE "\n" "%0A" error_message "${error_message}")
37+
message("::error::${error_message}")
38+
message(FATAL_ERROR "Build failed")
39+
endif()

.github/scripts/configure.cmake

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/local/bin/cmake -P
2+
3+
if ("$ENV{RUNNER_OS}" STREQUAL "Windows" AND NOT "x$ENV{ENVIRONMENT_SCRIPT}" STREQUAL "x")
4+
execute_process(
5+
COMMAND "$ENV{ENVIRONMENT_SCRIPT}" && set
6+
OUTPUT_FILE environment_script_output.txt
7+
)
8+
file(STRINGS environment_script_output.txt output_lines)
9+
foreach(line IN LISTS output_lines)
10+
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
11+
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
12+
endif()
13+
endforeach()
14+
endif()
15+
16+
set(path_separator ":")
17+
if ("$ENV{RUNNER_OS}" STREQUAL "Windows")
18+
set(path_separator ";")
19+
endif()
20+
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
21+
22+
if (NOT "$ENV{RUNNER_OS}" STREQUAL "Linux")
23+
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake" toolchain_file)
24+
25+
execute_process(
26+
COMMAND cmake
27+
-S .
28+
-B build
29+
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
30+
-G Ninja
31+
-D CMAKE_MAKE_PROGRAM=ninja
32+
-D CMAKE_C_COMPILER_LAUNCHER=ccache
33+
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
34+
-D CMAKE_TOOLCHAIN_FILE=${toolchain_file} -DVCPKG_TARGET_TRIPLET=$ENV{VCPKG_TRIPLET} -DVCPKG_HOST_TRIPLET=$ENV{VCPKG_TRIPLET}
35+
RESULT_VARIABLE result
36+
)
37+
else()
38+
execute_process(
39+
COMMAND cmake
40+
-S .
41+
-B build
42+
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
43+
-G Ninja
44+
-D CMAKE_MAKE_PROGRAM=ninja
45+
-D CMAKE_C_COMPILER_LAUNCHER=ccache
46+
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
47+
RESULT_VARIABLE result
48+
)
49+
endif()
50+
51+
if (NOT result EQUAL 0)
52+
message(FATAL_ERROR "Bad exit status")
53+
endif()

.github/scripts/test.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/local/bin/cmake -P
2+
3+
include(ProcessorCount)
4+
ProcessorCount(N)
5+
6+
set(ENV{CTEST_OUTPUT_ON_FAILURE} "ON")
7+
8+
execute_process(
9+
COMMAND ctest -j ${N} -C $ENV{BUILD_TYPE}
10+
WORKING_DIRECTORY build
11+
RESULT_VARIABLE result
12+
OUTPUT_VARIABLE output
13+
ERROR_VARIABLE output
14+
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE
15+
)
16+
if (NOT result EQUAL 0)
17+
string(REGEX MATCH "[0-9]+% tests.*[0-9.]+ sec.*$" test_results "${output}")
18+
string(REPLACE "\n" "%0A" test_results "${test_results}")
19+
message("::error::${test_results}")
20+
message(FATAL_ERROR "Running tests failed!")
21+
endif()

.github/workflows/cmake.yml

Lines changed: 45 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ on:
1919
- v**
2020

2121
env:
22-
CMAKE_VERSION: 3.26.3
23-
NINJA_VERSION: 1.11.1
2422
BUILD_TYPE: Release
25-
CCACHE_VERSION: 4.7.3
2623

2724
jobs:
2825
build:
@@ -58,53 +55,42 @@ jobs:
5855
vcpkg_triplet: x64-osx-release
5956
}
6057

58+
defaults:
59+
run:
60+
# Run scripts with project directory as working directory
61+
working-directory: ./
62+
# Use bash as default shell
63+
shell: bash
64+
6165
steps:
6266
- uses: actions/checkout@v3
6367

64-
- name: Download Ninja and CMake
65-
shell: cmake -P {0}
68+
- name: Install Ninja
69+
shell: bash
6670
run: |
67-
set(cmake_version $ENV{CMAKE_VERSION})
68-
set(ninja_version $ENV{NINJA_VERSION})
69-
70-
message(STATUS "Using host CMake version: ${CMAKE_VERSION}")
71-
72-
if ("${{ runner.os }}" STREQUAL "Windows")
73-
set(ninja_suffix "win.zip")
74-
set(cmake_suffix "windows-x86_64.zip")
75-
set(cmake_dir "cmake-${cmake_version}-windows-x86_64/bin")
76-
elseif ("${{ runner.os }}" STREQUAL "Linux")
77-
set(ninja_suffix "linux.zip")
78-
set(cmake_suffix "linux-x86_64.tar.gz")
79-
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin")
80-
elseif ("${{ runner.os }}" STREQUAL "macOS")
81-
set(ninja_suffix "mac.zip")
82-
set(cmake_suffix "macos-universal.tar.gz")
83-
set(cmake_dir "cmake-${cmake_version}-macos-universal/CMake.app/Contents/bin")
84-
endif()
85-
86-
set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
87-
file(DOWNLOAD "${ninja_url}" ./ninja.zip SHOW_PROGRESS)
88-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ninja.zip)
89-
90-
set(cmake_url "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-${cmake_suffix}")
91-
file(DOWNLOAD "${cmake_url}" ./cmake.zip SHOW_PROGRESS)
92-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./cmake.zip)
93-
94-
# Add to PATH environment variable
95-
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/${cmake_dir}" cmake_dir)
96-
set(path_separator ":")
97-
if ("${{ runner.os }}" STREQUAL "Windows")
98-
set(path_separator ";")
99-
endif()
100-
file(APPEND "$ENV{GITHUB_PATH}" "$ENV{GITHUB_WORKSPACE}${path_separator}${cmake_dir}")
71+
if [ "$RUNNER_OS" == "Linux" ]; then
72+
sudo apt-get install -y ninja-build
73+
elif [ "$RUNNER_OS" == "Windows" ]; then
74+
choco install ninja
75+
elif [ "$RUNNER_OS" == "macOS" ]; then
76+
brew install ninja
77+
fi
78+
79+
- name: Install ccache
80+
shell: bash
81+
run: |
82+
if [ "$RUNNER_OS" == "Linux" ]; then
83+
sudo apt-get install -y ccache
84+
elif [ "$RUNNER_OS" == "Windows" ]; then
85+
choco install ccache
86+
elif [ "$RUNNER_OS" == "macOS" ]; then
87+
brew install ccache
88+
fi
10189
102-
if (NOT "${{ runner.os }}" STREQUAL "Windows")
103-
execute_process(
104-
COMMAND chmod +x ninja
105-
COMMAND chmod +x ${cmake_dir}/cmake
106-
)
107-
endif()
90+
- name: Install Ubuntu dependencies
91+
if: runner.os == 'Linux'
92+
shell: bash
93+
run: sudo apt-get install -y libwxgtk3.0-gtk3-dev libgtest-dev rpm
10894

10995
- name: vcpkg build
11096
if: runner.os != 'Linux'
@@ -116,19 +102,6 @@ jobs:
116102
revision: master
117103
token: ${{ github.token }}
118104

119-
- name: Install Ubuntu dependencies
120-
if: runner.os == 'Linux'
121-
shell: bash
122-
run: sudo apt-get -y install libwxgtk3.0-gtk3-dev rpm libgtest-dev
123-
124-
- name: Download ccache
125-
id: ccache
126-
shell: cmake -P {0}
127-
run: |
128-
set(ccache_url "https://github.com/cristianadam/ccache/releases/download/v$ENV{CCACHE_VERSION}/${{ runner.os }}.tar.xz")
129-
file(DOWNLOAD "${ccache_url}" ./ccache.tar.xz SHOW_PROGRESS)
130-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ccache.tar.xz)
131-
132105
- name: Prepare ccache timestamp
133106
id: ccache_cache_timestamp
134107
shell: cmake -P {0}
@@ -145,115 +118,23 @@ jobs:
145118
${{ matrix.config.name }}-ccache-
146119
147120
- name: Configure
148-
shell: cmake -P {0}
121+
env:
122+
CC: ${{ matrix.config.cc }}
123+
CXX: ${{ matrix.config.cxx }}
124+
ENVIRONMENT_SCRIPT: ${{ matrix.config.environment_script }}
125+
RUNNER_OS: ${{ runner.os }}
126+
VCPKG_TRIPLET: ${{ matrix.config.vcpkg_triplet }}
149127
run: |
150-
set(ENV{CC} ${{ matrix.config.cc }})
151-
set(ENV{CXX} ${{ matrix.config.cxx }})
152-
153-
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
154-
execute_process(
155-
COMMAND "${{ matrix.config.environment_script }}" && set
156-
OUTPUT_FILE environment_script_output.txt
157-
)
158-
file(STRINGS environment_script_output.txt output_lines)
159-
foreach(line IN LISTS output_lines)
160-
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
161-
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
162-
endif()
163-
endforeach()
164-
endif()
165-
166-
set(path_separator ":")
167-
if ("${{ runner.os }}" STREQUAL "Windows")
168-
set(path_separator ";")
169-
endif()
170-
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
171-
172-
if (NOT "${{ runner.os }}" STREQUAL "Linux")
173-
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake" toolchain_file)
174-
175-
if("${{ runner.os }}" STREQUAL "Windows" AND ${{ matrix.config.cxx }} STREQUAL "g++")
176-
execute_process(
177-
COMMAND cmake
178-
-S .
179-
-B build
180-
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
181-
-G "MinGW Makefiles"
182-
-D CMAKE_C_COMPILER_LAUNCHER=ccache
183-
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
184-
-D CMAKE_TOOLCHAIN_FILE=${toolchain_file} -DVCPKG_TARGET_TRIPLET=${{ matrix.config.vcpkg_triplet }} -DVCPKG_HOST_TRIPLET=${{ matrix.config.vcpkg_triplet }}
185-
RESULT_VARIABLE result
186-
)
187-
else()
188-
execute_process(
189-
COMMAND cmake
190-
-S .
191-
-B build
192-
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
193-
-D CMAKE_C_COMPILER_LAUNCHER=ccache
194-
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
195-
-D CMAKE_TOOLCHAIN_FILE=${toolchain_file} -DVCPKG_TARGET_TRIPLET=${{ matrix.config.vcpkg_triplet }} -DVCPKG_HOST_TRIPLET=${{ matrix.config.vcpkg_triplet }}
196-
RESULT_VARIABLE result
197-
)
198-
endif()
199-
else()
200-
execute_process(
201-
COMMAND cmake
202-
-S .
203-
-B build
204-
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
205-
-G Ninja
206-
-D CMAKE_MAKE_PROGRAM=ninja
207-
-D CMAKE_C_COMPILER_LAUNCHER=ccache
208-
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
209-
RESULT_VARIABLE result
210-
)
211-
endif()
212-
213-
if (NOT result EQUAL 0)
214-
message(FATAL_ERROR "Bad exit status")
215-
endif()
128+
chmod a+x ./.github/scripts/*.cmake
129+
cmake -P ./.github/scripts/configure.cmake
216130
217131
- name: Build
218-
shell: cmake -P {0}
132+
env:
133+
CXX: ${{ matrix.config.cxx }}
134+
ENVIRONMENT_SCRIPT: ${{ matrix.config.environment_script }}
135+
RUNNER_OS: ${{ runner.os }}
219136
run: |
220-
set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ")
221-
222-
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
223-
file(STRINGS environment_script_output.txt output_lines)
224-
foreach(line IN LISTS output_lines)
225-
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
226-
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
227-
endif()
228-
endforeach()
229-
endif()
230-
231-
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}" ccache_basedir)
232-
set(ENV{CCACHE_BASEDIR} "${ccache_basedir}")
233-
set(ENV{CCACHE_DIR} "${ccache_basedir}/.ccache")
234-
set(ENV{CCACHE_COMPRESS} "true")
235-
set(ENV{CCACHE_COMPRESSLEVEL} "6")
236-
set(ENV{CCACHE_MAXSIZE} "400M")
237-
if ("${{ matrix.config.cxx }}" STREQUAL "cl")
238-
set(ENV{CCACHE_MAXSIZE} "600M")
239-
endif()
240-
241-
execute_process(COMMAND ccache -p)
242-
execute_process(COMMAND ccache -z)
243-
244-
execute_process(
245-
COMMAND cmake --build build --config $ENV{BUILD_TYPE}
246-
RESULT_VARIABLE result
247-
OUTPUT_VARIABLE output
248-
ERROR_VARIABLE output
249-
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE
250-
)
251-
if (NOT result EQUAL 0)
252-
string(REGEX MATCH "FAILED:.*$" error_message "${output}")
253-
string(REPLACE "\n" "%0A" error_message "${error_message}")
254-
message("::error::${error_message}")
255-
message(FATAL_ERROR "Build failed")
256-
endif()
137+
cmake -P ./.github/scripts/build.cmake
257138
258139
- name: ccache statistics
259140
shell: cmake -P {0}
@@ -265,27 +146,7 @@ jobs:
265146
execute_process(COMMAND ccache -s)
266147
267148
- name: Run tests
268-
shell: cmake -P {0}
269-
run: |
270-
include(ProcessorCount)
271-
ProcessorCount(N)
272-
273-
set(ENV{CTEST_OUTPUT_ON_FAILURE} "ON")
274-
275-
execute_process(
276-
COMMAND ctest -j ${N} -C $ENV{BUILD_TYPE}
277-
WORKING_DIRECTORY build
278-
RESULT_VARIABLE result
279-
OUTPUT_VARIABLE output
280-
ERROR_VARIABLE output
281-
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE
282-
)
283-
if (NOT result EQUAL 0)
284-
string(REGEX MATCH "[0-9]+% tests.*[0-9.]+ sec.*$" test_results "${output}")
285-
string(REPLACE "\n" "%0A" test_results "${test_results}")
286-
message("::error::${test_results}")
287-
message(FATAL_ERROR "Running tests failed!")
288-
endif()
149+
run: cmake -P ./.github/scripts/test.cmake
289150

290151
- name: Install Strip
291152
run: cmake --install build --prefix instdir --strip

0 commit comments

Comments
 (0)