|
| 1 | +name: CMake Build Matrix |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build: |
| 7 | + name: ${{ matrix.config.name }} |
| 8 | + runs-on: ${{ matrix.config.os }} |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + config: |
| 13 | + - { |
| 14 | + name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz", |
| 15 | + os: windows-latest, |
| 16 | + build_type: "Release", cc: "cl", cxx: "cl", |
| 17 | + environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat" |
| 18 | + } |
| 19 | + - { |
| 20 | + name: "Windows Latest MinGW", artifact: "Windows-MinGW.tar.xz", |
| 21 | + os: windows-latest, |
| 22 | + build_type: "Release", cc: "gcc", cxx: "g++" |
| 23 | + } |
| 24 | + - { |
| 25 | + name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz", |
| 26 | + os: ubuntu-latest, |
| 27 | + build_type: "Release", cc: "gcc", cxx: "g++" |
| 28 | + } |
| 29 | + - { |
| 30 | + name: "macOS Latest Clang", artifact: "macOS.tar.xz", |
| 31 | + os: macos-latest, |
| 32 | + build_type: "Release", cc: "clang", cxx: "clang++" |
| 33 | + } |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v1 |
| 37 | + |
| 38 | + - name: Download Ninja and CMake |
| 39 | + id: cmake_and_ninja |
| 40 | + shell: cmake -P {0} |
| 41 | + run: | |
| 42 | + set(ninja_version "1.9.0") |
| 43 | + set(cmake_version "3.16.2") |
| 44 | + |
| 45 | + message(STATUS "Using host CMake version: ${CMAKE_VERSION}") |
| 46 | +
|
| 47 | + if ("${{ runner.os }}" STREQUAL "Windows") |
| 48 | + set(ninja_suffix "win.zip") |
| 49 | + set(cmake_suffix "win64-x64.zip") |
| 50 | + set(cmake_dir "cmake-${cmake_version}-win64-x64/bin") |
| 51 | + elseif ("${{ runner.os }}" STREQUAL "Linux") |
| 52 | + set(ninja_suffix "linux.zip") |
| 53 | + set(cmake_suffix "Linux-x86_64.tar.gz") |
| 54 | + set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin") |
| 55 | + elseif ("${{ runner.os }}" STREQUAL "macOS") |
| 56 | + set(ninja_suffix "mac.zip") |
| 57 | + set(cmake_suffix "Darwin-x86_64.tar.gz") |
| 58 | + set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin") |
| 59 | + endif() |
| 60 | +
|
| 61 | + set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}") |
| 62 | + file(DOWNLOAD "${ninja_url}" ./ninja.zip SHOW_PROGRESS) |
| 63 | + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ninja.zip) |
| 64 | +
|
| 65 | + set(cmake_url "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-${cmake_suffix}") |
| 66 | + file(DOWNLOAD "${cmake_url}" ./cmake.zip SHOW_PROGRESS) |
| 67 | + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./cmake.zip) |
| 68 | +
|
| 69 | + # Save the path for other steps |
| 70 | + file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/${cmake_dir}" cmake_dir) |
| 71 | + message("::set-output name=cmake_dir::${cmake_dir}") |
| 72 | +
|
| 73 | + if (NOT "${{ runner.os }}" STREQUAL "Windows") |
| 74 | + execute_process( |
| 75 | + COMMAND chmod +x ninja |
| 76 | + COMMAND chmod +x ${cmake_dir}/cmake |
| 77 | + ) |
| 78 | + endif() |
| 79 | +
|
| 80 | + - name: Configure |
| 81 | + shell: cmake -P {0} |
| 82 | + run: | |
| 83 | + set(ENV{CC} ${{ matrix.config.cc }}) |
| 84 | + set(ENV{CXX} ${{ matrix.config.cxx }}) |
| 85 | +
|
| 86 | + if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") |
| 87 | + execute_process( |
| 88 | + COMMAND "${{ matrix.config.environment_script }}" && set |
| 89 | + OUTPUT_FILE environment_script_output.txt |
| 90 | + ) |
| 91 | + file(STRINGS environment_script_output.txt output_lines) |
| 92 | + foreach(line IN LISTS output_lines) |
| 93 | + if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$") |
| 94 | + set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}") |
| 95 | + endif() |
| 96 | + endforeach() |
| 97 | + endif() |
| 98 | +
|
| 99 | + file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/ninja" ninja_program) |
| 100 | +
|
| 101 | + execute_process( |
| 102 | + COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake |
| 103 | + -S . |
| 104 | + -B build |
| 105 | + -D CMAKE_BUILD_TYPE=${{ matrix.config.build_type }} |
| 106 | + -G Ninja |
| 107 | + -D CMAKE_MAKE_PROGRAM=${ninja_program} |
| 108 | + RESULT_VARIABLE result |
| 109 | + ) |
| 110 | + if (NOT result EQUAL 0) |
| 111 | + message(FATAL_ERROR "Bad exit status") |
| 112 | + endif() |
| 113 | +
|
| 114 | +
|
| 115 | + - name: Build |
| 116 | + shell: cmake -P {0} |
| 117 | + run: | |
| 118 | + set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ") |
| 119 | +
|
| 120 | + if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") |
| 121 | + file(STRINGS environment_script_output.txt output_lines) |
| 122 | + foreach(line IN LISTS output_lines) |
| 123 | + if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$") |
| 124 | + set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}") |
| 125 | + endif() |
| 126 | + endforeach() |
| 127 | + endif() |
| 128 | +
|
| 129 | + execute_process( |
| 130 | + COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build build |
| 131 | + RESULT_VARIABLE result |
| 132 | + ) |
| 133 | + if (NOT result EQUAL 0) |
| 134 | + message(FATAL_ERROR "Bad exit status") |
| 135 | + endif() |
| 136 | +
|
| 137 | +
|
| 138 | + - name: Run tests |
| 139 | + shell: cmake -P {0} |
| 140 | + run: | |
| 141 | + include(ProcessorCount) |
| 142 | + ProcessorCount(N) |
| 143 | +
|
| 144 | + execute_process( |
| 145 | + COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/ctest -j ${N} |
| 146 | + WORKING_DIRECTORY build |
| 147 | + RESULT_VARIABLE result |
| 148 | + ) |
| 149 | + if (NOT result EQUAL 0) |
| 150 | + message(FATAL_ERROR "Running tests failed!") |
| 151 | + endif() |
| 152 | +
|
| 153 | +
|
| 154 | + - name: Install Strip |
| 155 | + run: ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --install build --prefix instdir --strip |
| 156 | + |
| 157 | + |
| 158 | + - name: Pack |
| 159 | + working-directory: instdir |
| 160 | + run: ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake -E tar cJfv ../${{ matrix.config.artifact }} . |
| 161 | + |
| 162 | + |
| 163 | + - name: Upload |
| 164 | + uses: actions/upload-artifact@v1 |
| 165 | + with: |
| 166 | + path: ./${{ matrix.config.artifact }} |
| 167 | + name: ${{ matrix.config.artifact }} |
| 168 | + |
| 169 | + release: |
| 170 | + if: contains(github.ref, 'tags/v') |
| 171 | + runs-on: ubuntu-latest |
| 172 | + needs: build |
| 173 | + |
| 174 | + steps: |
| 175 | + - name: Create Release |
| 176 | + id: create_release |
| 177 | + uses: actions/create-release@v1.0.0 |
| 178 | + env: |
| 179 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 180 | + with: |
| 181 | + tag_name: ${{ github.ref }} |
| 182 | + release_name: Release ${{ github.ref }} |
| 183 | + draft: false |
| 184 | + prerelease: false |
| 185 | + |
| 186 | + - name: Store Release url |
| 187 | + run: | |
| 188 | + echo "${{ steps.create_release.outputs.upload_url }}" > ./upload_url |
| 189 | +
|
| 190 | + - uses: actions/upload-artifact@v1 |
| 191 | + with: |
| 192 | + path: ./upload_url |
| 193 | + name: upload_url |
| 194 | + |
| 195 | + publish: |
| 196 | + if: contains(github.ref, 'tags/v') |
| 197 | + name: ${{ matrix.config.name }} |
| 198 | + runs-on: ${{ matrix.config.os }} |
| 199 | + strategy: |
| 200 | + fail-fast: false |
| 201 | + matrix: |
| 202 | + config: |
| 203 | + - { |
| 204 | + name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz", |
| 205 | + os: ubuntu-latest |
| 206 | + } |
| 207 | + - { |
| 208 | + name: "Windows Latest MinGW", artifact: "Windows-MinGW.tar.xz", |
| 209 | + os: ubuntu-latest |
| 210 | + } |
| 211 | + - { |
| 212 | + name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz", |
| 213 | + os: ubuntu-latest |
| 214 | + } |
| 215 | + - { |
| 216 | + name: "macOS Latest Clang", artifact: "macOS.tar.xz", |
| 217 | + os: ubuntu-latest |
| 218 | + } |
| 219 | + needs: release |
| 220 | + |
| 221 | + steps: |
| 222 | + - name: Download artifact |
| 223 | + uses: actions/download-artifact@v1 |
| 224 | + with: |
| 225 | + name: ${{ matrix.config.artifact }} |
| 226 | + path: ./ |
| 227 | + |
| 228 | + - name: Download URL |
| 229 | + uses: actions/download-artifact@v1 |
| 230 | + with: |
| 231 | + name: upload_url |
| 232 | + path: ./ |
| 233 | + - id: set_upload_url |
| 234 | + run: | |
| 235 | + upload_url=`cat ./upload_url` |
| 236 | + echo ::set-output name=upload_url::$upload_url |
| 237 | +
|
| 238 | + - name: Upload to Release |
| 239 | + id: upload_to_release |
| 240 | + uses: actions/upload-release-asset@v1.0.1 |
| 241 | + env: |
| 242 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 243 | + with: |
| 244 | + upload_url: ${{ steps.set_upload_url.outputs.upload_url }} |
| 245 | + asset_path: ./${{ matrix.config.artifact }} |
| 246 | + asset_name: ${{ matrix.config.artifact }} |
| 247 | + asset_content_type: application/x-gtar |
0 commit comments