diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6094ad4..1383f5b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,96 +13,92 @@ jobs: os: [macos-13, macos-14] runs-on: ${{ matrix.os }} outputs: - hash-darwin-x86_64: ${{ steps.hash.outputs.hash-darwin-x86_64 }} - hash-darwin-arm64: ${{ steps.hash.outputs.hash-darwin-arm64 }} - checksum-darwin-x86_64: ${{ steps.hash.outputs.checksum-darwin-x86_64 }} - checksum-darwin-arm64: ${{ steps.hash.outputs.checksum-darwin-arm64 }} - archive-darwin-x86_64: ${{ steps.archive.outputs.archive-darwin-x86_64 }} - archive-darwin-arm64: ${{ steps.archive.outputs.archive-darwin-arm64 }} + artifact-filename-darwin-arm64: ${{ steps.artifact.outputs.artifact-filename-darwin-arm64 }} + artifact-filename-darwin-x86_64: ${{ steps.artifact.outputs.artifact-filename-darwin-x86_64 }} + sha256-checksum-darwin-arm64: ${{ steps.checksum.outputs.sha256-checksum-darwin-arm64 }} + sha256-checksum-darwin-x86_64: ${{ steps.checksum.outputs.sha256-checksum-darwin-x86_64 }} + sha256-filename-darwin-arm64: ${{ steps.checksum.outputs.sha256-filename-darwin-arm64 }} + sha256-filename-darwin-x86_64: ${{ steps.checksum.outputs.sha256-filename-darwin-x86_64 }} steps: - name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - - name: Install dependencies + - name: Install build dependencies run: brew install popt + - name: Install build tools + run: brew install just - id: arch name: Get machine hardware name run: | + set -euo pipefail arch=$(uname -m) if [[ "${arch}" != "x86_64" && "${arch}" != "arm64" ]]; then echo "Unexpected machine hardware name: ${arch}" exit 1 fi - echo "name=${arch}" >> "$GITHUB_OUTPUT" + echo "name=${arch}" >> "${GITHUB_OUTPUT}" - id: artifact name: Generate build artifact + env: + ARCHITECTURE: ${{ steps.arch.outputs.name }} run: | - cmake -S . -B build - cmake --build build - - output_dir="build/src" - artifact="flog" - - if [[ ! -f "${output_dir}/${artifact}" ]]; then - echo "Failed to generate build artifact: ${output_dir}/${artifact}" - exit 1 + set -euo pipefail + just package "${GITHUB_REF_NAME}" + artifact="flog-${GITHUB_REF_NAME}-darwin-${ARCHITECTURE}.tar.xz" + if [[ ! -f "${artifact}" ]]; then + echo "Failed to generated expected build artifact: ${artifact}" fi - - echo "dir=${output_dir}" >> "$GITHUB_OUTPUT" - echo "name=${artifact}" >> "$GITHUB_OUTPUT" - - id: archive - name: Compress build artifact - run: | - archive="flog-${GITHUB_REF_NAME}-darwin-${{ steps.arch.outputs.name }}.tar.xz" - tar -cvJf "${archive}" -C "${{ steps.artifact.outputs.dir }}" "${{ steps.artifact.outputs.name }}" - echo "name=${archive}" >> "$GITHUB_OUTPUT" - echo "archive-darwin-${{ steps.arch.outputs.name }}=${archive}" >> "$GITHUB_OUTPUT" - - id: hash - name: Generate build artifact hash + echo "name=${artifact}" >> "${GITHUB_OUTPUT}" + echo "artifact-filename-darwin-${{ steps.arch.outputs.name }}=${archive}" >> "${GITHUB_OUTPUT}" + - id: checksum + name: Generate build artifact SHA-256 checksum file + env: + ARCHITECTURE: ${{ steps.arch.outputs.name }} + ARTIFACT_NAME: ${{ steps.artifact.outputs.name }} run: | - set -o pipefail - shasum -a 256 "${{ steps.archive.outputs.name }}" > "${{ steps.archive.outputs.name }}.sha256" - b64_hash=$(cat "${{ steps.archive.outputs.name }}.sha256" | base64) - echo "hash-darwin-${{ steps.arch.outputs.name }}=${b64_hash}" >> "$GITHUB_OUTPUT" - echo "checksum-darwin-${{ steps.arch.outputs.name }}=${{ steps.archive.outputs.name }}.sha256" >> "$GITHUB_OUTPUT" + set -euo pipefail + shasum -a 256 "${ARTIFACT_NAME}" > "${ARTIFACT_NAME}.sha256" + echo "sha256-checksum-darwin-${ARCHITECTURE}=$(cat "${ARTIFACT_NAME}.sha256" | base64)" >> "${GITHUB_OUTPUT}" + echo "sha256-filename-darwin-${ARCHITECTURE}=${ARTIFACT_NAME}.sha256" >> "${GITHUB_OUTPUT}" - name: Upload build artifact uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: - name: ${{ steps.archive.outputs.name }} - path: ${{ steps.archive.outputs.name }} + name: ${{ steps.artifact.outputs.name }} + path: ${{ steps.artifact.outputs.name }} if-no-files-found: error retention-days: 7 - name: Upload SHA-256 checksum file uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: - name: ${{ steps.archive.outputs.name }}.sha256 - path: ${{ steps.archive.outputs.name }}.sha256 + name: ${{ steps.artifact.outputs.name }}.sha256 + path: ${{ steps.artifact.outputs.name }}.sha256 if-no-files-found: error retention-days: 7 - combine-hashes: + combine-checksums: needs: [build] runs-on: ubuntu-latest outputs: - hashes: ${{ steps.hashes.outputs.hashes }} + checksums: ${{ steps.checksums.outputs.combined }} env: - HASHES: ${{ toJSON(needs.build.outputs) }} + CHECKSUMS: ${{ toJSON(needs.build.outputs) }} steps: - - id: hashes + - id: checksums run: | - echo "$HASHES" | jq -r 'with_entries(select(.key | match("hash-.*-.*")))[] | @base64d' | sed "/^$/d" > hashes.txt - echo "hashes=$(cat hashes.txt | base64 -w0)" >> "$GITHUB_OUTPUT" + set -euo pipefail + echo "${CHECKSUMS}" | jq -r 'with_entries(select(.key | match("sha256-checksum-.*-.*")))[] | @base64d' | sed "/^$/d" > checksums.txt + echo "combined=$(cat checksums.txt | base64 -w0)" >> "${GITHUB_OUTPUT}" provenance: - needs: [build, combine-hashes] + needs: [build, combine-checksums] permissions: actions: read id-token: write contents: write uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.10.0 # Must specify version tag; see https://github.com/slsa-framework/slsa-verifier/issues/12 with: - base64-subjects: ${{ needs.combine-hashes.outputs.hashes }} - provenance-name: flog.multiple.intoto.jsonl + base64-subjects: ${{ needs.combine-checksums.outputs.checksums }} + provenance-name: flog-${{ github.ref_name }}.intoto.jsonl upload-assets: ${{ startsWith(github.ref, 'refs/tags/v') }} release: - needs: [build, combine-hashes, provenance] + needs: [build, combine-checksums, provenance] permissions: contents: write runs-on: ubuntu-latest @@ -111,24 +107,24 @@ jobs: - name: Download x86_64 build artifact uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: - name: ${{ needs.build.outputs.archive-darwin-x86_64 }} + name: ${{ needs.build.outputs.artifact-filename-darwin-x86_64 }} - name: Download x86_64 SHA-256 checksum file uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: - name: ${{ needs.build.outputs.checksum-darwin-x86_64 }} + name: ${{ needs.build.outputs.sha256-filename-darwin-x86_64 }} - name: Download arm64 build artifact uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: - name: ${{ needs.build.outputs.archive-darwin-arm64 }} + name: ${{ needs.build.outputs.artifact-filename-darwin-arm64 }} - name: Download arm64 SHA-256 checksum file uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: - name: ${{ needs.build.outputs.checksum-darwin-arm64 }} + name: ${{ needs.build.outputs.sha256-filename-darwin-arm64 }} - name: Upload release assets uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 with: files: | - ${{ needs.build.outputs.archive-darwin-x86_64 }} - ${{ needs.build.outputs.checksum-darwin-x86_64 }} - ${{ needs.build.outputs.archive-darwin-arm64 }} - ${{ needs.build.outputs.checksum-darwin-arm64 }} + ${{ needs.build.outputs.artifact-filename-darwin-x86_64 }} + ${{ needs.build.outputs.sha256-filename-darwin-x86_64 }} + ${{ needs.build.outputs.artifact-filename-darwin-arm64 }} + ${{ needs.build.outputs.sha256-filename-darwin-arm64 }} diff --git a/.gitignore b/.gitignore index 60ddddc..7021c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ codeql-database/ codeql-analysis.sarif +man/flog.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index ff87af8..f3135f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) find_package(PkgConfig REQUIRED) pkg_check_modules(POPT REQUIRED popt>=1.19) -if (NOT UNIT_TESTING) - message(STATUS "Building program target") - add_subdirectory(src) -else() - message(STATUS "Building unit test targets") +add_subdirectory(src bin) + +if (UNIT_TESTING) enable_testing() add_subdirectory(test) endif() diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..fe1bdfe --- /dev/null +++ b/Justfile @@ -0,0 +1,70 @@ +arch := `uname -m` +build_dir := "build" +debug_dir := build_dir / "debug" +release_dir := build_dir / "release" +debug_target := debug_dir / "bin" / "flog" +release_target := release_dir / "bin" / "flog" +man_dir := "man" +man_source := man_dir / "flog.1.md" +man_target := man_dir / "flog.1" + +# generate build artifacts and run unit tests +@all: build test + +# generate debug build +@build: + #!/usr/bin/env bash + set -euo pipefail + if [[ ! -d "{{debug_dir}}" ]]; then + cmake -S . -B "{{debug_dir}}" -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=on + fi + cmake --build "{{debug_dir}}" + +# generate release build +@build-release: + #!/usr/bin/env bash + set -euo pipefail + if [[ ! -d "{{release_dir}}" ]]; then + cmake -S . -B "{{release_dir}}" -DCMAKE_BUILD_TYPE=Release -DUNIT_TESTING=on + fi + cmake --build "{{release_dir}}" + +# run debug build unit tests +@test: build + ctest -V --test-dir "{{debug_dir}}/test" + +# run release build unit tests +@test-release: build-release + ctest -V --test-dir "{{release_dir}}/test" + +# remove build directories and artifacts +@clean: + rm -rf "{{build_dir}}" "{{man_target}}" *.xz + +# build the man page +@man: + pandoc --standalone -f markdown -t man "{{man_source}}" > "{{man_target}}" + +# build and show the man page +@show-man: man + man "{{man_target}}" + +# generate release package +@package version: build-release test-release man + #!/bin/bash + set -euo pipefail + echo "Packaging with version number: {{version}} for architecture: {{arch}}" + + tmp_dir=$(mktemp -d) + tar_dir="flog-{{version}}" + tar_file="flog-{{version}}-darwin-{{arch}}.tar.xz" + + mkdir -p "${tmp_dir}/${tar_dir}/bin" + mkdir -p "${tmp_dir}/${tar_dir}/usr/share/man/man1" + + cp "{{release_target}}" "${tmp_dir}/${tar_dir}/bin/" + cp "{{man_target}}" "${tmp_dir}/${tar_dir}/usr/share/man/man1/" + + tar -C "${tmp_dir}" -cvJf "${tar_file}" "${tar_dir}" + + echo "Generated release package: ${tar_file}" diff --git a/man/flog.1 b/man/flog.1 deleted file mode 100644 index fe6bac4..0000000 --- a/man/flog.1 +++ /dev/null @@ -1,87 +0,0 @@ -.\" Automatically generated by Pandoc 3.0.1 -.\" -.\" Define V font for inline verbatim, using C font in formats -.\" that render this, and otherwise B font. -.ie "\f[CB]x\f[]"x" \{\ -. ftr V B -. ftr VI BI -. ftr VB B -. ftr VBI BI -.\} -.el \{\ -. ftr V CR -. ftr VI CI -. ftr VB CB -. ftr VBI CBI -.\} -.TH "flog" "1" "" "Version 1.4.0" "Flog User\[cq]s Guide" -.hy -.SH NAME -.PP -\f[B]flog\f[R] \[em] write log messages to the unified logging system -.SH SYNOPSIS -.PP -\f[B]flog\f[R] [\f[I]options\f[R]] \f[I]message\f[R] -.SH DESCRIPTION -.PP -\f[I]flog\f[R] is used to write log messages to the unified logging -system. -Log messages may include a \f[I]subsystem\f[R] and \f[I]category\f[R] -name for the purposes of filtering, or to customise the logging -behaviour of a subsystem; see log(1) for more information. -Specify a log level with the \f[B]-l,\f[R] \f[B]--level\f[R] option to -override the `default' level if necessary. -Wrap the \f[I]message\f[R] string in quotes to preserve spacing. -.SS Options -.TP -\f[B]-h,\f[R] \f[B]--help\f[R] -Print brief help information -.TP -\f[B]-v,\f[R] \f[B]--version\f[R] -Print the current version string -.TP -\f[B]-s,\f[R] \f[B]--subsystem\f[R] -Specify an optional subsystem name. -This should be the identifier of the subsystem in reverse DNS form. -.TP -\f[B]-c,\f[R] \f[B]--category\f[R] -Specify an optional category name. -This option requires the \f[B]-s,\f[R] \f[B]--subsystem\f[R] option. -.TP -\f[B]-l,\f[R] \f[B]--level\f[R] \f[I]name\f[R] -Set the log level. -Supported values: default, info, debug, error, or fault. -The default log level is `default'. -.TP -\f[B]-a,\f[R] \f[B]--append\f[R] \f[I]file\f[R] -Append the log message to a file after sending it to the unified logging -system, creating the file if necessary. -.TP -\f[B]-p,\f[R] \f[B]--private\f[R] -Mark the log message as private. -Log message strings are public by default and can be viewed with the -log(1) command or Console app. -If the \f[B]-p,\f[R] \f[B]--private\f[R] option is used the message -string will be redacted and display as `'. -Device Management Profiles can be used to grant access to private log -messages. -.SH EXAMPLES -.IP -.nf -\f[C] -flog \[aq]batch.sh script success\[aq] -flog -l fault -s uk.co.fidgetbox.scm -c config \[aq]invalid configuration provided\[aq] -\f[R] -.fi -.SH EXIT STATUS -.PP -\f[B]flog\f[R] exits 0 on success, and >0 if an error occurs. -.SH BUGS -.PP -See GitHub Issues: https://github.com/marcransome/flog/issues -.SH AUTHOR -.PP -Marc Ransome -.SH SEE ALSO -.PP -log(1), os_log(3) diff --git a/man/flog.md b/man/flog.1.md similarity index 94% rename from man/flog.md rename to man/flog.1.md index c554243..5e22bf2 100644 --- a/man/flog.md +++ b/man/flog.1.md @@ -1,9 +1,9 @@ -% flog(1) Version 1.4.0 | Flog User's Guide +% flog(1) Version v1.5.0 | Flog User's Guide NAME ==== -**flog** — write log messages to the unified logging system +**flog** - write log messages to the unified logging system SYNOPSIS ======== diff --git a/man/gen-doc b/man/gen-doc deleted file mode 100755 index aa7c641..0000000 --- a/man/gen-doc +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -printf "Generating \033[0;34mman page\033[0m documentation..\n" -docker run --rm -v $(pwd):/src pandoc/core --standalone --to man --output /src/flog.1 /src/flog.md diff --git a/src/common.h b/src/common.h index acc4c96..f6306f1 100644 --- a/src/common.h +++ b/src/common.h @@ -29,7 +29,7 @@ */ #define PROGRAM_NAME "flog" -#define PROGRAM_VERSION "1.4.0" +#define PROGRAM_VERSION "v1.5.0" /*! \brief An enumerated type representing error conditions. */ typedef enum FlogErrorData { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f1ba59f..20f2eea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,3 @@ -include(CTest) - pkg_check_modules(CMOCKA REQUIRED cmocka>=1.1.7) include(add_cmocka_test)