From 3bceeb4da5ec953309bbc3e61d04f078198966d2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 27 Jul 2021 12:51:36 -0300 Subject: aux/: Update, adjust Makefile --- aux/80-columns.sh | 12 ++++++ aux/assert-shellcheck.sh | 6 +-- aux/ci/ci-build.sh | 25 ++++++++---- aux/ci/git-post-receive.sh | 16 ++++++-- aux/ci/git-pre-push.sh | 9 +++-- aux/ci/report.sh | 52 +++++++++++++++++++------ aux/guix/with-container.sh | 5 ++- aux/lib.sh | 30 +++++++++++++++ aux/workflow/TODOs.sh | 72 +++++++++++++++++++++++++--------- aux/workflow/assert-changelog.sh | 60 ++++++++++++++++++++++++++--- aux/workflow/assert-readme.sh | 75 ++++++++++++++++++++++++++++-------- aux/workflow/assert-todos.sh | 7 ++-- aux/workflow/commonmark.sh | 50 +++++++++++++++++------- aux/workflow/dist.sh | 63 +++++++++++++++++++++++++++--- aux/workflow/preamble.md | 6 +-- aux/workflow/public.sh | 63 +++++++++++++++++++++++++----- aux/workflow/sign-tarballs.sh | 39 ++++++++++++++----- aux/workflow/style.css | 83 +++++++++++++++++++--------------------- 18 files changed, 514 insertions(+), 159 deletions(-) create mode 100755 aux/80-columns.sh create mode 100755 aux/lib.sh diff --git a/aux/80-columns.sh b/aux/80-columns.sh new file mode 100755 index 0000000..ae4660e --- /dev/null +++ b/aux/80-columns.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +# shellcheck disable=2068 +for f in ${@:-$(cat -)}; do + if [ "$(file -i "$f" | cut -d' ' -f2 | cut -d/ -f1)" = 'text' ]; then + sed 's/\t/ /g' "$f" | + awk -v FNAME="$f" 'length > 80 { + printf "%s:%s:%s\n", FNAME, NR, $0 + }' + fi +done diff --git a/aux/assert-shellcheck.sh b/aux/assert-shellcheck.sh index cc01f3a..29d66a5 100755 --- a/aux/assert-shellcheck.sh +++ b/aux/assert-shellcheck.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -eux +set -eu -git ls-files | \ - xargs awk 'FNR==1 && /^#!\/bin\/sh$/ { print FILENAME }' | \ +git ls-files | + xargs awk 'FNR==1 && /^#!\/bin\/sh$/ { print FILENAME }' | xargs shellcheck diff --git a/aux/ci/ci-build.sh b/aux/ci/ci-build.sh index b6769a9..396fbff 100755 --- a/aux/ci/ci-build.sh +++ b/aux/ci/ci-build.sh @@ -1,12 +1,20 @@ #!/bin/sh set -eux -PACKAGE="$1" +PROJECT="$1" LOGS_DIR="$2" -read -r _ SHA _ # oldrev newrev refname +SHA="$3" FILENAME="$(date -Is)-$SHA.log" LOGFILE="$LOGS_DIR/$FILENAME" +mkdtemp() { + name="$(echo 'mkstemp(template)' | + m4 -D template="${TMPDIR:-/tmp}/m4-tmpname.")" + rm -f "$name" + mkdir "$name" + echo "$name" +} + { echo "Starting CI job at: $(date -Is)" @@ -26,24 +34,25 @@ EOF git notes append -m "$NOTE" cd - - sh aux/ci/report.sh "$PACKAGE" - rsync -a public/ "/srv/http/$PACKAGE/" --delete + git fetch origin refs/notes/*:refs/notes/* + sh aux/ci/report.sh -n "$PROJECT" -o public + rsync -av public/ "/srv/http/$PROJECT/" --delete - printf "\n>>>\n>>> CI logs added as Git note.\n>>>\n>>> Run status was %s" "$STATUS" + printf "\n>>>\n>>> CI logs added as Git note." + printf "\n>>>\n>>> Run status was %s\n\n" "$STATUS" } trap finish EXIT unset GIT_DIR REMOTE="$PWD" - cd "$(mktemp -d)" + cd "$(mkdtemp)" git clone "$REMOTE" . git config --global user.email git@euandre.org git config --global user.name 'EuAndreh CI' - git fetch origin refs/notes/*:refs/notes/* git annex get ||: if [ -f aux/guix/with-container.sh ]; then - RUNNER='./aux/guix/with-container.sh' + RUNNER='sh aux/guix/with-container.sh' else RUNNER='sh -c' fi diff --git a/aux/ci/git-post-receive.sh b/aux/ci/git-post-receive.sh index ee8075f..92bba73 100755 --- a/aux/ci/git-post-receive.sh +++ b/aux/ci/git-post-receive.sh @@ -4,11 +4,19 @@ set -eu for n in $(seq 0 $((GIT_PUSH_OPTION_COUNT - 1))); do opt="$(eval "echo \$GIT_PUSH_OPTION_$n")" if [ "$opt" = skip-ci ] || [ "$opt" = ci-skip ]; then - printf "\n'%s' option detected, not running ci-build.sh\n\n" "$opt" + printf "\n'%s' option detected, not running ci-build.sh\n\n" \ + "$opt" exit 0 fi done -PACKAGE="$(basename "$PWD" | cut -d. -f1)" # remove .git suffix -LOGS_DIR="/opt/ci/$PACKAGE/logs" -"/opt/ci/$PACKAGE/ci-build.sh" "$PACKAGE" "$LOGS_DIR" +# shellcheck disable=2034 +read -r _oldrev SHA _refname + +PROJECT="$(basename "$PWD" | cut -d. -f1)" # remove .git suffix +LOGS_DIR="/opt/ci/$PROJECT/logs" +sh "/opt/ci/$PROJECT/ci-build.sh" "$PROJECT" "$LOGS_DIR" "$SHA" ||: + +echo 'To retrigger the build, run:' +echo "cd /srv/http/$PROJECT.git/" +echo "sh /opt/ci/$PROJECT/ci-build.sh" "$PROJECT" "$LOGS_DIR" "$SHA" diff --git a/aux/ci/git-pre-push.sh b/aux/ci/git-pre-push.sh index e73b9b8..eaaa7bd 100755 --- a/aux/ci/git-pre-push.sh +++ b/aux/ci/git-pre-push.sh @@ -2,12 +2,13 @@ set -eux TLD="$(cat aux/tld.txt)" +. aux/lib.sh -PACKAGE="$(basename "$PWD")" -LOGS_DIR="/opt/ci/$PACKAGE/logs" -REMOTE_GIT_DIR="/srv/git/$PACKAGE.git" +PROJECT="$(basename "$PWD")" +LOGS_DIR="/opt/ci/$PROJECT/logs" +REMOTE_GIT_DIR="/srv/http/$PROJECT.git" -DESCRIPTION="$(mktemp)" +DESCRIPTION="$(mkstemp)" if [ -f description ] then cp description "$DESCRIPTION" diff --git a/aux/ci/report.sh b/aux/ci/report.sh index 65d3335..7fa3d08 100755 --- a/aux/ci/report.sh +++ b/aux/ci/report.sh @@ -1,23 +1,48 @@ #!/bin/sh set -eu -PROJECT_UC="$1" +TLD="$(cat aux/tld.txt)" +. aux/lib.sh + +while getopts 'n:o:' flag; do + case "$flag" in + n) + PROJECT="$OPTARG" + ;; + o) + OUTDIR="$OPTARG" + ;; + *) + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +assert_arg() { + if [ -z "$1" ]; then + echo "Missing $2" >&2 + exit 2 + fi +} + +assert_arg "${PROJECT:-}" '-n PROJECT' +assert_arg "${OUTDIR:-}" '-o OUTDIR' PASS='✅' FAIL='❌' -mkdir -p public/ci-logs public/ci-data +mkdir -p "$OUTDIR/ci-logs" "$OUTDIR/ci-data" -OUT="$(mktemp)" +OUT="$(mkstemp)" chmod 644 "$OUT" -git fetch origin refs/notes/*:refs/notes/* ||: - for c in $(git notes list | cut -d\ -f2); do DATA="$(git notes --ref=refs/notes/ci-data show "$c")" FILENAME="$(echo "$DATA" | cut -d\ -f2)" - echo "$DATA" > "public/ci-data/$FILENAME" - git notes --ref=refs/notes/ci-logs show "$c" > "public/ci-logs/$FILENAME" + echo "$DATA" > "$OUTDIR/ci-data/$FILENAME" + git notes --ref=refs/notes/ci-logs show "$c" \ + > "$OUTDIR/ci-logs/$FILENAME" done cat <> "$OUT" @@ -25,8 +50,10 @@ cat <> "$OUT" - + + CI logs for $PROJECT -- cgit v1.2.3