From d9aef665013e202ab4dac844e9dcd029a43f4222 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 10 Jan 2021 10:31:28 -0300 Subject: Move scripts/ to build-aux/ --- Makefile | 8 +++---- build-aux/assert-shellcheck.sh | 5 +++++ build-aux/assert-terraform.sh | 10 +++++++++ build-aux/ci/ci-build.sh | 43 ++++++++++++++++++++++++++++++++++++++ build-aux/ci/git-post-receive.sh | 13 ++++++++++++ build-aux/ci/git-pre-push.sh.in | 18 ++++++++++++++++ scripts/assert-shellcheck.sh | 6 ------ scripts/assert-terraform.sh | 10 --------- scripts/assert-todos.sh | 42 ------------------------------------- scripts/ci-build.sh | 40 ----------------------------------- scripts/generate-tasks-and-bugs.sh | 24 --------------------- scripts/with-container.sh | 3 --- 12 files changed, 93 insertions(+), 129 deletions(-) create mode 100755 build-aux/assert-shellcheck.sh create mode 100755 build-aux/assert-terraform.sh create mode 100755 build-aux/ci/ci-build.sh create mode 100755 build-aux/ci/git-post-receive.sh create mode 100644 build-aux/ci/git-pre-push.sh.in delete mode 100755 scripts/assert-shellcheck.sh delete mode 100755 scripts/assert-terraform.sh delete mode 100755 scripts/assert-todos.sh delete mode 100755 scripts/ci-build.sh delete mode 100755 scripts/generate-tasks-and-bugs.sh delete mode 100755 scripts/with-container.sh diff --git a/Makefile b/Makefile index 3ccfcd0..7238cf3 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .PHONY: check check: - bash scripts/assert-shellcheck.sh - bash scripts/assert-todos.sh - bash scripts/assert-terraform.sh + ./build-aux/assert-shellcheck.sh + # ./build-aux/assert-todos.sh + ./build-aux/assert-terraform.sh .PHONY: clean clean: @@ -10,5 +10,5 @@ clean: .PHONY: public public: - bash ./scripts/generate-tasks-and-bugs.sh + ./build-aux/generate-tasks-and-bugs.sh pandoc -s --metadata title='VPS - EuAndreh' -c styles.css -o public/index.html README.md diff --git a/build-aux/assert-shellcheck.sh b/build-aux/assert-shellcheck.sh new file mode 100755 index 0000000..d07815b --- /dev/null +++ b/build-aux/assert-shellcheck.sh @@ -0,0 +1,5 @@ +#!/bin/sh -eux + +git ls-files -z | \ + xargs -0 awk 'FNR==1 && /^#!\/bin\/sh/ { print FILENAME }' | \ + xargs shellcheck diff --git a/build-aux/assert-terraform.sh b/build-aux/assert-terraform.sh new file mode 100755 index 0000000..8f03d7f --- /dev/null +++ b/build-aux/assert-terraform.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +terraform fmt -check=true -diff=true || { + echo "Terraform files are unformatted. To fix it, run:" + echo " terraform fmt" + exit 1 +} diff --git a/build-aux/ci/ci-build.sh b/build-aux/ci/ci-build.sh new file mode 100755 index 0000000..62e0f22 --- /dev/null +++ b/build-aux/ci/ci-build.sh @@ -0,0 +1,43 @@ +#!/bin/sh -eux + +PACKAGE="$1" +LOGS_DIR="$2" +read -r _ SHA _ # oldrev newrev refname +FILENAME="$(date -Is)-$SHA.log" +LOGFILE="$LOGS_DIR/$FILENAME" + +{ + echo "Starting CI job at: $(date -Is)" + + finish() { + STATUS="$?" + printf "\n\n>>> exit status was %s\n" "$STATUS" + echo "Finishing CI job at: $(date -Is)" + cd - + NOTE=$(cat <>>\n>>> CI logs added as Git note.\n>>>\n>>> Run status was %s" "$STATUS" + } + trap finish EXIT + + unset GIT_DIR + CLONE="$(mktemp -d)" + git clone . "$CLONE" + cd "$CLONE" + git config --global user.email git@euandre.org + git config --global user.name 'EuAndreh CI' + + if [ -f ./bootstrap ]; then + ./build-aux/with-container.sh './bootstrap && ./configure --enable-programmer-mode --enable-ci-mode && make clean all check distcheck public' + else + ./build-aux/with-container.sh 'make clean check public' + fi + rsync -avzzP public/ "/srv/http/$PACKAGE/" --delete +} | tee "$LOGFILE" 2>&1 diff --git a/build-aux/ci/git-post-receive.sh b/build-aux/ci/git-post-receive.sh new file mode 100755 index 0000000..c78f1ac --- /dev/null +++ b/build-aux/ci/git-post-receive.sh @@ -0,0 +1,13 @@ +#!/bin/sh -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" + exit 0 + fi +done + +PACKAGE="$(basename "$PWD" | cut -d. -f1)" # remove .git suffix +LOGS_DIR="/data/ci/$PACKAGE/logs" +"/data/ci/$PACKAGE/ci-build.sh" "$PACKAGE" "$LOGS_DIR" diff --git a/build-aux/ci/git-pre-push.sh.in b/build-aux/ci/git-pre-push.sh.in new file mode 100644 index 0000000..37e777c --- /dev/null +++ b/build-aux/ci/git-pre-push.sh.in @@ -0,0 +1,18 @@ +#!/bin/sh -eux + +PACKAGE="$(basename "$PWD")" +LOGS_DIR="/data/ci/$PACKAGE/logs" +REMOTE_GIT_DIR="/data/git/$PACKAGE.git" + +DESCRIPTION="$(mktemp)" +if [ -f description ] +then + cp description "$DESCRIPTION" +else + git config euandreh.description > "$DESCRIPTION" +fi + +scp "$DESCRIPTION" "git.@TLD@:$REMOTE_GIT_DIR/description" +ssh git.@TLD@ mkdir -p "$LOGS_DIR" +scp build-aux/ci/ci-build.sh "git.@TLD@:$(dirname "$LOGS_DIR")/ci-build.sh" +scp build-aux/ci/git-post-receive.sh "git.@TLD@:$REMOTE_GIT_DIR/hooks/post-receive" diff --git a/scripts/assert-shellcheck.sh b/scripts/assert-shellcheck.sh deleted file mode 100755 index e24c29c..0000000 --- a/scripts/assert-shellcheck.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../ - -git ls-files | grep '\.sh$' | xargs shellcheck diff --git a/scripts/assert-terraform.sh b/scripts/assert-terraform.sh deleted file mode 100755 index 8f03d7f..0000000 --- a/scripts/assert-terraform.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../ - -terraform fmt -check=true -diff=true || { - echo "Terraform files are unformatted. To fix it, run:" - echo " terraform fmt" - exit 1 -} diff --git a/scripts/assert-todos.sh b/scripts/assert-todos.sh deleted file mode 100755 index a9c5ef9..0000000 --- a/scripts/assert-todos.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../ - -if git grep FIXME | grep -v '^TODOs.org' | grep -v '^scripts/assert-todos.sh'; then - echo "Found dangling FIXME markers on the project." - echo "You should write them down properly on TODOs.org." - exit 1 -fi - -contains-element() { - local e match="$1" - shift - for e; do [[ "$e" == "$match" ]] && return 0; done - return 1 -} - -KNOWN_IDS=() -has_error=0 -# shellcheck disable=2013 -for todo in $(sed -e '/^\* Tasks$/,/^\* Improvements$/!d' TODOs.org | grep -nE '^\*\* .*$' | cut -d: -f1); do - if grep -E '^\*\* (CANCELLED|DONE)' <(sed "${todo}q;d" TODOs.org) > /dev/null; then - ID_OFFSET=3 - else - ID_OFFSET=2 - fi - ID="$(sed "$((todo+ID_OFFSET))q;d" TODOs.org)" - if grep '^:CUSTOM_ID: .*$' <(echo "$ID") > /dev/null; then - if contains-element "$ID" "${KNOWN_IDS[@]}"; then - echo "Duplicated ID: $ID" - has_error=1 - else - KNOWN_IDS+=("$ID") - fi - else - echo "Missing ID for TODO in line $todo" - has_error=1 - fi -done - -exit "$has_error" diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh deleted file mode 100755 index f9602a1..0000000 --- a/scripts/ci-build.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -set -x - -PREFIX="$LOGS_PREFIX/vps" -mkdir -p "$PREFIX" -read -r _ SHA _ # oldrev newrev refname -FILENAME="$(date -Is)-$SHA.log" -LOGFILE="$PREFIX/$FILENAME" -exec &> >(tee -a "$LOGFILE") - -echo "Starting CI job at: $(date -Is)" - -finish() { - STATUS="$?" - printf "\n\n>>> exit status was %s\n" "$STATUS" - echo "Finishing CI job at: $(date -Is)" - popd - NOTE=$(cat <>> CI logs added as Git note." -} -trap finish EXIT - -unset GIT_DIR -CLONE="$(mktemp -d)" -git clone . "$CLONE" -pushd "$CLONE" -git config --global user.email git@euandre.org -git config --global user.name 'EuAndreh CI' - -./scripts/with-container.sh 'make clean check public' -rm -rf /srv/http/vps/ && mv public/ /srv/http/vps/ diff --git a/scripts/generate-tasks-and-bugs.sh b/scripts/generate-tasks-and-bugs.sh deleted file mode 100755 index cbbce29..0000000 --- a/scripts/generate-tasks-and-bugs.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../ - -mkdir -p public - -cat workflow/vendor/org.css workflow/workflow.css > public/styles.css - -sed -e '/^\* Tasks$/,/^\* Improvements$/!d' TODOs.org | \ - head -n -1 | \ - cat workflow/preamble.org - > tasks-and-bugs.org - -emacs tasks-and-bugs.org \ - -l workflow/vendor/htmlize.el \ - --eval '(setq org-export-allow-bind-keywords t)' \ - -f org-html-export-to-html \ - --batch \ - --kill - -# Add anchor link to bug headers -perl -pe \ - 's|^

(.*)

$|

\2
#\1

|' \ - tasks-and-bugs.html > public/tasks-and-bugs.html diff --git a/scripts/with-container.sh b/scripts/with-container.sh deleted file mode 100755 index 1261022..0000000 --- a/scripts/with-container.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -guix time-machine -C guix/channels.scm -- environment --pure -C -m guix/manifest.scm -- sh -c "$@" -- cgit v1.2.3