Skip to content

Commit

Permalink
build: 📦 add limbo tools
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed Dec 5, 2023
1 parent 972d8ad commit a64fb72
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tools/autorevert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

if [ $# -ne 1 ]; then
COMMAND=$(basename $0)
echo "Usage: $COMMAND <limit in minutes>"
exit 1
fi

LIMIT=$(( $1 * 60 ))

function logWaiting() {
echo -ne "\r\033[K👀 Waiting for changes to start timer..."
}

logWaiting

while true; do
GIT_STATUS=$(git status --porcelain)

# Start timer when user starts making changes.
if [ -z "$STARTED" ] && [ -n "$GIT_STATUS" ]; then
STARTED=$(date +%s)
fi

# User is making changes.
if [ -n "$STARTED" ]; then

# Compute remaining time.
REMAINING_TIME=$(($STARTED + $LIMIT - $(date +%s)))
# Keep it positive.
REMAINING_TIME=$(($REMAINING_TIME > 0 ? $REMAINING_TIME : 0))

# Log remaining time.
if [ $REMAINING_TIME -gt 60 ]; then
echo -ne "\r\033[K\033[1;32)mReverting in $(($REMAINING_TIME / 60)) minutes and $(($REMAINING_TIME % 60)) seconds...\033[0m"
else
echo -ne "\r\033[K\033[1;31)mReverting in $REMAINING_TIME seconds...\033[0m"
fi

# If user has been making changes for more than $LIMIT, revert:
if [ $(($(date +%s) - $STARTED)) -gt $LIMIT ]; then
git reset --hard > /dev/null
git clean -df > /dev/null
echo -ne "\r\033[K🧹 Changes reverted! Waiting for changes to start timer again."
STARTED=""
fi

# Detect when user stops making changes:
if [ -z "$GIT_STATUS" ]; then
logWaiting
STARTED=""
fi
fi

# We don't need this to be super reactive, 5 seconds is fine.
sleep 5
done
9 changes: 9 additions & 0 deletions tools/limbo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

while :;
do
git fetch;
[ $(git rev-parse HEAD) != $(git rev-parse @{u}) ] && git pull --rebase --autostash && git push;
# We don't need this to be super reactive, 5 seconds is fine.
sleep 5
done
23 changes: 23 additions & 0 deletions tools/tcr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e

if [ $# -lt 1 ]; then
COMMAND=$(basename $0)
echo "Usage:"
echo " $COMMAND <message>"
echo " $COMMAND --fixup <commit>"
exit 1
fi

if [ "$1" == "--fixup" ]; then
shift
COMMIT="git commit -a --fixup $1"
else
COMMIT="git commit -a -m \"$1\""
fi

TEST="nx run-many -t test,test-ui"
REVERT="(git diff --name-only | grep -v '.spec.ts' | xargs git checkout) && git clean -df
$TEST && $COMMIT || $REVERT

0 comments on commit a64fb72

Please sign in to comment.