NAMESPACE := fedoraserver
NAME      := general
ARTIFACT  := $(NAMESPACE)-$(NAME)

# The release version is supplied by the caller, NOT read from galaxy.yml.
# galaxy.yml only carries a placeholder; CI stamps the real version in at build
# time. Use: VERSION=1.2.3 make build
VERSION ?= 0.0.0

# Reject anything that isn't a plain dotted version before it reaches sed, which
# would otherwise fail with a confusing "unknown option to s" error.
ifeq ($(shell printf '%s' '$(VERSION)' | grep -cE '^[0-9]+\.[0-9]+\.[0-9]+$$'), 0)
  $(error VERSION='$(VERSION)' is not a valid X.Y.Z version)
endif

all: install lint

install:
	ansible-galaxy collection install -r requirements.yml

lint:
	ansible-lint

build:
	@sed -i 's/^[[:space:]]*version:.*/version: $(VERSION)/' galaxy.yml
	ansible-galaxy collection build --output-path build

clean:
	rm -rf build
	rm -f $(ARTIFACT)-*.tar.gz

# Print the collection identity, e.g. for RPM spec / packager cross-checks.
info:
	@echo "collection: $(NAMESPACE).$(NAME)"
	@echo "version:    $(VERSION)"
	@echo "rpm:        ansible-collection-$(NAMESPACE)-$(NAME)"

.PHONY: all install lint build clean info
