-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (96 loc) · 4.15 KB
/
Makefile
File metadata and controls
110 lines (96 loc) · 4.15 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
.PHONY: deploy format commit-format check-undefined increment-version release trigger-workflow get-version check-gh-auth
# Default Python interpreter
PYTHON := uv run python
GIT_FILES := $(shell git ls-files "./morphcloud")
# Helper function to extract the version, defined once and reusable
get_current_version = $(shell grep -oP 'version = "\K[^"]+' pyproject.toml)
deploy: check-gh-auth format commit-format check-undefined increment-version release trigger-workflow
# Check that GitHub CLI is installed and user is authenticated
check-gh-auth:
@echo "Checking GitHub CLI authentication..."
@if ! command -v gh &> /dev/null; then \
echo "Error: GitHub CLI (gh) is not installed."; \
echo "Please install it from https://cli.github.com/"; \
exit 1; \
fi
@if gh auth status &> /dev/null; then \
echo "GitHub CLI authentication verified!"; \
elif gh repo view &> /dev/null; then \
echo "GitHub CLI token verified (repo access)."; \
else \
echo "Error: You are not authenticated with GitHub CLI."; \
echo "Set GH_TOKEN/GITHUB_TOKEN or run 'gh auth login' to authenticate."; \
exit 1; \
fi
# Format code with black and isort
format:
@echo "Formatting code with black and isort..."
uv run black ./morphcloud
uv run isort ./morphcloud
# Commit formatted changes (only already‑tracked files)
commit-format:
@echo "Staging formatted files already tracked..."
@git add -u ./morphcloud
@# Only create a commit if something is staged
@git diff --cached --quiet && echo "No formatting changes to commit." || git commit -m "chore: format"
# Check for undefined variables in all git-tracked files
check-undefined:
@echo "Checking for undefined variables..."
@for file in $(GIT_FILES); do \
echo "Checking $$file"; \
UNDEFINED=$$(ruff check "$$file" | grep ndefined || true); \
if [ ! -z "$$UNDEFINED" ]; then \
echo "Undefined variables found in $$file:"; \
echo "$$UNDEFINED"; \
exit 1; \
fi; \
done
@echo "No undefined variables found!"
# Increment version if current is less than the latest on PyPI
increment-version:
@echo "Checking current version against PyPI..."
uv run python ./scripts/increment_version.py
# Display the current version
get-version:
@echo "Current version is: $(call get_current_version)"
# Push to GitHub, create tag and GitHub release
release:
@echo "Pushing to GitHub and creating release..."
$(eval VERSION := $(get_current_version))
@echo "Version to release: $(VERSION)"
git diff --quiet pyproject.toml || git add pyproject.toml
git diff --quiet --cached || git commit -m "Bump version to $(VERSION)"
git push origin main || true
# Create git tag if it doesn't exist
git tag -l "v$(VERSION)" | grep -q . || git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
git push origin "v$(VERSION)" || true
# Create GitHub release if it doesn't exist
@if command -v gh &> /dev/null; then \
if ! gh release view "v$(VERSION)" &>/dev/null; then \
echo "Creating GitHub release v$(VERSION)..."; \
gh release create "v$(VERSION)" \
--title "v$(VERSION)" \
--notes "Release v$(VERSION) of morphcloud." \
--target main; \
else \
echo "GitHub release v$(VERSION) already exists, skipping creation."; \
fi; \
else \
echo "GitHub CLI not found. Please create the release manually at:"; \
echo "https://github.com/$(shell git config --get remote.origin.url | sed -e 's/.*github.com[:\/]\(.*\)\.git/\1/')/releases/new"; \
fi
@echo "Release created!"
# Trigger the GitHub workflow manually on the tagged release
trigger-workflow:
$(eval VERSION := $(get_current_version))
@echo "Triggering GitHub publish workflow for tag v$(VERSION)..."
@if command -v gh &> /dev/null; then \
echo "Running workflow publish.yaml on tag v$(VERSION)"; \
gh workflow run publish.yaml --ref "v$(VERSION)" || \
echo "Please trigger the workflow manually on the tag v$(VERSION)"; \
else \
echo "GitHub CLI not found. Please trigger the workflow manually at:"; \
echo "https://github.com/$(shell git config --get remote.origin.url | sed -e 's/.*github.com[:\/]\(.*\)\.git/\1/')/actions/workflows/publish.yaml"; \
echo "Be sure to select the 'v$(VERSION)' tag when triggering the workflow!"; \
fi
@echo "Deployment complete!"