From 9ced2af562674f4e2f60899a872cb8f29f26f113 Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Wed, 11 Mar 2026 07:42:45 +0100 Subject: [PATCH] Actions --- .gitea/workflows/lint.yml | 16 ++++++++++++++++ .gitea/workflows/release.yml | 24 ++++++++++++++++++++++++ .github/workflows/lint.yml | 16 ++++++++++++++++ .github/workflows/release.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + kewt.sh | 18 ++++++++---------- markdown.sh | 8 +++++--- tools/build-standalone.sh | 32 ++++++++++++++++++++++++++++++++ 8 files changed, 124 insertions(+), 13 deletions(-) create mode 100644 .gitea/workflows/lint.yml create mode 100644 .gitea/workflows/release.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml create mode 100644 tools/build-standalone.sh diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..002c615 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,16 @@ +name: Lint + +on: + push: + branches: [ main, master ] + pull_request: + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Shellcheck + run: sudo apt-get update && sudo apt-get install -y shellcheck + - name: Run Shellcheck + run: shellcheck kewt.sh markdown.sh tools/build-standalone.sh || true diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..5311cf6 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,24 @@ +name: Release Standalone Builder + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build standalone executable + run: | + chmod +x tools/build-standalone.sh + ./tools/build-standalone.sh + + - name: Upload Release Asset + uses: https://gitea.com/actions/release-action@main + with: + files: |- + kewt + api_key: '${{secrets.GITEA_TOKEN}}' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..002c615 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: Lint + +on: + push: + branches: [ main, master ] + pull_request: + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Shellcheck + run: sudo apt-get update && sudo apt-get install -y shellcheck + - name: Run Shellcheck + run: shellcheck kewt.sh markdown.sh tools/build-standalone.sh || true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bdb356e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Release Standalone Builder + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build standalone executable + run: | + chmod +x tools/build-standalone.sh + ./tools/build-standalone.sh + + - name: Upload Release Asset + uses: softprops/action-gh-release@v2 + with: + files: kewt diff --git a/.gitignore b/.gitignore index 89f9ac0..d2efdfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ out/ +kewt \ No newline at end of file diff --git a/kewt.sh b/kewt.sh index 9667c6a..fc33099 100755 --- a/kewt.sh +++ b/kewt.sh @@ -20,7 +20,7 @@ Options: EOF } -script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +script_dir=$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd) awk_dir="$script_dir/awk" ensure_root_defaults() { @@ -93,10 +93,7 @@ create_new_site() { exit 0 } -generate_nav() { - dinfo=$(find "$1" \( -name ".*" ! -name "." ! -name ".." -prune \) -o -print | sort | awk -v src="$1" -f "$awk_dir/collect_dir_info.awk") - find "$1" \( -name ".*" ! -name "." ! -name ".." -prune \) -o -name "*.md" -print | sort | awk -v src="$1" -v single_file_index="$single_file_index" -v flatten="$flatten" -v order="$order" -v dinfo="$dinfo" -f "$awk_dir/generate_sidebar.awk" -} + src="" out="" @@ -133,9 +130,9 @@ while [ $# -gt 0 ]; do *) positional_count=$((positional_count + 1)) if [ "$positional_count" -eq 1 ]; then - [ -z "$src" ] && src="$1" || die "Source already set (use either positional or --from)." + if [ -z "$src" ]; then src="$1"; else die "Source already set (use either positional or --from)."; fi elif [ "$positional_count" -eq 2 ]; then - [ -z "$out" ] && out="$1" || die "Output already set (use either positional or --to)." + if [ -z "$out" ]; then out="$1"; else die "Output already set (use either positional or --to)."; fi else die "Too many positional arguments." fi @@ -333,6 +330,7 @@ nav_links_html() { old_ifs=$IFS set -f IFS=',' + # shellcheck disable=SC2086 set -- $nav_links IFS=$old_ifs set +f @@ -418,7 +416,7 @@ render_markdown() { closest_style_src=$(find_closest "styles.css" "$(dirname "$file")") [ -z "$closest_style_src" ] && closest_style_src=$(find_closest "style.css" "$(dirname "$file")") if [ -n "$closest_style_src" ]; then - style_rel_to_src="${closest_style_src#$src/}" + style_rel_to_src="${closest_style_src#"$src"/}" case "$closest_style_src" in "$src/styles.css") style_rel_to_src="styles.css" ;; "$src/style.css") style_rel_to_src="style.css" ;; @@ -466,7 +464,7 @@ render_markdown() { echo "Building site from '$src' to '$out'..." eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while read -r dir; do - rel_dir="${dir#$src}" + rel_dir="${dir#"$src"}" rel_dir="${rel_dir#/}" [ -z "$rel_dir" ] && rel_dir="." out_dir="$out/$rel_dir" @@ -518,7 +516,7 @@ if [ ! -f "$out/styles.css" ] && [ -f "$script_dir/styles/$style.css" ]; then fi eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while IFS= read -r file; do - rel_path="${file#$src}" + rel_path="${file#"$src"}" rel_path="${rel_path#/}" dir_rel=$(dirname "$rel_path") out_dir="$out/$dir_rel" diff --git a/markdown.sh b/markdown.sh index 8d7bf61..7b2b61e 100755 --- a/markdown.sh +++ b/markdown.sh @@ -1,16 +1,18 @@ #!/bin/sh -script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +script_dir=$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd) awk_dir="$script_dir/awk" sed_inplace() { script="$1" file="$2" tmp="${file}.tmp.$$" - sed "$script" "$file" > "$tmp" && mv "$tmp" "$file" || { + if sed "$script" "$file" > "$tmp" && mv "$tmp" "$file"; then + return 0 + else rm -f "$tmp" return 1 - } + fi } temp_file="/tmp/markdown.$$.md" diff --git a/tools/build-standalone.sh b/tools/build-standalone.sh new file mode 100644 index 0000000..ca35727 --- /dev/null +++ b/tools/build-standalone.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" + +if [ ! -f "$REPO_ROOT/kewt.sh" ]; then + echo "kewt.sh not found. Run from the repository root or tools/." + exit 1 +fi + +OUT_FILE="$REPO_ROOT/kewt" + +cat << 'EOF' > "$OUT_FILE" +#!/bin/sh +tmpdir=$(mktemp -d "/tmp/kewt.XXXXXX") +trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM + +# Extract payload +sed '1,/^#==PAYLOAD==$/d' "$0" | tar -xz -C "$tmpdir" + +# Pass control to the extracted script +exec "$tmpdir/kewt.sh" "$@" + +#==PAYLOAD== +EOF + +tar -cz -C "$REPO_ROOT" kewt.sh markdown.sh awk styles >> "$OUT_FILE" + +chmod +x "$OUT_FILE" + +echo "Generated standalone executable at $OUT_FILE"