💾 Archived View for thatit.be › 2024-07-07-23-53-48.gmi captured on 2024-08-25 at 00:09:29. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-08-18)

-=-=-=-=-=-=-

ducktape

I want something lighter than github to watch and build some projects on change. I’m going to call it ducktape. It’s a bash script that will have an array of projects. It will have a configurable delay. It will loop over all the projects, fetch from upstream, and if there is a change fetched, it will merge and build.

First Pass

For this to work, any project it watches must have a Makefile. And some standard targets.

Since it wont completely use a fresh repo on each run (I’m bandwidth constrained) each project must have a clean target.

Since my note repo has a publish target, I’ll make that required, too.

And then a default target is needed, which will be used to determine if the publish target is called.

Well, that sounds easy enough.

First pass is done. Embedding a copy here…

#!/bin/env bash

DELAY=600 # how long to wait before fetching updates and building again
REPOS=(
    #add URI's here
)

get_new_repos(){
    for REPO in "${REPOS[@]}" ; do
        2>/dev/null git clone "${REPO}" || continue
    done
}

build_and_publish(){
    local REPO=${1:-}
    if [ -z "${REPO}" ] ; then
        echo "Need a repo dir in order to build, failing..."
        return 1
    fi
    (
        set -e
        cd "${REPO}" || exit 1
        git log -n1
        echo "Attempting to build $(git remote)"
        if [ -f "shell.nix" ] && [ -f "Makefile" ] ; then
            nix-shell "shell.nix" --run "make clean"
            nix-shell "shell.nix" --run "make"
            nix-shell "shell.nix" --run "make publish"
        fi
    ) || (
        echo "There was a problem building, skipping this commit:"
        (cd "$REPO" ; git log -n1)
    )
}

update_existing_repos(){
    local DIR
    local DIFFS
    local DIRS
    local LOG
    DIRS=( */ )
    for DIR in "${DIRS[@]}" ; do
        DIFFS=$(
            1>/dev/null cd "${DIR}" || exit 1
            1>/dev/null git fetch
            git diff origin | wc | awk '{print $1}'
        )
        LOG="run-${DIR%/}-$(date "+%Y-%m-%d-%H-%M-%S").log"
        if ((DIFFS>0)) ; then
            echo "Changes in ${REPO}, attempting to run..."
            (cd "${DIR%/}"; git merge origin)
            build_and_publish "${DIR}" |& tee "${LOG}"
        fi
    done
}

get_new_repos
while true ; do
    update_existing_repos 
    sleep "${DELAY}"
done

Second Pass

For my second pass, I want to use containers that use an overlay on the existing checkout and build everything in place in the clean environment. Or at least, I certainly want to experiment with that. It would be nice to use NixOS containers instead of docker containers, just to see how those work.

Actually, I should make use of NixOS to get the dependencies and such as well.

Tags

#cli

Navigation

index

tags

Backlinks

2024-07-09 - I have a dumb idea

updated: 2024-07-07 23:57:33

generated: 2024-08-16