diff --git a/.editorconfig b/.editorconfig index 69f7ddb..1df132f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,7 +12,7 @@ insert_final_newline = true indent_style = space indent_size = 4 -[*.{sh,bash,cmake,json}] +[*.{sh,bash,cmake,json,yaml}] indent_style = space indent_size = 2 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..885c622 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,43 @@ +name: Build +on: + pull_request: + push: + branches: + - "master" + tags: + - "v*" +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + /var/lib/apt/lists + /var/cache/apt/archives/**.deb + !/var/lib/apt/lists/partial + !/var/lib/apt/lists/lock + !/var/cache/apt/archives/partial + !/var/cache/apt/archives/lock + key: ${{ runner.os }}-apt-v1 + - uses: lukka/get-cmake@latest + - name: Setup APT packages + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends rpm + - name: Build release + run: ./build.sh pack + - name: Upload to GitHub artifact + uses: actions/upload-artifact@v3 + with: + name: dist + path: "build/dist/" + - name: Upload to GitHub release + uses: xresloader/upload-to-github-release@v1 + with: + file: "build/dist/*" + tags: true + draft: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index e824687..13b0bba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,3 +6,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_executable(trapit trapit.cc) install(TARGETS trapit) + +set(CPACK_PACKAGE_VENDOR "Jiangge Zhang ") +set(CPACK_PACKAGE_CONTACT "Jiangge Zhang ") +set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/dist") +set( + CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line utility that traps \ + short-lived processes to inspect them with PID-aware tools (e.g. strace)") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/tonyseek/trapit") +set(CPACK_STRIP_FILES TRUE) +set( + CPACK_SOURCE_IGNORE_FILES + "\\\\.git/" "\\\\.github/" "\\\\.sw[op]$" "/build/") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)") +include(CPack) diff --git a/build.sh b/build.sh index 658fd24..f4a2342 100755 --- a/build.sh +++ b/build.sh @@ -5,6 +5,7 @@ set -e SOURCE_DIR="$(pwd)" BUILD_DIR="${SOURCE_DIR}/build" BUILD_BIN="trapit" +PACK_DIR="${SOURCE_DIR}/build/dist" if ! [ -f "${SOURCE_DIR}/CMakeLists.txt" ]; then printf >&2 'ERROR: %s is not the source directory which includes %s' \ @@ -40,6 +41,27 @@ cmd_build() { cmake_build } +cmd_pack() { + cmd_clean + cmd_build + ( + cd "${BUILD_DIR}" + cpack -G TXZ --config CPackSourceConfig.cmake + cpack -G TXZ + if command -v dpkg > /dev/null; then + cpack -G DEB + else + printf >&2 '=> Skip to pack DEB because lack of "dpkg" (dpkg)\n' + fi + if command -v rpmbuild > /dev/null; then + cpack -G RPM + else + printf >&2 '=> Skip to pack RPM because lack of "rpm-tools" (rpmbuild)\n' + fi + rm -rf "${PACK_DIR}/_CPack_Packages" + ) +} + cmd_run() { cmd_build exec "${BUILD_DIR}/${BUILD_BIN}" "$@" @@ -64,6 +86,9 @@ case "$1" in build) cmd_build ;; + pack) + cmd_pack + ;; run) shift cmd_run "$@"