Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions scripts/check-commitlog.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# Check that every non-merge commit after the specified base commit has a commit
# message ending with a valid Change-Id line. A valid Change-Id line must be the
Expand All @@ -8,6 +8,16 @@
#
# Merge commits are excluded from this check.

# Ensure that the common script exists and is readable, then verify it has no
# syntax errors and defines the required function.
common_script="$(dirname "$0")/common.sh"
[ -r "$common_script" ] || { echo "[!] '$common_script' not found or not readable." >&2; exit 1; }
bash -n "$common_script" >/dev/null 2>&1 || { echo "[!] '$common_script' contains syntax errors." >&2; exit 1; }
source "$common_script"
declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not define the required function." >&2; exit 1; }

set_colors

# Base commit from which to start checking.
BASE_COMMIT="0b8be2c15160c216e8b6ec82c99a000e81c0e429"

Expand All @@ -33,10 +43,7 @@ for commit in $commits; do
done

if [ $failed -ne 0 ]; then
echo
echo "Some commits are missing a valid Change-Id. Please amend the commit messages accordingly."
echo
exit 1
throw "Some commits are missing a valid Change-Id. Please amend the commit messages accordingly."
fi

exit 0
11 changes: 9 additions & 2 deletions scripts/check-repo.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash

# Source the common utilities
source "$(dirname "$0")/common.sh"
# Ensure that the common script exists and is readable, then verify it has no
# syntax errors and defines the required function.
common_script="$(dirname "$0")/common.sh"
[ -r "$common_script" ] || { echo "[!] '$common_script' not found or not readable." >&2; exit 1; }
bash -n "$common_script" >/dev/null 2>&1 || { echo "[!] '$common_script' contains syntax errors." >&2; exit 1; }
source "$common_script"
declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not define the required function." >&2; exit 1; }

set_colors

check_github_actions

Expand Down
2 changes: 1 addition & 1 deletion scripts/checksums
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
398b59c23f699ff1bf1e73a94503a9a91caa9207 queue.h
9be9666430f392924f5d27caa71a412527bf9267 list.h
3bb0192cee08d165fd597a9f6fbb404533e28fcf scripts/check-commitlog.sh
1029c2784b4cae3909190c64f53a06cba12ea38e scripts/check-commitlog.sh
33 changes: 11 additions & 22 deletions scripts/commit-msg.hook
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,20 @@ HOOK_EDITOR=
SKIP_DISPLAY_WARNINGS=0
WARNINGS=

RED=
YELLOW=
BLUE=
WHITE=
CYAN=
NC=

# Set colour variables if the output should be coloured.
set_colors() {
local default_color=$(git config --get hooks.goodcommit.color || git config --get color.ui || echo 'auto')
if [[ $default_color == 'always' ]] || [[ $default_color == 'auto' && -t 1 ]]; then
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
CYAN='\033[1;36m'
NC='\033[0m' # No Color
fi
}
# Ensure that the common script exists and is readable, then verify it has no
# syntax errors and defines the required function.
common_script="$(dirname "$0")/../../scripts/common.sh"
[ -r "$common_script" ] || { echo "[!] '$common_script' not found or not readable." >&2; exit 1; }
bash -n "$common_script" >/dev/null 2>&1 || { echo "[!] '$common_script' contains syntax errors." >&2; exit 1; }
source "$common_script"
declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not define the required function." >&2; exit 1; }

