diff --git a/RELEASE.md b/RELEASE.md index 61439374..12ce93e7 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -13,11 +13,13 @@ We run the test workflow on: * `**.fish` files with the exception `conf.d/pure.fish`, as we have dedicated mechanism to manage versions bump ; * and workflow (`*.yml`) files -## Bumping version +## Versioning -**required:** You MUST **follow semantic versioning** based on [conventional commits][coco]. +**required:** Commits must **[follow conventional commits convention][coco]**. -Is triggered only on `master` and: +Versioning is done automatically based on commit messages and triggered only on `master` branch. + +Details: 1. We compute the [project's next version][next-version] using a GitHub Action ; 2. Then update `$pure_version` value in `./conf.d/pure.fish` ; @@ -29,3 +31,4 @@ The `add-version-tag.yml` pipeline is triggered only for `master` when `./conf.d [next-version]: https://github.com/thenativeweb/get-next-version [push]: https://github.com/ad-m/github-push-action +[coco]: https://www.conventionalcommits.org/en/v1.0.0/ diff --git a/functions/_pure_k8s_namespace.fish b/functions/_pure_k8s_namespace.fish index 94d32016..87e08c7a 100644 --- a/functions/_pure_k8s_namespace.fish +++ b/functions/_pure_k8s_namespace.fish @@ -1,3 +1,9 @@ function _pure_k8s_namespace - kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null + set namespace (kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null) + + if test -z "$namespace" + set namespace default + end + + echo $namespace end diff --git a/functions/_pure_prompt_k8s.fish b/functions/_pure_prompt_k8s.fish index cde20ae5..a2830583 100644 --- a/functions/_pure_prompt_k8s.fish +++ b/functions/_pure_prompt_k8s.fish @@ -4,14 +4,13 @@ function _pure_prompt_k8s and _pure_check_availability pure_enable_k8s kubectl and test -n (_pure_k8s_context) # todo: use $(cmd) syntax when Fish 3.3.1 is dropped - set --local symbol (_pure_set_color $pure_color_k8s_prefix)$pure_symbol_k8s_prefix set --local context (_pure_set_color $pure_color_k8s_context)(_pure_k8s_context) - set --local namespace (_pure_set_color $pure_color_k8s_namespace)(_pure_k8s_namespace) - if test -n "$namespace" - set --local namespace (_pure_set_color $pure_color_k8s_namespace)default - end + if test -n "$context" + set --local symbol (_pure_set_color $pure_color_k8s_prefix)$pure_symbol_k8s_prefix + set --local namespace (_pure_set_color $pure_color_k8s_namespace)(_pure_k8s_namespace) - echo "$symbol $context/$namespace" + echo "$symbol $context/$namespace" + end end end diff --git a/makefile b/makefile index a8f10f6c..a4368e57 100644 --- a/makefile +++ b/makefile @@ -22,6 +22,7 @@ build-pure-on: --target ${STAGE} \ --build-arg FISH_VERSION=${FISH_VERSION} \ --tag=pure-${STAGE}-${FISH_VERSION} \ + --load \ ./ .PHONY: dev-pure-on @@ -65,6 +66,7 @@ build-pure-on-nix: --file ./docker/${STAGE}.Dockerfile \ --build-arg FISH_VERSION=${FISH_VERSION} \ --tag=pure-${STAGE}-${FISH_VERSION} \ + --load \ ./ dev-pure-on-nix: STAGE?=nix diff --git a/tests/_pure_k8s_namespace.test.fish b/tests/_pure_k8s_namespace.test.fish index 7edc68a4..0841414c 100644 --- a/tests/_pure_k8s_namespace.test.fish +++ b/tests/_pure_k8s_namespace.test.fish @@ -5,8 +5,8 @@ source (status dirname)/../functions/_pure_k8s_namespace.fish function before_each - functions --erase head _clean_all_spy_calls + _clean_all_mocks end @@ -19,8 +19,16 @@ before_each before_each @test "_pure_k8s_namespace: call `kubectl config view…`" ( - function kubectl; echo (status current-function) $argv > /tmp/(status current-function).mock_calls; end # spy + _spy kubectl + + _pure_k8s_namespace > /dev/null - _pure_k8s_namespace _has_called kubectl "config view --minify --output jsonpath={..namespace}" ) $status -eq $SUCCESS + +before_each +@test "_pure_k8s_namespace: return default when no namespace is set" ( + _mock_response kubectl "" + + _pure_k8s_namespace +) = default diff --git a/tests/_pure_prompt_k8s.test.fish b/tests/_pure_prompt_k8s.test.fish index 0a59d2a8..4cccf996 100644 --- a/tests/_pure_prompt_k8s.test.fish +++ b/tests/_pure_prompt_k8s.test.fish @@ -8,7 +8,8 @@ source (status dirname)/../functions/_pure_check_availability.fish function before_each _purge_configs - _disable_colors + _clean_all_mocks + _disable_colors # we use mocks so cleaning them must happen before end function after_all @@ -25,14 +26,39 @@ end echo (_pure_prompt_k8s) ) = $EMPTY - before_each -@test "_pure_prompt_k8s: print kubernetes context and namespace" ( +@test "_pure_prompt_k8s: print kubernetes context and namespace when present" ( set --universal pure_enable_k8s true set --universal pure_symbol_k8s_prefix "☸" + _mock kubectl + _mock_response _pure_k8s_context "my-context" + _mock_response _pure_k8s_namespace "my-namespace" _pure_prompt_k8s ) = '☸ my-context/my-namespace' +before_each +@test "_pure_prompt_k8s: print nothing when context is not set" ( + set --universal pure_enable_k8s true + set --universal pure_symbol_k8s_prefix "☸" + + _mock kubectl + _mock_response _pure_k8s_context $EMPTY + + _pure_prompt_k8s +) $status -eq $SUCCESS + +before_each +@test "_pure_prompt_k8s: print default when namespace is not set" ( + set --universal pure_enable_k8s true + set --universal pure_symbol_k8s_prefix '☸' + + _mock_response _pure_k8s_context my-context + _mock_response kubectl $EMPTY + + _pure_prompt_k8s +) = '☸ my-context/default' + + after_all diff --git a/tests/mocks/cleaning.fish b/tests/mocks/cleaning.fish index 55f67619..5766e950 100644 --- a/tests/mocks/cleaning.fish +++ b/tests/mocks/cleaning.fish @@ -9,9 +9,9 @@ end function _clean_all_mocks \ --description "Clean all mock function" - for mock in $__mocks - if functions --query $mock - functions --erase $mock + for function_name in $__mocks + if functions --query $function_name + functions --erase $function_name end if functions --query __backup_$function_name # restore original function diff --git a/tests/mocks/spying.fish b/tests/mocks/spying.fish index da127634..9975b182 100644 --- a/tests/mocks/spying.fish +++ b/tests/mocks/spying.fish @@ -6,7 +6,7 @@ function _spy \ _backup_before_mocking $function_name function $function_name - echo (status current-function) >/tmp/(status current-function).mock_calls + echo -- (status current-function) $argv >/tmp/(status current-function).mock_calls end # spy end