From bd0e6f287b44b37dc4a7c984a308fae120f7d3fe Mon Sep 17 00:00:00 2001 From: Akis Maziotis Date: Thu, 6 Jun 2024 11:27:19 +0300 Subject: [PATCH] [feat] Implementing new release process (#200) Streamlining the release process for mattermost-plugins by integrating release and signing pipelines under the delivery platform. This update automates signing and releasing by simply pushing a semver tag(e.g: v0.0.1) or by using the newly introduced Makefile targets. ``` make patch make minor make major ``` For Release Candidades(RC): ``` make patch-rc make minor-rc make major-rc ``` Signed-off-by: Akis Maziotis --- .github/workflows/cd.yml | 18 -------- Makefile | 94 ++++++++++++++++++++++++++++++++++++++++ README.md | 40 +++++++++++++++++ 3 files changed, 134 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml deleted file mode 100644 index c929fd9..0000000 --- a/.github/workflows/cd.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: cd -on: - workflow_run: - workflows: ["ci"] - branches-ignore: ["*"] - types: - - completed - push: - tags: - - "v*" - -permissions: - contents: read - -jobs: - plugin-cd: - uses: mattermost/actions-workflows/.github/workflows/plugin-cd.yml@main - secrets: inherit diff --git a/Makefile b/Makefile index 18e745a..f22c81d 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,100 @@ else GO_BUILD_GCFLAGS = endif + +# ==================================================================================== +# Used for semver bumping +PROTECTED_BRANCH := master +APP_NAME := $(shell basename -s .git `git config --get remote.origin.url`) +CURRENT_VERSION := $(shell git describe --abbrev=0 --tags) +VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION)))) +MAJOR := $(word 1,$(VERSION_PARTS)) +MINOR := $(word 2,$(VERSION_PARTS)) +PATCH := $(word 3,$(VERSION_PARTS)) +RC := $(shell echo $(CURRENT_VERSION) | grep -oE 'rc[0-9]+' | sed 's/rc//') +# Check if current branch is protected +define check_protected_branch + @current_branch=$$(git rev-parse --abbrev-ref HEAD); \ + if ! echo "$(PROTECTED_BRANCH)" | grep -wq "$$current_branch"; then \ + echo "Error: Tagging is only allowed from $(PROTECTED_BRANCH) branch. You are on $$current_branch branch."; \ + exit 1; \ + fi +endef +# Check if there are pending pulls +define check_pending_pulls + @git fetch; \ + current_branch=$$(git rev-parse --abbrev-ref HEAD); \ + if [ "$$(git rev-parse HEAD)" != "$$(git rev-parse origin/$$current_branch)" ]; then \ + echo "Error: Your branch is not up to date with upstream. Please pull the latest changes before performing a release"; \ + exit 1; \ + fi +endef +# ==================================================================================== + +.PHONY: patch minor major patch-rc minor-rc major-rc + +patch: ## to bump patch version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + @$(eval PATCH := $(shell echo $$(($(PATCH)+1)))) + @echo Bumping $(APP_NAME) to Patch version $(MAJOR).$(MINOR).$(PATCH) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH) -m "Bumping $(APP_NAME) to Patch version $(MAJOR).$(MINOR).$(PATCH)" + git push origin v$(MAJOR).$(MINOR).$(PATCH) + @echo Bumped $(APP_NAME) to Patch version $(MAJOR).$(MINOR).$(PATCH) + +minor: ## to bump minor version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + @$(eval MINOR := $(shell echo $$(($(MINOR)+1)))) + @$(eval PATCH := 0) + @echo Bumping $(APP_NAME) to Minor version $(MAJOR).$(MINOR).$(PATCH) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH) -m "Bumping $(APP_NAME) to Minor version $(MAJOR).$(MINOR).$(PATCH)" + git push origin v$(MAJOR).$(MINOR).$(PATCH) + @echo Bumped $(APP_NAME) to Minor version $(MAJOR).$(MINOR).$(PATCH) + +major: ## to bump major version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + $(eval MAJOR := $(shell echo $$(($(MAJOR)+1)))) + $(eval MINOR := 0) + $(eval PATCH := 0) + @echo Bumping $(APP_NAME) to Major version $(MAJOR).$(MINOR).$(PATCH) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH) -m "Bumping $(APP_NAME) to Major version $(MAJOR).$(MINOR).$(PATCH)" + git push origin v$(MAJOR).$(MINOR).$(PATCH) + @echo Bumped $(APP_NAME) to Major version $(MAJOR).$(MINOR).$(PATCH) + +patch-rc: ## to bump patch release candidate version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + @$(eval RC := $(shell echo $$(($(RC)+1)))) + @echo Bumping $(APP_NAME) to Patch RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) -m "Bumping $(APP_NAME) to Patch RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC)" + git push origin v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + @echo Bumped $(APP_NAME) to Patch RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + +minor-rc: ## to bump minor release candidate version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + @$(eval MINOR := $(shell echo $$(($(MINOR)+1)))) + @$(eval PATCH := 0) + @$(eval RC := 1) + @echo Bumping $(APP_NAME) to Minor RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) -m "Bumping $(APP_NAME) to Minor RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC)" + git push origin v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + @echo Bumped $(APP_NAME) to Minor RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + +major-rc: ## to bump major release candidate version (semver) + $(call check_protected_branch) + $(call check_pending_pulls) + @$(eval MAJOR := $(shell echo $$(($(MAJOR)+1)))) + @$(eval MINOR := 0) + @$(eval PATCH := 0) + @$(eval RC := 1) + @echo Bumping $(APP_NAME) to Major RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + git tag -s -a v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) -m "Bumping $(APP_NAME) to Major RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC)" + git push origin v$(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + @echo Bumped $(APP_NAME) to Major RC version $(MAJOR).$(MINOR).$(PATCH)-rc$(RC) + ## Checks the code style, tests, builds and bundles the plugin. .PHONY: all all: check-style test dist diff --git a/README.md b/README.md index a1ac099..f83aada 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,46 @@ The version of a plugin is determined at compile time, automatically populating To disable this behaviour, manually populate and maintain the `version` field. +## How to Release + +To trigger a release, follow these steps: + +1. **For Patch Release:** Run the following command: + ``` + make patch + ``` + This will release a patch change. + +2. **For Minor Release:** Run the following command: + ``` + make minor + ``` + This will release a minor change. + +3. **For Major Release:** Run the following command: + ``` + make major + ``` + This will release a major change. + +4. **For Patch Release Candidate (RC):** Run the following command: + ``` + make patch-rc + ``` + This will release a patch release candidate. + +5. **For Minor Release Candidate (RC):** Run the following command: + ``` + make minor-rc + ``` + This will release a minor release candidate. + +6. **For Major Release Candidate (RC):** Run the following command: + ``` + make major-rc + ``` + This will release a major release candidate. + ## Q&A ### How do I make a server-only or web app-only plugin?