Skip to content

Commit 57b701c

Browse files
committed
wip: packaging and github release action
1 parent 117707b commit 57b701c

4 files changed

Lines changed: 83 additions & 0 deletions

File tree

.github/release.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2023 Intercreate, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Authors: J.P. Hutchins <jp@intercreate.io>
5+
6+
name: Release
7+
permissions:
8+
contents: write
9+
10+
on:
11+
release:
12+
types: [published]
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Configure & run examples
21+
run: cmake -B build
22+
23+
- name: Package source code
24+
run: cmake --build build --target package
25+
26+
- name: Add packaged source code to release
27+
uses: svenstaro/upload-release-action@v2
28+
with:
29+
repo_token: ${{ secrets.GITHUB_TOKEN }}
30+
file: build/test_cmake.zip
31+
tag: ${{ github.ref }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2023 Intercreate, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Authors: J.P. Hutchins <jp@intercreate.io>
5+
6+
cmake_minimum_required(VERSION 3.20)
7+
project(test_cmake)
8+
9+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
10+
# We're in the root, define additional targets for developers.
11+
12+
add_subdirectory(examples)
13+
14+
# generate a package for distribution
15+
# reference: https://www.foonathan.net/2022/06/cmake-fetchcontent/
16+
set(package_files test_cmake.cmake LICENSE)
17+
add_custom_command(
18+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.zip
19+
COMMAND ${CMAKE_COMMAND} -E tar
20+
c ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.zip
21+
--format=zip
22+
-- ${package_files}
23+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
24+
DEPENDS ${package_files}
25+
)
26+
add_custom_target(package
27+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.zip
28+
)
29+
endif()

examples/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2023 Intercreate, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Authors: J.P. Hutchins <jp@intercreate.io>
5+
6+
cmake_minimum_required(VERSION 3.20)
7+
project(test_cmake_examples)
8+
9+
include(${CMAKE_CURRENT_SOURCE_DIR}/../test_cmake.cmake)
10+
11+
# Collect example folders
12+
file(GLOB examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*/tests.cmake)
13+
message(STATUS "Collected examples [ ${examples} ]")
14+
15+
# Run each example
16+
foreach(example ${examples})
17+
execute_process(
18+
COMMAND cmake "-P" "${CMAKE_CURRENT_SOURCE_DIR}/${example}"
19+
RESULT_VARIABLE res
20+
)
21+
assert(${res} EQUAL 0)
22+
endforeach()

0 commit comments

Comments
 (0)