-
Notifications
You must be signed in to change notification settings - Fork 3
165 lines (147 loc) · 5.56 KB
/
Copy pathcalm-test.yaml
File metadata and controls
165 lines (147 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright (c) 2025 Erick Bourgeois, firestoned
# SPDX-License-Identifier: Apache-2.0
#
# Tests for the reusable CALM workflow (.github/workflows/calm.yaml) and its
# argument-building script (.github/scripts/calm-args.sh).
#
# Three layers:
# 1. bats — unit tests on the shell script.
# 2. shellcheck — static analysis on the shell script.
# 3. integration — invokes the reusable workflow end-to-end against the
# checked-in architecture fixture.
#
# A separate job exercises the negative path (unknown command must fail).
name: CALM (tests)
on:
pull_request:
paths:
- '.github/workflows/calm.yaml'
- '.github/workflows/calm-test.yaml'
- '.github/scripts/calm-args.sh'
- '.github/scripts/calm-args.bats'
- 'docs/architecture/calm/**'
push:
branches:
- main
paths:
- '.github/workflows/calm.yaml'
- '.github/workflows/calm-test.yaml'
- '.github/scripts/calm-args.sh'
- '.github/scripts/calm-args.bats'
- 'docs/architecture/calm/**'
workflow_dispatch:
permissions:
contents: read
jobs:
# ── Unit: bats tests on the arg-building script ─────────────────────────────
bats:
name: 🧪 bats (calm-args.sh)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install bats-core
run: sudo apt-get update && sudo apt-get install -y bats
- name: Run bats suite
run: bats .github/scripts/calm-args.bats
# ── Static: shellcheck on the arg-building script ───────────────────────────
shellcheck:
name: 🔍 shellcheck
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Run shellcheck
run: shellcheck .github/scripts/calm-args.sh
# ── Integration: validate the checked-in CALM architecture ──────────────────
integration-validate:
name: ✅ integration — validate architecture
needs: [bats, shellcheck]
uses: ./.github/workflows/calm.yaml
with:
command: validate
architecture: docs/architecture/calm/architecture.json
format: pretty
verbose: true
# ── Integration: template rendering against a tiny inline fixture ───────────
#
# We render a minimal Handlebars template that enumerates node names. This
# exercises the `template` sub-command path (TEMPLATE_DIR + ARCH + OUTPUT +
# CLEAR_OUT) without requiring a full external bundle.
integration-template:
name: 🧱 integration — template (mermaid-style)
needs: [bats, shellcheck]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Prepare inline template
run: |
mkdir -p /tmp/calm-tpl
cat > /tmp/calm-tpl/nodes.md.hbs <<'HBS'
# Nodes
{{#each nodes}}
- {{this.unique-id}} ({{this.node-type}})
{{/each}}
HBS
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '20'
- name: Install @finos/calm-cli
run: npm install -g "@finos/calm-cli@1.37.0"
- name: Render template via calm-args.sh + calm
env:
CMD: template
ARCH: docs/architecture/calm/architecture.json
TEMPLATE_DIR: /tmp/calm-tpl
OUTPUT: /tmp/calm-out
CLEAR_OUT: "true"
VERBOSE: "true"
run: |
set -euo pipefail
mapfile -t args < <(./.github/scripts/calm-args.sh)
calm template "${args[@]}"
ls -la /tmp/calm-out
# Sanity-check that at least one file was produced.
test -n "$(ls -A /tmp/calm-out)"
# ── Negative: unknown command must fail the script with exit 2 ──────────────
negative-unknown-command:
name: ❌ negative — unknown command
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Unknown command exits non-zero
shell: bash
run: |
set +e
CMD=deploy ./.github/scripts/calm-args.sh
rc=$?
if [ "$rc" -eq 0 ]; then
echo "::error::Expected non-zero exit for unknown command, got 0"
exit 1
fi
if [ "$rc" -ne 2 ]; then
echo "::error::Expected exit code 2, got $rc"
exit 1
fi
echo "OK: script exited with $rc as expected"
# ── Negative: CMD unset must fail ───────────────────────────────────────────
negative-missing-cmd:
name: ❌ negative — missing CMD
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Unset CMD exits non-zero
shell: bash
run: |
set +e
env -u CMD ./.github/scripts/calm-args.sh
rc=$?
if [ "$rc" -eq 0 ]; then
echo "::error::Expected non-zero exit when CMD is unset, got 0"
exit 1
fi
echo "OK: script exited with $rc as expected"