Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce task make target that runs tests before committing the provided message #353

Merged
merged 1 commit into from
Nov 26, 2024
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ check-manifest:
.PHONY: generate
generate:
@go generate ./...

.PHONY: task
task:
@./task.sh "$(m)"
40 changes: 40 additions & 0 deletions task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

if [[ -z "$1" ]]; then
echo "Please provide a commit message"
exit 1
fi
created_files=$(git ls-files --others --exclude-standard)
modified_files=$(git diff --name-only)
staged_files=$(git diff --cached --name-only)
echo -e "-------------"
if [[ -n "${created_files}${modified_files}" ]]; then
echo -e "\033[1;31mChanges:\033[0m"
echo -e "${created_files}${created_files:+\n}${modified_files}"
echo
fi
if [[ -n "$staged_files" ]]; then
echo -e "\033[1;32mStaged changes:\033[0m"
echo -e "$staged_files"
echo
fi
echo -e "-------------"
echo
if [[ -n "${created_files}${modified_files}" ]]; then
echo "Please stage all files before running this command"
exit 1
fi
if [[ -z "$staged_files" ]]; then
echo "No files are staged"
exit 1
fi

echo "Running tests:"
.ci/test > /dev/null 2>&1
echo "Running integration tests:"
.ci/integration-test > /dev/null 2>&1

commit_message="[task] $1"
git commit -m"$commit_message"