Repo containing scripts to be used with dovel, and git hooks that powers our web interface.
Author: blmayer (bleemayer@gmail.com)
Date: Mon Oct 2 14:59:47 2023 -0300
Parent: b405a3a
Merged other scripts in post-receive
diff --git a/post-receive b/post-receive index 7ce8aaf..b6b44b6 100755 --- a/post-receive +++ b/post-receive @@ -2,39 +2,264 @@ # for debugging # set -ex +. ./hooks/aux.sh +ROOT="$HOME/www/dovel.email" REPO="$(basename $PWD)" -OUT="$HOME/www/dovel.email" +OUT="$ROOT/$REPO" -[ -d "$OUT/$REPO/tree" ] && rm -rf "$OUT/$REPO/tree" -git clone . "$OUT/$REPO/tree" +updategit() { + cat <<- EOF > "$ROOT/git.html" + $(pagehead "dovel") + ← <a href="/">dovel website</a> -while read oldrev newrev ref -do - # only checking out the master (or whatever branch you would like to deploy) - case "$ref" in - "refs/heads/$BRANCH") - # update git's index page - . ./hooks/update-git-index + <h1>Dovel project Git home</h1> + Welcome! Here you'll find general info about our projects and how to + contribute to them. We proudly use dovel email technology for our + mailing lists. Its hooks are in the scripts repo. Please read the next + sections before making a contribution. + + <h2>Repositories</h2> + <dl> + EOF + + for dir in "$HOME/git/dovel.email"/* + do + cat <<- EOF >> "$ROOT/git.html" + <dt><a href=$(basename $dir)/index.html>$(basename $dir)</a></dt> + <dd>$(cat "$dir/description")</dd> + EOF + done + + cat <<- EOF >> "$ROOT/git.html" + </dl> + + <h2>Contributing</h2> + The dovel team uses the git email workflow to accept contributions. + All email sent to dovel.email is considered as git mailling lists, check + each repository for email to a specific project. To send email about + other subjects please address them to + <a href=mailto:dovel@myr.sh>dovel@myr.sh</a>. + + <h3>Email addresses</h3> + To send contributions use the repo name as the email's recipient, i.e. + to contribute to the server project send email to + <kbd>server@dovel.email</kbd>. Please CC me as well so I can reply + faster: <kbd>dovel@myr.sh</kbd>. + + <h3>Email etiquette</h3> + We only accept plain text email. More info and recomendations can be + found on <a href=//useplaintext.email>useplaintext.email</a>. Also + <a href=//git-send-email.io>git-send-email.io</a> has instructions on + how to setup git to send email for many platforms. + </body> + </html> + EOF +} + +updateindex() { + echo "creating archives" + tar -C "$OUT" -cz tree/ --xform="s/tree/$REPO/" > "$OUT.tar.gz" + + echo "creating index.html" + cat <<- EOF > "$OUT/index.html" + $(pagehead "$REPO") + $(pagesummary) + <hr> + <p>Latest commit: $(git log -n 1 --format="(%h) by %an at %as: %s")</p> + <pre>$(cat "$OUT/tree/README"*)</pre> + </body> + </html> + EOF +} + +filepage() { + cat <<- EOF + $(pagehead "$REPO") + $(pagesummary) + <hr> + <h2>$1</h2> + <file> + <pre> + <ol> + EOF + + # print file + while IFS= read -r l + do + printf "<li>%s</li>\n" "$(escapehtml "$l")" + done < "$OUT/tree/$1" + + echo "</ol>\n</pre>\n</file>\n</body>\n</html>" +} + +createcommitpage() { + cat <<- EOF + $(pagehead "$REPO") + $(pagesummary) + <hr> + <h2>$1</h2> + EOF + + # print commit + git show --format='%an%n%ae%n%ad%n%p%n%B' -s "$1" | { + read -r name + read -r email + read -r date + read -r parent + + cat <<- EOF + <p>Author: $name ($email)</p> + <p>Date: $date</p> + <p>Parent: <a href=$parent.html>$parent</a></p> + <p><pre> + EOF + + # the rest is the message + cat - - # update repo's index page - . ./hooks/update-repo-index + # now the diff + cat <<- EOF + </pre> + <h3>Diff</h3> + <pre style="overflow-x:auto;white-space:pre"> + EOF + } - # update repo's refs page - . ./hooks/update-repo-refs + git show --format='' "$1" | while read -r l + do + printf "%s\n" "$(escapehtml "$l")" + done - # update repo's tree page - . ./hooks/update-repo-tree + cat <<- EOF + </pre> + </body> + </html> + EOF +} - # update repo's log page - . ./hooks/update-repo-log +updatelog() { + echo "creating log.html" + cat <<- EOF > "$OUT/log.html" + $(pagehead "$REPO") + $(pagesummary) + <hr> + <h2>Log</h2> + <table> + <tr><th>Hash</th><th>Author</th><th>Date</th><th>Subject</td></tr> + EOF + + git log -n 100 --format='%h%n%ad%n%an%n%s' --date=iso | while read -r h + do + read -r date + read -r name + read -r msg + + cat <<- EOF >> "$OUT/log.html" + <tr><td><a href=log/$h.html>$h</a></td><td>$name</td><td>$date</td><td>$msg</td></tr> + EOF + + [ -f "$OUT/log/$h.html" ] && continue + echo "creating commit page $h" + createcommitpage "$h" > "$OUT/log/$h.html" + done + cat <<- EOF >> "$OUT/log.html" + </table> + <p>Note: Only showing up to 100 commits, for full log clone the repo.</p> + </body> + </html> + EOF +} + +updaterefs() { + echo "creating refs.html" + cat <<- EOF > "$OUT/refs.html" + $(pagehead "$REPO") + $(pagesummary) + <hr> + <h2>Branches</h2> + <table> + EOF + + git show-ref --heads | while read -r h n + do + echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" + done + + echo "</table>\n<h2>Tags</h2>\n<table>" >> "$OUT/refs.html" + + git show-ref --tags | while read -r h n + do + echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" + done + + cat <<- EOF >> "$OUT/refs.html" + </table> + </body> + </html> + EOF +} + +updatetree() { + echo "creating tree.html" + cat <<- EOF > "$OUT/tree.html" + $(pagehead "$REPO") + $(pagesummary) + <hr> + <h2>Tree</h2> + <table> + <tr><th>Size</th><th>Name</th><th>Raw</th></tr> + EOF + + (cd "$OUT/tree" && find * -type f -printf '%s %p\n') | while read -r s f + do + echo "updating file $f" + + cat <<- EOF >> "$OUT/tree.html" + <tr> + <td>$s</td> + <td><a href=tree/$f.html>$f</a></td> + <td><a href=tree/$f>raw</a></td> + </tr> + EOF + filepage "$f" > "$OUT/tree/$f.html" + done + cat <<- EOF >> "$OUT/tree.html" + </table> + </body> + </html> + EOF +} + +# first argument should be the version, e.g. v0.1.0 +creategomod() { + [ -d "$OUT/@latest" ] || mkdir -p "$OUT/@latest" + [ -d "$OUT/@v/$1" ] || mkdir -p "$OUT/@v/$1" + + find "$OUT/tree/"* -print | sed "s:$OUT/tree/:dovel.email/$REPO@v$1/" | zip -@ > "$OUT/@v/$1.zip" + cp "$OUT/$1.zip" "$OUT/@latest/" +} + +[ -d "$OUT/tree" ] && rm -rf "$OUT/tree" +[ -d "$OUT/log" ] || mkdir -p "$OUT/log" +git clone . "$OUT/tree" + +while read oldrev newrev ref +do + case "$ref" in + "refs/heads/$BRANCH") + updategit + updateindex + updaterefs + updatetree + updatelog ;; "refs/tags/v"*) echo "received version tag $ref" # check repo for go mod tag="${ref#refs/tags/}" - find "$OUT/$REPO/tree/" -name go.mod && .hooks/create-go-mod "$tag" + find "$OUT/tree/" -name go.mod && creategomod "$tag" ;; *) echo "Ref $ref received. Doing nothing." ;; esac diff --git a/post-receive-scripts b/post-receive-scripts index cf44b5f..ac6f2c1 100755 --- a/post-receive-scripts +++ b/post-receive-scripts @@ -3,54 +3,22 @@ #for debugging #set -ex -BRANCH="main" -REPO="$(basename $PWD)" -OUT="$HOME/www/dovel.email" +echo "copying scritps" +TMP="$(mktemp -d)" +git --work-tree="$TMP" checkout -f ${BRANCH} -while read oldrev newrev ref +# copy main scripts to projects +for dir in ../* do - # only checking out the master (or whatever branch you would like to deploy) - case "$ref" in - "refs/heads/$BRANCH") - echo "Ref $ref received. Updating git pages" - TMP="$(mktemp -d)" - git --work-tree="$TMP" checkout -f ${BRANCH} - - # copy main scripts to projects - for dir in ../* - do - cp "$TMP/post-receive" "$dir/hooks/" - cp "$TMP/update-git-index" "$dir/hooks/" - cp "$TMP/update-repo-index" "$dir/hooks/" - cp "$TMP/update-repo-refs" "$dir/hooks/" - cp "$TMP/update-repo-tree" "$dir/hooks/" - cp "$TMP/update-repo-log" "$dir/hooks/" - cp "$TMP/create-go-mod" "$dir/hooks/" - cp "$TMP/aux.sh" "$dir/hooks/" - done - - # for this repo copy scripts - rm ./hooks/post-receive - cp "$TMP/post-receive-scripts" ./hooks/post-receive - echo "cleaning up TMP" - rm -fr "$TMP" + cp "$TMP/post-receive" "$dir/hooks/" + cp "$TMP/aux.sh" "$dir/hooks/" +done - # the common part - [ -d "$OUT/$REPO/tree" ] && rm -rf "$OUT/$REPO/tree" - git clone . "$OUT/$REPO/tree" +# for this repo copy scripts +mv hooks/post-receive hooks/post-receive-all +cp "$TMP/post-receive-scripts" hooks/post-receive - . ./hooks/update-git-index - . ./hooks/update-repo-index - . ./hooks/update-repo-refs - . ./hooks/update-repo-tree - . ./hooks/update-repo-log - ;; - "refs/tags/v"*) - # check repo for go mod - tag="${ref#refs/tags/}" - find -name go.mod tree/ && .hooks/create-go-mod "$tag" - ;; - *) echo "Ref $ref received. Doing nothing." ;; - esac -done +echo "cleaning up TMP" +rm -fr "$TMP" +. hooks/post-receive-all