build(makefile): add 'release' target to automate release branch creation
Paul wanted a Makefile target that: - takes the target version as an argument (V=1.0.7-rc1), - creates a release/<V> branch from main, - runs 'dotnet-gitversion /updateprojectfiles' to bump <Version> across all .csproj from git history, - commits the bump on the release branch (not on main, so main stays clean), - pushes the new branch to origin. The /src/**/*.csproj paths and CHANGELOG.md are excluded from Forgejo's protected-branch rule so the bump commit goes through on the release branch. The target refuses to run unless the operator is already on main with a clean working tree — no automatic checkout to main, so the bump never lands on the wrong branch by accident. The version in the branch name (V=...) is an intent label. The version GitVersion writes into the .csproj is whatever GitVersion computes from git history (last tag + commit count), so assembly versions stay truthful even when the branch name is aspirational.
This commit is contained in:
parent
f4d4c786b4
commit
6e50967702
1 changed files with 74 additions and 2 deletions
74
Makefile
74
Makefile
|
|
@ -48,5 +48,77 @@ docker-build:
|
||||||
docker-run:
|
docker-run:
|
||||||
docker run -d -p 5000:5000 --name yavsc yavsc
|
docker run -d -p 5000:5000 --name yavsc yavsc
|
||||||
|
|
||||||
|
# Crée une branche release/<V> depuis main, met à jour les
|
||||||
|
# `<Version>` des .csproj via dotnet-gitversion, et la
|
||||||
|
# pousse sur origin.
|
||||||
|
#
|
||||||
|
# Usage : make release V=1.0.7-rc1
|
||||||
|
#
|
||||||
|
# Pré-requis : être sur main, working tree clean. La cible
|
||||||
|
# vérifie les deux et refuse sinon — elle ne fait JAMAIS
|
||||||
|
# de checkout automatique, c'est à l'opérateur de s'être
|
||||||
|
# positionné sur la bonne branche au préalable (sinon le
|
||||||
|
# bump pourrait partir sur une branche tierce par accident).
|
||||||
|
#
|
||||||
|
# Notes :
|
||||||
|
# - Le nom de branche vient de l'argument V (ex: 1.0.7-rc1
|
||||||
|
# donne release/1.0.7-rc1). C'est une étiquette d'intention,
|
||||||
|
# pas la version assembly.
|
||||||
|
# - La version dans les .csproj vient de GitVersion qui la
|
||||||
|
# calcule depuis l'historique git (tag le plus proche +
|
||||||
|
# nombre de commits). C'est la version assembly réelle.
|
||||||
|
# - L'ordre (fetch → branche → bump → push) garantit qu'on
|
||||||
|
# part d'un main synchro et qu'on ne pollue pas main avec
|
||||||
|
# le bump (qui vit sur la branche release).
|
||||||
|
# - Fail-fast si la branche existe déjà en local ou sur origin.
|
||||||
|
release:
|
||||||
|
@if [ -z "$(V)" ]; then \
|
||||||
|
echo "Usage: make release V=<version>"; \
|
||||||
|
echo " V : version semver (ex. 1.0.7-rc1) — sert à nommer la branche."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@CURRENT=$$(git branch --show-current); \
|
||||||
|
if [ "$$CURRENT" != "main" ]; then \
|
||||||
|
echo "Refus : la cible doit être lancée depuis main."; \
|
||||||
|
echo " Branche courante : $$CURRENT"; \
|
||||||
|
echo " Fais : git checkout main && git pull --ff-only origin main"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@if [ -n "$$(git status --porcelain)" ]; then \
|
||||||
|
echo "Working tree sale, refus de créer une branche release."; \
|
||||||
|
git status --short; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@BRANCH="release/$(V)"; \
|
||||||
|
if git show-ref --verify --quiet "refs/heads/$$BRANCH"; then \
|
||||||
|
echo "La branche $$BRANCH existe déjà en local."; \
|
||||||
|
echo " Pour la supprimer : git branch -D $$BRANCH"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
if git ls-remote --exit-code --heads origin "$$BRANCH" >/dev/null 2>&1; then \
|
||||||
|
echo "La branche $$BRANCH existe déjà sur origin."; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
echo "==> Fetch + vérification synchro main"; \
|
||||||
|
git fetch origin main; \
|
||||||
|
if ! git merge-base --is-ancestor origin/main HEAD; then \
|
||||||
|
echo "main a avancé plus loin que HEAD. Fais :"; \
|
||||||
|
echo " git pull --ff-only origin main"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
echo "==> Création de $$BRANCH depuis main"; \
|
||||||
|
git checkout -b "$$BRANCH"; \
|
||||||
|
echo "==> dotnet-gitversion /updateprojectfiles"; \
|
||||||
|
dotnet-gitversion /updateprojectfiles; \
|
||||||
|
echo "==> Commit du bump"; \
|
||||||
|
git add .; \
|
||||||
|
if git diff --cached --quiet; then \
|
||||||
|
echo "Pas de changements à committer (gitversion n'a produit aucune diff)."; \
|
||||||
|
else \
|
||||||
|
git commit -m "chore(release): bump version via gitversion for $(V)"; \
|
||||||
|
fi; \
|
||||||
|
echo "==> Push de $$BRANCH sur origin"; \
|
||||||
|
git push -u origin "$$BRANCH"; \
|
||||||
|
echo "==> Terminé. Branche $$BRANCH live sur origin."
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test release
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue