Files
evercatch-php/Makefile

71 lines
2.7 KiB
Makefile

.PHONY: help install tag publish packagist-update gitea-publish
GITEA_URL := https://git.psmattas.com
GITEA_OWNER := Evercatch
GITEA_REPO := evercatch-php
PACKAGIST_VENDOR := evercatch
PACKAGIST_PACKAGE := evercatch-php
# Read current version from git tags
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "none")
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo " Current version: $(VERSION)"
install: ## Install dependencies via Composer
composer install
# Usage: make tag VERSION=v0.1.0
tag: ## Create and push a git tag (VERSION=v0.x.x required)
ifndef VERSION
$(error VERSION is not set. Usage: make tag VERSION=v0.1.0)
endif
@echo "Tagging $(VERSION)..."
git tag -a $(VERSION) -m "Release $(VERSION)"
git push origin $(VERSION)
@echo "Tag $(VERSION) pushed."
# Usage: make publish VERSION=v0.1.0
publish: ## Tag, push, update Packagist, and publish to Gitea (VERSION=v0.x.x required)
ifndef VERSION
$(error VERSION is not set. Usage: make publish VERSION=v0.1.0)
endif
$(MAKE) tag VERSION=$(VERSION)
$(MAKE) packagist-update
$(MAKE) gitea-publish VERSION=$(VERSION)
packagist-update: ## Trigger a Packagist crawl (requires PACKAGIST_TOKEN env var)
ifndef PACKAGIST_TOKEN
$(error PACKAGIST_TOKEN is not set. Export it first: export PACKAGIST_TOKEN=your_token)
endif
@echo "Triggering Packagist update..."
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"repository":{"url":"$(GITEA_URL)/$(GITEA_OWNER)/$(GITEA_REPO)"}}' \
"https://packagist.org/api/update-package?username=$(PACKAGIST_VENDOR)&apiToken=$(PACKAGIST_TOKEN)" \
| python3 -m json.tool || true
@echo "Packagist notified."
gitea-publish: ## Zip and PUT package to Gitea Composer registry (requires GITEA_TOKEN, GITEA_USER, VERSION)
ifndef GITEA_TOKEN
$(error GITEA_TOKEN is not set. Export it first: export GITEA_TOKEN=your_token)
endif
ifndef GITEA_USER
$(error GITEA_USER is not set. Export it first: export GITEA_USER=your_username)
endif
ifndef VERSION
$(error VERSION is not set. Usage: make gitea-publish VERSION=v0.1.0)
endif
$(eval SEMVER := $(shell echo $(VERSION) | sed 's/^v//'))
@echo "Creating zip from git archive..."
git archive --format=zip HEAD > /tmp/$(GITEA_REPO)-$(SEMVER).zip
@echo "Publishing $(SEMVER) to Gitea Composer registry..."
curl -s -w "\nHTTP %{http_code}\n" \
--user "$(GITEA_USER):$(GITEA_TOKEN)" \
--upload-file /tmp/$(GITEA_REPO)-$(SEMVER).zip \
"$(GITEA_URL)/api/packages/$(GITEA_OWNER)/composer?version=$(SEMVER)"
rm -f /tmp/$(GITEA_REPO)-$(SEMVER).zip
@echo "Done. Check: $(GITEA_URL)/$(GITEA_OWNER)/$(GITEA_REPO)/packages"