-
-
Notifications
You must be signed in to change notification settings - Fork 13
test: add tests #40
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
test: add tests #40
Changes from all commits
3194135
817b779
a18fbbc
cb985e1
aaab382
276b554
ab24b7c
30fd8ec
89b7ff0
9daa8e3
2b8830d
741a74f
5c4851d
5230615
81c6349
ae3fde4
5cfbf6f
d0ee5f5
33d7959
74e7866
adaba93
b7b3332
d051b86
58a7cd2
86ea3e7
d9c4554
8b27389
4dbf6a5
305fd7f
13b7963
8a132e1
c560806
9ddd142
fa48127
ac4e8ec
010db32
f839b18
5a35f55
ea63a2e
61d0391
582fbd1
fe3b837
836385e
9634795
4c5c6f8
193809d
b614dd3
2d4bf82
8233886
ec5f9ae
fa382fe
f5ffb0c
bd2078a
158e402
066bfc6
7b0f81f
75c62c8
e1a08ca
c6514fc
e7fce0f
ba82832
69b05ec
47597f4
78aaefe
6cc6d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,16 @@ defaults: | |
| shell: bash -el {0} | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run Tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Setup BATS | ||
| uses: bats-core/[email protected] | ||
| - name: Run BATS tests | ||
| run: bats --jobs 4 --timing tests/*.bats | ||
|
|
||
| run-ci: | ||
| name: Run CI | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -23,26 +33,22 @@ jobs: | |
| - uses: actions/setup-python@v6 | ||
| with: | ||
| check-latest: true | ||
| cache: "pip" | ||
| - name: Install pre-commit | ||
| run: | | ||
| python3 -m pip install --upgrade pip | ||
| python3 -m pip install --upgrade pre-commit | ||
| - name: Set cache date | ||
| run: | | ||
| echo "DATE=$(date +'%Y%m%d')" >> "$GITHUB_ENV" | ||
| - name: Cache pre-commit hooks | ||
| id: cache-pre-commit-hooks | ||
| uses: actions/cache@v5 | ||
| env: | ||
| CACHE_NUMBER: 0 | ||
| CACHE_NUMBER: 1 | ||
| with: | ||
| path: ~/.cache/pre-commit | ||
| key: ${{ runner.os }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} # yamllint disable-line rule:line-length | ||
| - name: Install pre-commit hooks | ||
| key: ${{ runner.os }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }}-${{ env.CACHE_NUMBER }} # yamllint disable-line rule:line-length | ||
| - name: Install pre-commit hook environments | ||
| if: steps.cache-pre-commit-hooks.outputs.cache-hit != 'true' | ||
| run: | | ||
| pre-commit install | ||
| pre-commit install-hooks | ||
| - name: Run pre-commit hooks | ||
| run: | | ||
| pre-commit run --all-files | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| extends: default | ||
|
|
||
| yaml-files: | ||
| - ".yamlfmt" | ||
| - ".yamllint" | ||
| - "*.yaml" | ||
| - "*.yml" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| .ONESHELL: | ||
|
|
||
| DEBUG ?= false | ||
| VERBOSE ?= false | ||
|
|
||
| ifeq ($(DEBUG),true) | ||
| MAKEFLAGS += --debug=v | ||
| else ifneq ($(VERBOSE),true) | ||
| MAKEFLAGS += --silent | ||
| endif | ||
|
|
||
| PRECOMMIT ?= pre-commit | ||
| ifneq ($(shell command -v prek >/dev/null 2>&1 && echo y),) | ||
| PRECOMMIT := prek | ||
| ifneq ($(filter true,$(DEBUG) $(VERBOSE)),) | ||
| $(info Using prek for pre-commit checks) | ||
| ifeq ($(DEBUG),true) | ||
| PRECOMMIT := $(PRECOMMIT) -v | ||
| endif | ||
| endif | ||
| endif | ||
|
|
||
| # Terminal formatting (tput with fallbacks to ANSI codes) | ||
| _COLOR := $(shell tput sgr0 2>/dev/null || printf '\033[0m') | ||
| BOLD := $(shell tput bold 2>/dev/null || printf '\033[1m') | ||
| CYAN := $(shell tput setaf 6 2>/dev/null || printf '\033[0;36m') | ||
| GREEN := $(shell tput setaf 2 2>/dev/null || printf '\033[0;32m') | ||
| RED := $(shell tput setaf 1 2>/dev/null || printf '\033[0;31m') | ||
| YELLOW := $(shell tput setaf 3 2>/dev/null || printf '\033[0;33m') | ||
|
|
||
| .DEFAULT_GOAL := help | ||
| .PHONY: help | ||
| help: ## Show this help message | ||
| @echo "$(BOLD)Available targets:$(_COLOR)" | ||
| @grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | ||
| awk 'BEGIN {FS = ":.*?## "; max = 0} \ | ||
| {if (length($$1) > max) max = length($$1)} \ | ||
| {targets[NR] = $$0} \ | ||
| END {for (i = 1; i <= NR; i++) { \ | ||
| split(targets[i], arr, FS); \ | ||
| printf "$(CYAN)%-*s$(_COLOR) %s\n", max + 2, arr[1], arr[2]}}' | ||
| @echo | ||
| @echo "$(BOLD)Environment variables:$(_COLOR)" | ||
| @echo " $(YELLOW)DEBUG$(_COLOR) = true|false Set to true to enable debug output (default: false)" | ||
| @echo " $(YELLOW)VERBOSE$(_COLOR) = true|false Set to true to enable verbose output (default: false)" | ||
|
|
||
| .PHONY: develop | ||
| WITH_HOOKS ?= true | ||
| develop: ## Set up the project for development (WITH_HOOKS={true|false}, default=true) | ||
| @if ! git config --local --get-all include.path | grep -q ".gitconfigs/alias"; then \ | ||
| git config --local --add include.path "$(CURDIR)/.gitconfigs/alias"; \ | ||
| fi | ||
| @git config blame.ignoreRevsFile .git-blame-ignore-revs | ||
| @set -e; \ | ||
| if command -v git-lfs >/dev/null 2>&1; then \ | ||
| git lfs install --local --skip-repo || true; \ | ||
| fi; \ | ||
| current_branch=$$(git branch --show-current); \ | ||
| stash_was_needed=0; \ | ||
| cleanup() { \ | ||
| exit_code=$$?; \ | ||
| if [ "$$current_branch" != "$$(git branch --show-current)" ]; then \ | ||
| echo "$(YELLOW)Attempting to return to $$current_branch...$(_COLOR)"; \ | ||
| if git switch "$$current_branch" 2>/dev/null; then \ | ||
| echo "Successfully returned to $$current_branch"; \ | ||
| else \ | ||
| echo "$(RED)Error: Could not return to $$current_branch. You are on $$(git branch --show-current).$(_COLOR)" >&2; \ | ||
| if [ "$$exit_code" -eq 0 ]; then exit_code=1; fi; \ | ||
| fi; \ | ||
| fi; \ | ||
| if [ $$stash_was_needed -eq 1 ] && git stash list | head -1 | grep -q "Auto stash before switching to main"; then \ | ||
| echo "$(YELLOW)Note: Your stashed changes are still available. Run 'git stash pop' to restore them.$(_COLOR)"; \ | ||
| fi; \ | ||
| exit $$exit_code; \ | ||
| }; \ | ||
| trap cleanup EXIT; \ | ||
| if ! git diff --quiet || ! git diff --cached --quiet; then \ | ||
| git stash push -m "Auto stash before switching to main"; \ | ||
| stash_was_needed=1; \ | ||
| fi; \ | ||
| git switch main && git pull; \ | ||
| if command -v git-lfs >/dev/null 2>&1; then \ | ||
| git lfs pull || true; \ | ||
| fi; \ | ||
| git switch "$$current_branch"; \ | ||
| if [ $$stash_was_needed -eq 1 ]; then \ | ||
| if git stash apply; then \ | ||
| git stash drop; \ | ||
| else \ | ||
| echo "$(RED)Error: Stash apply had conflicts. Resolve them, then run: git stash drop$(_COLOR)"; \ | ||
| fi; \ | ||
| fi; \ | ||
| trap - EXIT | ||
| @if [ "$(WITH_HOOKS)" = "true" ]; then \ | ||
| $(MAKE) enable-pre-commit; \ | ||
| fi | ||
|
|
||
| .PHONY: test | ||
| PARALLEL ?= true | ||
| test: ## Run all tests (PARALLEL={true|false}, default=true) | ||
| @if [ "$(PARALLEL)" = "true" ]; then \ | ||
| echo "$(CYAN)Running tests in parallel...$(_COLOR)"; \ | ||
| bats --jobs 4 --timing tests/*.bats; \ | ||
| else \ | ||
| echo "$(CYAN)Running tests sequentially...$(_COLOR)"; \ | ||
| bats tests/*.bats; \ | ||
| fi | ||
|
|
||
| .PHONY: check | ||
| check: run-pre-commit test ## Run all code quality checks and tests | ||
|
|
||
| .PHONY: enable-pre-commit | ||
| enable-pre-commit: ## Enable pre-commit hooks (along with commit-msg and pre-push hooks) | ||
| @if command -v pre-commit >/dev/null 2>&1; then \ | ||
| pre-commit install --hook-type commit-msg --hook-type pre-commit --hook-type pre-push --hook-type prepare-commit-msg ; \ | ||
| else \ | ||
| echo "$(YELLOW)Warning: pre-commit is not installed. Skipping hook installation.$(_COLOR)"; \ | ||
| echo "Install it with: pip install pre-commit (or brew install pre-commit on macOS)"; \ | ||
| fi | ||
|
|
||
| .PHONY: run-pre-commit | ||
| run-pre-commit: ## Run the pre-commit checks | ||
| $(PRECOMMIT) run --all-files |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,8 @@ process_directory() { | |
| for file in "$dir"/.* "$dir"/*; do | ||
| # Skip if file doesn't exist (handles empty dirs) or if it's `.` or `..` | ||
| [[ -e $file && $file != "$dir/." && $file != "$dir/.." ]] || continue | ||
| # Skip symlinks to prevent loops and operating outside target tree | ||
| [[ -L $file ]] && continue | ||
|
Comment on lines
+70
to
+71
|
||
| if [[ -f $file ]]; then | ||
| # Check if the first line starts with #! | ||
| if head -n 1 "$file" | grep -q '^#!'; then | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,11 +61,14 @@ fi | |||||
| echo "Fetching latest remote info and pruning..." | ||||||
| git fetch --prune | ||||||
|
|
||||||
| # Identify local branches fully merged into the target branch. | ||||||
| MERGED_BRANCHES=$(git branch --merged "$TARGET_BRANCH" | | ||||||
| grep -v "$TARGET_BRANCH" | | ||||||
| # Identify local branches fully merged into the remote target branch. | ||||||
| # Using origin/$TARGET_BRANCH ensures we compare against the up-to-date remote. | ||||||
| # Wrap in subshell so filtering applies to both the primary and fallback command. | ||||||
| MERGED_BRANCHES=$( (git branch --merged "origin/$TARGET_BRANCH" 2>/dev/null || | ||||||
| git branch --merged "$TARGET_BRANCH") | | ||||||
|
Comment on lines
+67
to
+68
|
||||||
| grep -v "^\*" | | ||||||
| sed 's/^ //') | ||||||
| sed 's/^ //' | | ||||||
| grep -v -F -x "$TARGET_BRANCH") | ||||||
|
|
||||||
| if [ -z "$MERGED_BRANCHES" ]; then | ||||||
| echo "No local branches merged into '$TARGET_BRANCH' found. Nothing to clean." | ||||||
|
|
@@ -91,7 +94,8 @@ else | |||||
| fi | ||||||
|
|
||||||
| # Identify local branches that no longer have a remote. | ||||||
| STALE_BRANCHES=$(git branch -v | grep '\[gone\]' | awk '{print $1}') | ||||||
| # Use -vv to show tracking info; ": gone]" indicates deleted upstream | ||||||
| STALE_BRANCHES=$(git branch -vv | awk '/: gone]/ {print ($1 == "*" ? $2 : $1)}') | ||||||
|
||||||
| STALE_BRANCHES=$(git branch -vv | awk '/: gone]/ {print ($1 == "*" ? $2 : $1)}') | |
| STALE_BRANCHES=$(git branch -vv | awk '/ \[.*: gone\]/ {print ($1 == "*" ? $2 : $1)}') |
Uh oh!
There was an error while loading. Please reload this page.