port the make list functions and JWT, and expose the framework variables to hooks

lib/str.sh gains firstword, lastword, or, patsubst, filter, filter_out,
addprefix, addsuffix and jwt: what the catalogue .mk files are written in.
The make JWT macro split on the commas of its payload; this one does not.

lib/context.sh registers COMPOSE_PROJECT_NAME, APP, DOCKER_NETWORK_* and the
rest as lazy defaults, so a converted .mk keeps reading them as it did.

Hooks also load a directory-level _stack.env and _stack.sh, for the .mk files
of the catalogue that hold settings for several stacks at once.
This commit is contained in:
Yann Autissier
2026-09-03 21:58:22 +02:00
parent 3e55cdcd14
commit 6192d73cbe
8 changed files with 199 additions and 36 deletions
+52
View File
@@ -68,3 +68,55 @@ Describe 'lib/str.sh'
End
End
End
# The make list functions the catalogue relies on, ported so that a stack hook
# reads like the .mk it replaces.
Describe 'lib/str.sh list functions'
It 'takes the first and last word'
When call myos_firstword "a b c"
The output should equal "a"
End
It 'takes the last word'
When call myos_lastword "a b c"
The output should equal "c"
End
It 'returns the first argument that is not empty'
When call myos_or "" "" "third"
The output should equal "third"
End
Describe 'myos_patsubst'
Parameters
"%" "pre%" "a b" "prea preb"
"%.yml" "%.yaml" "a.yml b.md" "a.yaml b.md"
"%" "%/" "x y" "x/ y/"
End
It "substitutes $1 -> $2 in $3"
When call myos_patsubst "$1" "$2" "$3"
The output should equal "$4"
End
End
It 'filters a list'
When call myos_filter "a%" "abc bcd axe"
The output should equal "abc axe"
End
It 'filters a list out'
When call myos_filter_out "local master main" "staging"
The output should equal "staging"
End
It 'drops the words it is told to'
When call myos_filter_out "local master main" "master"
The output should equal ""
End
It 'adds a prefix and a suffix'
When call myos_addprefix "x." "a b"
The output should equal "x.a x.b"
End
End
Describe 'lib/str.sh myos_jwt'
It 'signs a token whose payload decodes back'
When call myos_jwt "" '{"role":"anon"}' secret
The output should start with "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
The output should include "eyJyb2xlIjoiYW5vbiJ9"
End
End