From 059587b2463b4df76c7a4d31cccbe59d5d159ac9 Mon Sep 17 00:00:00 2001 From: Alex Bucknall Date: Fri, 6 Mar 2026 13:14:24 +0000 Subject: [PATCH 1/3] feat: add release packaging workflow and update script Add a GitHub Actions workflow that packages the note-c library files into a tarball and uploads it as a release asset when a release is published. Add a bash script that users can run to fetch the latest (or a specific) release of the library into their project. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/release.yml | 32 +++++++++++++++++++ scripts/update_note_c.sh | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 scripts/update_note_c.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..09fa7be1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Package Release + +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + package: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create release archive + run: | + version="${GITHUB_REF_NAME}" + archive="note-c-${version}.tar.gz" + tar czf "${archive}" \ + LICENSE \ + note.h \ + n_lib.h \ + n_cjson.h \ + n_*.c + echo "ARCHIVE=${archive}" >> "$GITHUB_ENV" + + - name: Upload release asset + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload "${{ github.event.release.tag_name }}" "${{ env.ARCHIVE }}" diff --git a/scripts/update_note_c.sh b/scripts/update_note_c.sh new file mode 100755 index 00000000..e8e80962 --- /dev/null +++ b/scripts/update_note_c.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# Update the note-c C library to the latest release or a specified version. +# +# Usage: +# ./update_note_c.sh [dest_dir] [version] +# +# Arguments: +# dest_dir Directory to install note-c files into (default: current directory) +# version Release version tag, e.g. v2.5.5 (default: latest) +# +# Examples: +# ./update_note_c.sh # Latest release into current dir +# ./update_note_c.sh ./lib/note-c # Latest release into ./lib/note-c +# ./update_note_c.sh . v2.5.4 # Specific version into current dir + +set -euo pipefail + +REPO="blues/note-c" +DEST="${1:-.}" +VERSION="${2:-}" + +if ! command -v curl &>/dev/null; then + echo "Error: curl is required but not found." >&2 + exit 1 +fi + +# Resolve the version tag +if [ -z "${VERSION}" ]; then + VERSION=$(curl -sfL \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${REPO}/releases/latest" \ + | grep '"tag_name"' | cut -d'"' -f4) + if [ -z "${VERSION}" ]; then + echo "Error: failed to determine latest release version." >&2 + exit 1 + fi + echo "Latest release: ${VERSION}" +else + echo "Requested release: ${VERSION}" +fi + +ARCHIVE="note-c-${VERSION}.tar.gz" +URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}" + +# Download the archive +TMPDIR=$(mktemp -d) +trap 'rm -rf "${TMPDIR}"' EXIT + +echo "Downloading ${URL}..." +if ! curl -fL -o "${TMPDIR}/${ARCHIVE}" "${URL}"; then + echo "Error: download failed. Check that version '${VERSION}' exists and has a release archive." >&2 + exit 1 +fi + +# Extract into destination +mkdir -p "${DEST}" +tar xzf "${TMPDIR}/${ARCHIVE}" -C "${DEST}" + +echo "note-c ${VERSION} installed to ${DEST}" From 7b43a064c8e6ed4da6b115d56e7f7300273888a9 Mon Sep 17 00:00:00 2001 From: Alex Bucknall Date: Fri, 6 Mar 2026 14:01:38 +0000 Subject: [PATCH 2/3] feat: include update script in release archive Co-Authored-By: Claude Opus 4.6 --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 09fa7be1..b7f1d479 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,8 @@ jobs: note.h \ n_lib.h \ n_cjson.h \ - n_*.c + n_*.c \ + scripts/update_note_c.sh echo "ARCHIVE=${archive}" >> "$GITHUB_ENV" - name: Upload release asset From 18531e82524b9d9802a83635e0e6540fe502f0d0 Mon Sep 17 00:00:00 2001 From: Alex Bucknall Date: Fri, 6 Mar 2026 15:21:32 +0000 Subject: [PATCH 3/3] feat: add --clean flag to strip non-library files from a directory Useful after cloning the repo to reduce it to just the library files. Removes everything except the headers, source files, and LICENSE. Co-Authored-By: Claude Opus 4.6 --- scripts/update_note_c.sh | 63 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/scripts/update_note_c.sh b/scripts/update_note_c.sh index e8e80962..9418462c 100755 --- a/scripts/update_note_c.sh +++ b/scripts/update_note_c.sh @@ -3,19 +3,80 @@ # Update the note-c C library to the latest release or a specified version. # # Usage: -# ./update_note_c.sh [dest_dir] [version] +# ./update_note_c.sh [options] [dest_dir] [version] # # Arguments: # dest_dir Directory to install note-c files into (default: current directory) # version Release version tag, e.g. v2.5.5 (default: latest) # +# Options: +# --clean [dir] Remove all non-library files from dir (default: current +# directory). This is useful after cloning the repo to strip +# it down to just the library. The script removes itself. +# # Examples: # ./update_note_c.sh # Latest release into current dir # ./update_note_c.sh ./lib/note-c # Latest release into ./lib/note-c # ./update_note_c.sh . v2.5.4 # Specific version into current dir +# ./update_note_c.sh --clean # Clean current dir to library only +# ./update_note_c.sh --clean ./note-c # Clean a specific directory set -euo pipefail +# Library files to keep during --clean +LIBRARY_FILES=( + LICENSE + note.h + n_lib.h + n_cjson.h + n_atof.c + n_b64.c + n_cjson.c + n_cjson_helpers.c + n_cobs.c + n_const.c + n_ftoa.c + n_helpers.c + n_hooks.c + n_i2c.c + n_md5.c + n_printf.c + n_request.c + n_serial.c + n_str.c + n_ua.c +) + +clean() { + local dir="${1:-.}" + dir=$(cd "${dir}" && pwd) + + # Remove everything in the directory that isn't a library file + for entry in "${dir}"/* "${dir}"/.*; do + name=$(basename "${entry}") + [ "${name}" = "." ] || [ "${name}" = ".." ] && continue + + local is_library=false + for f in "${LIBRARY_FILES[@]}"; do + if [ "${name}" = "${f}" ]; then + is_library=true + break + fi + done + + if [ "${is_library}" = false ]; then + rm -rf "${entry}" + fi + done + + echo "Cleaned ${dir} to library files only." +} + +if [ "${1:-}" = "--clean" ]; then + clean "${2:-.}" + exit 0 +fi + REPO="blues/note-c" DEST="${1:-.}" VERSION="${2:-}"