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
2 changes: 2 additions & 0 deletions .base/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

export BASE_DEMO_ENV="${BASE_DEMO_ENV:-baseline}"
export BASE_DEMO_MESSAGE="${BASE_DEMO_MESSAGE:-Hello from base-demo activation.}"
export BASE_DEMO_ACTIVATED="${BASE_DEMO_ACTIVATED:-true}"
export BASE_DEMO_PROJECT_KIND="${BASE_DEMO_PROJECT_KIND:-reference-demo}"
2 changes: 2 additions & 0 deletions base_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ activate:

commands:
hello: ./src/hello.sh
env: ./src/env.sh
manifest: ./src/manifest.sh

test:
command: ./tests/validate.sh
Expand Down
31 changes: 29 additions & 2 deletions demo/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ project_shape_step() {
run_command test -f "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command test -f "$BASE_DEMO_ROOT/Brewfile"
run_command test -x "$BASE_DEMO_ROOT/src/hello.sh"
run_command test -x "$BASE_DEMO_ROOT/src/env.sh"
run_command test -x "$BASE_DEMO_ROOT/src/manifest.sh"
run_command test -x "$BASE_DEMO_ROOT/tests/validate.sh"
pause
}
Expand All @@ -129,6 +131,8 @@ manifest_step() {
step 2 "Manifest Contracts"
run_command grep -n "name: base-demo" "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command grep -n "hello: ./src/hello.sh" "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command grep -n "env: ./src/env.sh" "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command grep -n "manifest: ./src/manifest.sh" "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command grep -n "command: ./tests/validate.sh" "$BASE_DEMO_ROOT/base_manifest.yaml"
run_command grep -n "script: ./demo/demo.sh" "$BASE_DEMO_ROOT/base_manifest.yaml"
pause
Expand All @@ -139,7 +143,11 @@ activation_step() {
# shellcheck source=/dev/null
source "$BASE_DEMO_ROOT/.base/activate.sh"
printf 'BASE_DEMO_ENV=%s\n' "${BASE_DEMO_ENV:-unset}"
printf 'BASE_DEMO_ACTIVATED=%s\n' "${BASE_DEMO_ACTIVATED:-unset}"
printf 'BASE_DEMO_PROJECT_KIND=%s\n' "${BASE_DEMO_PROJECT_KIND:-unset}"
require_contains "activation" "${BASE_DEMO_ENV:-}" "baseline"
require_contains "activation" "${BASE_DEMO_ACTIVATED:-}" "true"
require_contains "activation" "${BASE_DEMO_PROJECT_KIND:-}" "reference-demo"
pause
}

Expand Down Expand Up @@ -167,6 +175,8 @@ command_discovery_step() {
output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" --list)"
printf '%s\n' "$output"
require_contains "run command list" "$output" "hello"
require_contains "run command list" "$output" "env"
require_contains "run command list" "$output" "manifest"
pause
}

Expand All @@ -180,10 +190,26 @@ run_step() {
pause
}

inspection_step() {
local env_output manifest_output

step 8 "Inspection Commands"
env_output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" env)"
printf '%s\n' "$env_output"
require_contains "env command" "$env_output" "BASE_PROJECT=base-demo"
require_contains "env command" "$env_output" "BASE_DEMO_PROJECT_KIND=reference-demo"

manifest_output="$(capture_command "$BASE_DEMO_BASECTL" run "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" manifest)"
printf '%s\n' "$manifest_output"
require_contains "manifest command" "$manifest_output" "base-demo manifest"
require_contains "manifest command" "$manifest_output" "commands:"
pause
}

test_step() {
local output

step 8 "Test Contract"
step 9 "Test Contract"
output="$(capture_command "$BASE_DEMO_BASECTL" test "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE")"
printf '%s\n' "$output"
require_contains "test command" "$output" "Repository baseline is present."
Expand All @@ -193,7 +219,7 @@ test_step() {
demo_step() {
local output

step 9 "Demo Contract"
step 10 "Demo Contract"
output="$(capture_command "$BASE_DEMO_BASECTL" demo "$BASE_DEMO_PROJECT" --workspace "$BASE_DEMO_WORKSPACE" --dry-run -- --non-interactive)"
printf '%s\n' "$output"
require_contains "demo command" "$output" "Would run demo"
Expand All @@ -216,6 +242,7 @@ main() {
activation_step
command_discovery_step
run_step
inspection_step
test_step
demo_step
printf '\nbase-demo walkthrough complete.\n'
Expand Down
15 changes: 15 additions & 0 deletions src/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail

print_var() {
local name="$1"
printf '%s=%s\n' "$name" "${!name:-unset}"
}

print_var BASE_PROJECT
print_var BASE_PROJECT_ROOT
print_var BASE_PROJECT_MANIFEST
print_var BASE_PROJECT_VENV_DIR
print_var BASE_DEMO_ENV
print_var BASE_DEMO_ACTIVATED
print_var BASE_DEMO_PROJECT_KIND
8 changes: 8 additions & 0 deletions src/manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

manifest="${BASE_PROJECT_MANIFEST:-base_manifest.yaml}"

printf 'base-demo manifest\n'
printf 'path=%s\n' "$manifest"
grep -nE '^(schema_version|brewfile|activate:|commands:|test:|demo:|artifacts:)' "$manifest"
17 changes: 16 additions & 1 deletion tests/demo_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@ case "$*" in
printf 'ok project base-demo is healthy.\n'
;;
run\ base-demo\ --workspace\ *\ --list)
printf 'hello ./src/hello.sh\n'
printf 'hello ./src/hello.sh\n'
printf 'env ./src/env.sh\n'
printf 'manifest ./src/manifest.sh\n'
;;
run\ base-demo\ --workspace\ *\ hello)
printf 'hello from base-demo\n'
printf 'BASE_PROJECT=base-demo\n'
printf 'BASE_DEMO_ENV=%s\n' "${BASE_DEMO_ENV:-unset}"
;;
run\ base-demo\ --workspace\ *\ env)
printf 'BASE_PROJECT=base-demo\n'
printf 'BASE_DEMO_PROJECT_KIND=%s\n' "${BASE_DEMO_PROJECT_KIND:-unset}"
;;
run\ base-demo\ --workspace\ *\ manifest)
printf 'base-demo manifest\n'
printf 'commands:\n'
;;
test\ base-demo\ --workspace\ *)
printf 'Repository baseline is present.\n'
;;
Expand All @@ -75,15 +85,20 @@ EOF
[[ "$output" == *"Workspace Discovery"* ]]
[[ "$output" == *"Project Diagnostics"* ]]
[[ "$output" == *"Declared Commands"* ]]
[[ "$output" == *"Inspection Commands"* ]]
[[ "$output" == *"BASE_DEMO_ENV=baseline"* ]]
[[ "$output" == *"BASE_DEMO_PROJECT_KIND=reference-demo"* ]]
[[ "$output" == *"hello from base-demo"* ]]
[[ "$output" == *"base-demo manifest"* ]]
[[ "$output" == *"Repository baseline is present."* ]]
[[ "$output" == *"base-demo walkthrough complete."* ]]
grep -Fq "basectl projects list --workspace " "$state_file"
grep -Fqx "basectl check base-demo" "$state_file"
grep -Fqx "basectl doctor base-demo" "$state_file"
grep -Eq "^basectl run base-demo --workspace .+ --list$" "$state_file"
grep -Eq "^basectl run base-demo --workspace .+ hello$" "$state_file"
grep -Eq "^basectl run base-demo --workspace .+ env$" "$state_file"
grep -Eq "^basectl run base-demo --workspace .+ manifest$" "$state_file"
grep -Eq "^basectl test base-demo --workspace .+$" "$state_file"
grep -Eq "^basectl demo base-demo --workspace .+ --dry-run -- --non-interactive$" "$state_file"
}
14 changes: 13 additions & 1 deletion tests/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ required_files=(
Brewfile
.base/activate.sh
src/hello.sh
src/env.sh
src/manifest.sh
demo/demo.sh
tests/demo_test.bats
.github/workflows/tests.yml
Expand All @@ -23,7 +25,7 @@ for file in "${required_files[@]}"; do
}
done

for executable in tests/validate.sh .base/activate.sh src/hello.sh demo/demo.sh; do
for executable in tests/validate.sh .base/activate.sh src/hello.sh src/env.sh src/manifest.sh demo/demo.sh; do
[[ -x "$executable" ]] || {
printf 'Required file is not executable: %s\n' "$executable" >&2
exit 1
Expand All @@ -50,6 +52,16 @@ grep -Fq 'hello: ./src/hello.sh' base_manifest.yaml || {
exit 1
}

grep -Fq 'env: ./src/env.sh' base_manifest.yaml || {
printf 'base_manifest.yaml does not declare the env command.\n' >&2
exit 1
}

grep -Fq 'manifest: ./src/manifest.sh' base_manifest.yaml || {
printf 'base_manifest.yaml does not declare the manifest command.\n' >&2
exit 1
}

grep -Fq 'script: ./demo/demo.sh' base_manifest.yaml || {
printf 'base_manifest.yaml does not declare the demo script.\n' >&2
exit 1
Expand Down
Loading