Skip to content

Commit eccb964

Browse files
authored
Merge pull request #36 from kellenmurphy/makefile-pr-flow
Rework release targets for protected main
2 parents 27354bd + 1730de8 commit eccb964

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,46 @@ PATCH := $(word 3,$(subst ., ,$(CURRENT_VERSION)))
55

66
.DEFAULT_GOAL := help
77

8-
.PHONY: help patch minor major
8+
.PHONY: help patch minor major release-finish
99

1010
help:
11-
@echo "Usage: make [patch|minor|major]"
11+
@echo "Usage: make [patch|minor|major] — open a version-bump release PR"
12+
@echo " make release-finish — after the PR merges: tag + GitHub release"
1213
@echo " Current version: $(CURRENT_VERSION)"
1314

1415
patch:
1516
$(eval NEW_VERSION := $(MAJOR).$(MINOR).$(shell echo $$(($(PATCH)+1))))
16-
$(call _release,$(NEW_VERSION))
17+
$(call _start_release,$(NEW_VERSION))
1718

1819
minor:
1920
$(eval NEW_VERSION := $(MAJOR).$(shell echo $$(($(MINOR)+1))).0)
20-
$(call _release,$(NEW_VERSION))
21+
$(call _start_release,$(NEW_VERSION))
2122

2223
major:
2324
$(eval NEW_VERSION := $(shell echo $$(($(MAJOR)+1))).0.0)
24-
$(call _release,$(NEW_VERSION))
25+
$(call _start_release,$(NEW_VERSION))
2526

26-
define _release
27+
# Main is protected (PRs + status checks + signed commits required), so a
28+
# release happens in two phases: a version-bump PR, then — after merge —
29+
# tagging the merge commit and publishing the GitHub release.
30+
define _start_release
31+
@git diff --quiet && git diff --cached --quiet || { echo "[error] working tree not clean"; exit 1; }
32+
git fetch origin
33+
git switch -c release-$(1) origin/main
2734
sed -i.bak 's/__version__ = "$(CURRENT_VERSION)"/__version__ = "$(1)"/' py_conf_sync.py && rm py_conf_sync.py.bak
2835
git add py_conf_sync.py
2936
git commit -m "chore: bump version to $(1)"
30-
git tag v$(1)
31-
git push origin main --tags
37+
git push -u origin release-$(1)
38+
gh pr create --title "chore: bump version to $(1)" --body "Release v$(1). After merging, run \`make release-finish\` to tag and publish."
39+
@echo "Release PR opened. After it merges: make release-finish"
3240
endef
41+
42+
release-finish:
43+
git switch main
44+
git pull --ff-only
45+
@V=$$(grep -m1 '__version__' py_conf_sync.py | cut -d'"' -f2); \
46+
if git rev-parse "v$$V" >/dev/null 2>&1; then echo "[error] tag v$$V already exists"; exit 1; fi; \
47+
git tag -m "v$$V" "v$$V" && \
48+
git push origin "v$$V" && \
49+
gh release create "v$$V" --title "v$$V" --generate-notes && \
50+
echo "Released v$$V"

0 commit comments

Comments
 (0)