1+ # BodhiApp Release Management
2+ # This file contains release logic for llama-server binaries and delegation to base-images
3+ # It keeps the original Makefile clean while providing standardized release commands
4+
5+ .PHONY: release-server release-base-images help-bodhiapp show-server-git-info validate-server-release clean-server-release sync-upstream sync-upstream-check
6+
7+ # Function to check git branch status - borrowed from base-images/Makefile
8+ define check_git_branch
9+ @CURRENT_BRANCH=$$(git branch --show-current) && \
10+ if [ "$$CURRENT_BRANCH" != "master" ]; then \
11+ read -p "Warning: You are not on master branch (current: $$CURRENT_BRANCH). Continue? [y/N] " confirm && \
12+ if [ "$$confirm" != "y" ]; then \
13+ echo "Aborting release." && exit 1; \
14+ fi \
15+ fi && \
16+ echo "Fetching latest changes from remote..." && \
17+ git fetch origin master && \
18+ LOCAL_HEAD=$$(git rev-parse HEAD) && \
19+ REMOTE_HEAD=$$(git rev-parse origin/master) && \
20+ if [ "$$LOCAL_HEAD" != "$$REMOTE_HEAD" ]; then \
21+ echo "Warning: Your local master branch is different from origin/master" && \
22+ echo "Local: $$LOCAL_HEAD" && \
23+ echo "Remote: $$REMOTE_HEAD" && \
24+ read -p "Continue anyway? [y/N] " confirm && \
25+ if [ "$$confirm" != "y" ]; then \
26+ echo "Aborting release." && exit 1; \
27+ fi \
28+ fi
29+ endef
30+
31+ # Function to safely delete existing tag - borrowed from base-images/Makefile
32+ define delete_tag_if_exists
33+ echo "Checking for existing tag $(1)..." && \
34+ if git rev-parse "$(1)" >/dev/null 2>&1; then \
35+ read -p "Tag $(1) already exists. Delete and recreate? [y/N] " confirm && \
36+ if [ "$$confirm" = "y" ]; then \
37+ echo "Deleting existing tag $(1)..." && \
38+ git tag -d "$(1)" 2>/dev/null || true && \
39+ git push --delete origin "$(1)" 2>/dev/null || true; \
40+ else \
41+ echo "Aborting release." && exit 1; \
42+ fi \
43+ fi
44+ endef
45+
46+ # Function to create date-based version (YYYYMMDD format)
47+ define create_version_from_git
48+ if [ "$$(uname)" = "Darwin" ]; then \
49+ VERSION="$$(date +%Y%m%d)"; \
50+ else \
51+ VERSION="$$(date +%Y%m%d)"; \
52+ fi && \
53+ echo "$$VERSION"
54+ endef
55+
56+ # Function to validate release prerequisites
57+ define validate_release_prerequisites
58+ echo "Validating release prerequisites..." && \
59+ if ! command -v git >/dev/null 2>&1; then \
60+ echo "Error: git is required but not installed" && exit 1; \
61+ fi && \
62+ if ! git rev-parse --git-dir >/dev/null 2>&1; then \
63+ echo "Error: Not in a git repository" && exit 1; \
64+ fi && \
65+ if [ ! -f ".github/workflows/llama-server.yml" ]; then \
66+ echo "Error: llama-server.yml workflow not found" && exit 1; \
67+ fi && \
68+ if ! git diff-index --quiet HEAD --; then \
69+ echo "Error: Working directory has uncommitted changes. Please commit or reset changes before release." && exit 1; \
70+ fi && \
71+ echo "Prerequisites validated successfully"
72+ endef
73+
74+ # Function to validate upstream sync prerequisites
75+ define validate_sync_prerequisites
76+ echo "Validating sync prerequisites..." && \
77+ if ! command -v git >/dev/null 2>&1; then \
78+ echo "Error: git is required but not installed" && exit 1; \
79+ fi && \
80+ if ! git rev-parse --git-dir >/dev/null 2>&1; then \
81+ echo "Error: Not in a git repository" && exit 1; \
82+ fi && \
83+ if ! git remote get-url gg >/dev/null 2>&1; then \
84+ echo "Error: 'gg' remote not configured. Please add upstream remote as 'gg'" && exit 1; \
85+ fi && \
86+ if ! git diff-index --quiet HEAD --; then \
87+ echo "Error: Working directory has uncommitted changes. Please commit or reset changes before sync." && exit 1; \
88+ fi && \
89+ CURRENT_BRANCH=$$(git branch --show-current) && \
90+ if [ "$$CURRENT_BRANCH" != "master" ]; then \
91+ echo "Error: Must be on master branch for sync. Current branch: $$CURRENT_BRANCH" && exit 1; \
92+ fi && \
93+ echo "Sync prerequisites validated successfully"
94+ endef
95+
96+ # Release binary builds (all platforms) - creates both branch and tag
97+ release-server: ## Release llama-server binaries (creates bodhiapp_YYYYMMDD branch + llama-server/vYYYYMMDD tag)
98+ @echo "Preparing to release llama-server binaries..."
99+ @$(call validate_release_prerequisites)
100+ $(call check_git_branch)
101+ @echo "Creating version from current date..."
102+ @VERSION=$$($(call create_version_from_git)) && \
103+ BRANCH_NAME="bodhiapp_$$VERSION" && \
104+ TAG_NAME="llama-server/v$$VERSION" && \
105+ echo "Version: $$VERSION" && \
106+ echo "Release branch: $$BRANCH_NAME" && \
107+ echo "Release tag: $$TAG_NAME" && \
108+ $(call delete_tag_if_exists,$$TAG_NAME) && \
109+ echo "Creating release branch $$BRANCH_NAME..." && \
110+ if git show-ref --verify --quiet refs/heads/$$BRANCH_NAME; then \
111+ echo "Branch $$BRANCH_NAME already exists, switching to it..." && \
112+ git checkout $$BRANCH_NAME; \
113+ else \
114+ git checkout -b $$BRANCH_NAME; \
115+ fi && \
116+ echo "Pushing release branch to origin..." && \
117+ git push origin $$BRANCH_NAME && \
118+ echo "Creating and pushing release tag $$TAG_NAME..." && \
119+ git tag "$$TAG_NAME" && \
120+ git push origin "$$TAG_NAME" && \
121+ echo "Switching back to master..." && \
122+ git checkout master && \
123+ echo "Release created successfully:" && \
124+ echo " Branch: $$BRANCH_NAME (for support/hotfixes)" && \
125+ echo " Tag: $$TAG_NAME (triggers CI/CD)" && \
126+ echo " GitHub workflow will handle the binary build and release."
127+
128+ # Release Docker base images (all variants) - creates both branch and tag
129+ release-base-images: ## Release Docker base images (creates bodhiapp_YYYYMMDD branch + base-images/vYYYYMMDD tag)
130+ @echo "Preparing to release Docker base images..."
131+ @$(call validate_release_prerequisites)
132+ $(call check_git_branch)
133+ @echo "Creating version from current date..."
134+ @VERSION=$$($(call create_version_from_git)) && \
135+ BRANCH_NAME="bodhiapp_$$VERSION" && \
136+ TAG_NAME="base-images/v$$VERSION" && \
137+ echo "Version: $$VERSION" && \
138+ echo "Release branch: $$BRANCH_NAME" && \
139+ echo "Release tag: $$TAG_NAME" && \
140+ $(call delete_tag_if_exists,$$TAG_NAME) && \
141+ echo "Creating release branch $$BRANCH_NAME..." && \
142+ if git show-ref --verify --quiet refs/heads/$$BRANCH_NAME; then \
143+ echo "Branch $$BRANCH_NAME already exists, switching to it..." && \
144+ git checkout $$BRANCH_NAME; \
145+ else \
146+ git checkout -b $$BRANCH_NAME; \
147+ fi && \
148+ echo "Pushing release branch to origin..." && \
149+ git push origin $$BRANCH_NAME && \
150+ echo "Creating and pushing release tag $$TAG_NAME..." && \
151+ git tag "$$TAG_NAME" && \
152+ git push origin "$$TAG_NAME" && \
153+ echo "Switching back to master..." && \
154+ git checkout master && \
155+ echo "Release created successfully:" && \
156+ echo " Branch: $$BRANCH_NAME (for support/hotfixes)" && \
157+ echo " Tag: $$TAG_NAME (triggers CI/CD)" && \
158+ echo " GitHub workflow will handle the Docker image build and release."
159+
160+ show-server-git-info: ## Show current git commit information for llama-server version generation
161+ @echo "=== Git Information for llama-server Version Generation ==="
162+ @COMMIT_HASH=$$(git rev-parse --short=7 HEAD) && \
163+ VERSION=$$($(call create_version_from_git)) && \
164+ BRANCH_NAME="bodhiapp_$$VERSION" && \
165+ TAG_NAME="llama-server/v$$VERSION" && \
166+ echo "Current commit: $$COMMIT_HASH" && \
167+ echo "Current date: $$(date '+%Y-%m-%d %H:%M:%S')" && \
168+ echo "Generated version: $$VERSION" && \
169+ echo "Release branch: $$BRANCH_NAME" && \
170+ echo "Release tag: $$TAG_NAME"
171+ @echo "============================================="
172+
173+ validate-server-release: ## Validate prerequisites for llama-server release
174+ @$(call validate_release_prerequisites)
175+ @echo "llama-server release validation completed successfully"
176+
177+ clean-server-release: ## Remove local llama-server release tags (interactive)
178+ @echo "Cleaning up local llama-server tags..."
179+ @git tag -l "llama-server/v*" | while read tag; do \
180+ read -p "Delete local tag $$tag? [y/N] " confirm && \
181+ if [ "$$confirm" = "y" ]; then \
182+ git tag -d "$$tag" && echo "Deleted: $$tag"; \
183+ fi \
184+ done
185+
186+ sync-upstream-check: ## Check what would be synced from upstream (dry-run)
187+ @echo "=== Upstream Sync Check ==="
188+ @$(call validate_sync_prerequisites)
189+ @echo "Fetching latest from upstream (gg)..."
190+ @git fetch gg
191+ @echo ""
192+ @echo "Commits in upstream (gg/master) not in our master:"
193+ @git log --oneline master..gg/master | head -10 || echo " (none - we are up to date)"
194+ @echo ""
195+ @echo "Our commits that will be rebased on top of upstream:"
196+ @git log --oneline --grep="\[Amir\]" gg/master..master || echo " (none - no custom commits)"
197+ @echo ""
198+ @echo "Total upstream commits ahead: $$(git rev-list --count master..gg/master)"
199+ @echo "Total our commits to rebase: $$(git rev-list --count gg/master..master)"
200+ @echo ""
201+ @echo "To proceed with sync: make sync-upstream"
202+
203+ sync-upstream: ## Fetch upstream and rebase master preserving our changes (does not push)
204+ @echo "=== Syncing with Upstream ==="
205+ @$(call validate_sync_prerequisites)
206+ @echo "Fetching latest from upstream (gg)..."
207+ @git fetch gg
208+ @echo "Rebasing master onto gg/master..."
209+ @if git rebase gg/master; then \
210+ echo "Rebase completed successfully!"; \
211+ echo ""; \
212+ echo "Summary:"; \
213+ echo " Master branch rebased onto latest upstream"; \
214+ echo " Your changes preserved on top"; \
215+ echo ""; \
216+ echo "Next steps:"; \
217+ echo " 1. Review the rebased commits"; \
218+ echo " 2. Test your changes"; \
219+ echo " 3. Push to origin when ready: git push origin master --force-with-lease"; \
220+ else \
221+ echo ""; \
222+ echo "Rebase failed due to conflicts."; \
223+ echo "Please resolve conflicts manually:"; \
224+ echo " 1. Edit conflicted files"; \
225+ echo " 2. git add <resolved-files>"; \
226+ echo " 3. git rebase --continue"; \
227+ echo " 4. Or abort: git rebase --abort"; \
228+ exit 1; \
229+ fi
230+
231+ # Show BodhiApp-specific targets
232+ help-bodhiapp: ## Show BodhiApp release targets
233+ @echo ''
234+ @echo 'BodhiApp Release Targets:'
235+ @echo ' make release-server - Release llama-server binaries (creates branch + tag)'
236+ @echo ' make release-base-images - Release Docker base images (creates branch + tag)'
237+ @echo ' make show-server-git-info - Show version info for releases'
238+ @echo ' make validate-server-release - Validate release prerequisites'
239+ @echo ' make clean-server-release - Clean local release tags'
240+ @echo ''
241+ @echo 'BodhiApp Upstream Sync Targets:'
242+ @echo ' make sync-upstream-check - Check what would be synced (dry-run)'
243+ @echo ' make sync-upstream - Rebase master on upstream (does not push)'
244+ @echo ''
245+ @echo 'BodhiApp Help:'
246+ @echo ' make help-bodhiapp - Show this help message'
247+ @echo ''
248+ @echo 'For more details, see README-bodhiapp.md'
0 commit comments