-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (47 loc) · 1.45 KB
/
Makefile
File metadata and controls
55 lines (47 loc) · 1.45 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
# purpose: Test wrapper for Molecule scenarios in this collection.
# adr: ADR-0606-ansible-collections-release-process
# maintainer: HybridOps.Tech
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
COLLECTION_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ROLES_DIR := $(COLLECTION_ROOT)/roles
ROLE ?=
MOLECULE_ROLES := $(shell \
find "$(ROLES_DIR)" -mindepth 1 -maxdepth 1 -type d 2>/dev/null \
| while read -r d; do \
if [ -d "$$d/molecule/default" ]; then basename "$$d"; fi; \
done \
)
ifeq ($(strip $(ROLE)),)
TEST_ROLES := $(MOLECULE_ROLES)
else
TEST_ROLES := $(ROLE)
endif
.PHONY: help test
help:
@echo ""
@echo "Usage:"
@echo " make test ROLE=<role_name> (optional)"
@echo ""
@echo "Targets:"
@echo " make test Run molecule test for all roles with scenarios."
@echo " make test ROLE=<name> Run molecule test for a single role."
@echo ""
@echo "Detected roles with Molecule scenarios:"
@echo " $(MOLECULE_ROLES)"
@echo ""
test:
@if [ -z "$(strip $(TEST_ROLES))" ]; then \
echo "No roles with Molecule scenarios found under $(ROLES_DIR)"; \
exit 1; \
fi
@for r in $(TEST_ROLES); do \
role_dir="$(ROLES_DIR)/$$r"; \
if [ ! -d "$$role_dir/molecule/default" ]; then \
echo "Skipping $$r (no molecule/default scenario)"; \
continue; \
fi; \
echo "==> molecule test for role: $$r"; \
(cd "$$role_dir" && molecule test) || exit $$?; \
done