# Set the hook editor, using the same approach as git.
set_editor() {
# $GIT_EDITOR appears to always be set to `:` when the hook is executed by Git?
# ref: http://stackoverflow.com/q/41468839/885540
# ref: https://github.com/tommarshall/git-good-commit/issues/11
# $GIT_EDITOR appears to always be set to ':' when the hook is executed by Git?
# Reference:
# - http://stackoverflow.com/q/41468839/885540
# - https://github.com/tommarshall/git-good-commit/issues/11
# HOOK_EDITOR=$GIT_EDITOR
test -z "${HOOK_EDITOR}" && HOOK_EDITOR=$(git config --get core.editor)
test -z "${HOOK_EDITOR}" && HOOK_EDITOR=$VISUAL
Expand Down
2 changes: 0 additions & 2 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,3 @@ make_random_string() {
echo "${raw_rand:0:pos}${sub_str}${raw_rand:pos}"
fi
}

set_colors
99 changes: 65 additions & 34 deletions scripts/install-git-hooks
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
#!/usr/bin/env bash

# Ensure that the common script exists and is readable, then verify it has no
# syntax errors and defines the required function.
common_script="$(dirname "$0")/common.sh"
[ -r "$common_script" ] || { echo "[!] '$common_script' not found or not readable." >&2; exit 1; }
bash -n "$common_script" >/dev/null 2>&1 || { echo "[!] '$common_script' contains syntax errors." >&2; exit 1; }
source "$common_script"
declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not define the required function." >&2; exit 1; }

set_colors

TOTAL_STEPS=5
CURRENT_STEP=0

# 1. Validate the workspace
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

if ! test -d .git; then
echo "Execute scripts/install-git-hooks in the top-level directory."
exit 1
throw "Execute scripts/install-git-hooks in the top-level directory."
fi

workspace=$(git rev-parse --show-toplevel)
if [ ! -d "$workspace" ]; then
throw "The workspace path '$workspace' contains non-ASCII characters."
fi

# 2. Check GitHub account
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

ACCOUNT=$(git config -l | grep -w remote.origin.url | sed -e 's/^.*github.com[\/:]\(.*\)\/lab0-c.*/\1/')

CURL=$(which curl)
if [ $? -ne 0 ]; then
echo "[!] curl not installed." >&2
exit 1
throw "curl not installed."
fi

CURL_RES=$(${CURL} -s \
Expand All @@ -19,44 +43,51 @@ https://api.github.com/repos/${ACCOUNT}/lab0-c/actions/workflows)

TOTAL_COUNT=$(echo ${CURL_RES} | sed -e 's/.*"total_count": \([^,"]*\).*/\1/')
case ${TOTAL_COUNT} in
*"Not Found"*)
echo "Check your repository. It should be located at https://github.com/${ACCOUNT}/lab0-c"
exit 1
*"Not Found"*)
throw "Check your repository. It should be located at https://github.com/${ACCOUNT}/lab0-c"
esac

# 3. Ensure this repository is frok from sysprog21/lab0-c'.
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

if [[ "${ACCOUNT}" != "sysprog21" ]]; then
REPO_FORKED=$(${CURL} -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${ACCOUNT}/lab0-c | grep -m 1 fork)
case ${REPO_FORKED} in
*true*)
;;
*)
echo "Your repository MUST be forked from sysprog21/lab0-c"
exit 1
esac
REPO_FORKED=$(${CURL} -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${ACCOUNT}/lab0-c | grep -m 1 fork)
case ${REPO_FORKED} in
*true*)
;;
*)
throw "Your repository MUST be forked from 'sysprog21/lab0-c'."
esac
fi

# 4. Check GitHub Actions
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

if [ ${TOTAL_COUNT} -eq "0" ]; then
echo "Fatal: GitHub Actions MUST be activated."
case ${OSTYPE} in
"linux"*)
xdg-open https://github.com/${ACCOUNT}/lab0-c/actions > /dev/null 2>&1
;;
"darwin"*)
open https://github.com/${ACCOUNT}/lab0-c/actions
;;
*)
echo "Please activate at https://github.com/${ACCOUNT}/lab0-c/actions"
;;
esac
echo "Check this article: https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow"
echo "Then, execute 'make' again."
exit 1
else
echo "GitHub Actions has been activated"
printf "\n[!] GitHub Actions MUST be activated."
case ${OSTYPE} in
"linux"*)
xdg-open https://github.com/${ACCOUNT}/lab0-c/actions > /dev/null 2>&1
;;
"darwin"*)
open https://github.com/${ACCOUNT}/lab0-c/actions
;;
*)
echo "Please activate at https://github.com/${ACCOUNT}/lab0-c/actions"
;;
esac
throw "Check this article: https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow\n\
Then, execute 'make' again."
fi

# 5. Install Git hooks
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

mkdir -p .git/hooks

ln -sf ../../scripts/pre-commit.hook .git/hooks/pre-commit || exit 1
Expand Down
14 changes: 10 additions & 4 deletions scripts/pre-push.hook
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/usr/bin/env bash

# Ensure that the common script exists and is readable, then verify it has no
# syntax errors and defines the required function.
common_script="$(dirname "$0")/../../scripts/common.sh"
[ -r "$common_script" ] || { echo "[!] '$common_script' not found or not readable." >&2; exit 1; }
bash -n "$common_script" >/dev/null 2>&1 || { echo "[!] '$common_script' contains syntax errors." >&2; exit 1; }
source "$common_script"
declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not define the required function." >&2; exit 1; }

set_colors

protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
RED='\033[0;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Validate repository
# commit 50c5ac53d31adf6baac4f8d3db6b3ce2215fee40
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-commit-msg.hook
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

COMMIT_MSG_FILE="$1"

Expand Down