# Release Management Capability Makefile
# Provides release management targets for any Python project

# Capability metadata
CAPABILITY_NAME := release-management
CAPABILITY_DESCRIPTION := Comprehensive release management for Python projects

# Default target
.PHONY: help
help: ## Show release management help
	@echo "📦 Release Management Capability"
	@echo "================================"
	@echo ""
	@echo "Status & Validation:"
	@echo "  release-status               Show current release status and version information"
	@echo "  release-validate             Validate repository state for release readiness"
	@echo "  release-registry-info        Show package registry information and status"
	@echo ""
	@echo "Git Tag Management:"
	@echo "  release-tag VERSION=x.y.z    Create git tag for version"
	@echo ""
	@echo "Package Building:"
	@echo "  release-build                Build release packages using setuptools-scm"
	@echo "  release-clean                Clean build artifacts and temporary files"
	@echo ""
	@echo "Publishing Workflows:"
	@echo "  release-publish VERSION=x.y.z         Complete release workflow (tag + build)"
	@echo "  release-publish-gitea VERSION=x.y.z   Complete release + Gitea upload"
	@echo "  release-publish-pypi VERSION=x.y.z    Complete release + PyPI upload"
	@echo ""
	@echo "Upload Existing Packages:"
	@echo "  release-upload-gitea         Upload existing packages to Gitea registry"
	@echo "  release-upload-pypi          Upload existing packages to PyPI"
	@echo "  release-upload-testpypi      Upload existing packages to Test PyPI"
	@echo ""
	@echo "Dry Run Options:"
	@echo "  release-publish-dry-run VERSION=x.y.z  Dry run of release workflow"
	@echo "  release-upload-dry-run                  Dry run of package upload"
	@echo ""
	@echo "Development & Setup:"
	@echo "  release-management-install          Install release management capability"
	@echo "  release-management-install-dev      Install with development dependencies"
	@echo "  release-management-test             Run capability tests"
	@echo "  release-management-help             Show CLI help"

# Check if release management capability is available
RELEASE_CLI := $(shell command -v release 2> /dev/null)

# Status and Information
.PHONY: release-status
release-status: ## Show current release status and version information
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@echo "   Install with: pip install -e capabilities/release-management/"
	@exit 1
endif
	release status

.PHONY: release-validate
release-validate: ## Validate repository state for release readiness
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release validate

.PHONY: release-registry-info
release-registry-info: ## Show package registry information and status
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release registry-info

# Git Tag Management
.PHONY: release-tag
release-tag: ## Create git tag for version (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make release-tag VERSION=1.0.0"
	@exit 1
endif
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release tag --version $(VERSION)

# Package Building
.PHONY: release-build
release-build: ## Build release packages using setuptools-scm
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release build

.PHONY: release-clean
release-clean: ## Clean build artifacts and temporary files
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release clean

# Publishing Workflows
.PHONY: release-publish
release-publish: ## Complete release workflow: tag + build (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make release-publish VERSION=1.0.0"
	@exit 1
endif
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release publish --version $(VERSION)

.PHONY: release-publish-gitea
release-publish-gitea: ## Complete release workflow + Gitea upload (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make release-publish-gitea VERSION=1.0.0"
	@exit 1
endif
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release publish --version $(VERSION) --registry gitea

.PHONY: release-publish-pypi
release-publish-pypi: ## Complete release workflow + PyPI upload (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make release-publish-pypi VERSION=1.0.0"
	@exit 1
endif
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release publish --version $(VERSION) --registry pypi

# Upload Existing Packages
.PHONY: release-upload-gitea
release-upload-gitea: ## Upload existing packages to Gitea registry
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release upload --registry gitea

.PHONY: release-upload-pypi
release-upload-pypi: ## Upload existing packages to PyPI
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release upload --registry pypi

.PHONY: release-upload-testpypi
release-upload-testpypi: ## Upload existing packages to Test PyPI
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release upload --registry testpypi

# Dry Run Options
.PHONY: release-publish-dry-run
release-publish-dry-run: ## Dry run of complete release workflow (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make release-publish-dry-run VERSION=1.0.0"
	@exit 1
endif
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release publish --version $(VERSION) --dry-run

.PHONY: release-upload-dry-run
release-upload-dry-run: ## Dry run of package upload to default registry
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@exit 1
endif
	release upload --dry-run

# Development and Setup
.PHONY: release-management-install
release-management-install: ## Install release management capability
	pip install -e capabilities/release-management/

.PHONY: release-management-install-dev
release-management-install-dev: ## Install release management capability with dev dependencies
	pip install -e "capabilities/release-management/[dev]"

.PHONY: release-management-test
release-management-test: ## Run release management capability tests
	cd capabilities/release-management && pytest tests/

.PHONY: release-management-help
release-management-help: ## Show release management CLI help
ifndef RELEASE_CLI
	@echo "❌ Release management capability not installed"
	@echo "   Install with: make release-management-install"
	@exit 1
endif
	release --help

# Convenience aliases
.PHONY: release-upload
release-upload: release-upload-gitea ## Upload packages to default registry (gitea)

.PHONY: package
package: release-build ## Build packages (alias for release-build)

.PHONY: publish
publish: ## Publish release to default registry (requires VERSION=x.y.z)
ifndef VERSION
	@echo "❌ VERSION is required. Usage: make publish VERSION=1.0.0"
	@exit 1
endif
	@make release-publish-gitea VERSION=$(VERSION)

# Meta information for capability discovery
.PHONY: capability-info
capability-info: ## Show capability information
	@echo "Name: $(CAPABILITY_NAME)"
	@echo "Description: $(CAPABILITY_DESCRIPTION)"
	@echo "Targets:"
	@$(MAKE) --no-print-directory help | grep "^  " | sed 's/^  /    /'