Skip to content

Commit

Permalink
Tweak release process (#502)
Browse files Browse the repository at this point in the history
* Split release in two steps

* Document the new release process

* Whoops, this should not be here

* Whoops x2

* Check whether the branch already exists
  • Loading branch information
agarciamontoro authored Aug 5, 2022
1 parent 0ebd7e9 commit 760a02b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 25 deletions.
68 changes: 44 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,53 @@ test:
MATCH=v.+\/mattermost-load-test-ng-v.+-linux-amd64.tar.gz
REPLACE=$(NEXT_VER)\/mattermost-load-test-ng-$(NEXT_VER)-linux-amd64.tar.gz
TAG_EXISTS=$(shell git rev-parse $(NEXT_VER) >/dev/null 2>&1; echo $$?)
BRANCH_NAME=bump-$(NEXT_VER)
BRANCH_EXISTS=$(shell git rev-parse $(BRANCH_NAME) >/dev/null 2>&1; echo $$?)
PR_URL=https://github.com/mattermost/mattermost-load-test-ng/compare/master...$(BRANCH_NAME)?quick_pull=1&labels=2:+Dev+Review

prepare-release:
ifndef NEXT_VER
@echo "Error: NEXT_VER must be defined"
else
ifeq ($(TAG_EXISTS), 0)
@echo "Error: tag ${NEXT_VER} already exists"
else
ifeq ($(BRANCH_EXISTS), 0)
@echo "Error: branch ${BRANCH_NAME} already exists"
else
git checkout -b $(BRANCH_NAME) origin/master
@echo "Applying changes"
@for file in $(shell grep -rPl --include="*.go" --include="*.json" $(MATCH)); do \
sed -r -i 's/$(MATCH)/$(REPLACE)/g' $$file; \
done
git commit -a -m "Bump version to $(NEXT_VER)"
git push --set-upstream origin $(BRANCH_NAME)
git checkout master
@echo "Visit the following URL to create a PR: ${PR_URL}\nWhen merged, run make release."
endif
endif
endif

release:
@if [ -z "${NEXT_VER}" ]; then \
echo "Error: NEXT_VER must be defined"; \
exit 1; \
else \
if [ "${TAG_EXISTS}" -eq 0 ]; then \
echo "Error: tag ${NEXT_VER} already exists"; \
exit 1; \
ifndef NEXT_VER
@echo "Error: NEXT_VER must be defined"
else
ifeq ($(TAG_EXISTS), 0)
@echo "Error: tag ${NEXT_VER} already exists"
else
ifeq ($(command -v goreleaser),)
@echo -n "goreleaser is not installed, do you want to download it? [y/N] " && read ans && \
if [ $${ans:-N} = y ] || [ $${ans:-N} = Y ]; then \
curl -sfL https://goreleaser.com/static/run | bash; \
else \
if ! [ -x "$$(command -v goreleaser)" ]; then \
echo "goreleaser is not installed, do you want to download it? [y/N] " && read ans && [ $${ans:-N} = y ]; \
if [ $$ans = y ] || [ $$ans = Y ] ; then \
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh; \
else \
echo "aborting make release."; \
exit 1; \
fi; \
fi; \
for file in $(shell grep -rPl --include="*.go" --include="*.json" $(MATCH)); do \
sed -r -i 's/$(MATCH)/$(REPLACE)/g' $$file; \
done; \
git commit -a -m 'Releasing $(NEXT_VER)'; \
git tag $(NEXT_VER); \
goreleaser --rm-dist; \
fi; \
fi;\
echo "aborting make release."; \
exit 1; \
fi;
endif
git tag $(NEXT_VER)
goreleaser --rm-dist
endif
endif

clean:
rm -f errors.log cache.db stats.log status.log
Expand Down
21 changes: 20 additions & 1 deletion docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,27 @@ make package
### Releasing

We use a combination of `Makefile` and [Goreleser](https://goreleaser.com/) to automate our release process.
To build, package and publish a new release you can issue the following command:

The release process consists of two steps:
1. Prepare the release and get the automatically created PR merged.
2. Do the actual release.

#### Prepare the release

There are certain changes that we need to do for every release (for now, simply updating the default load-test URL in the config sample). You can automatically apply those changes with the following command:

```sh
make prepare-release NEXT_VER=v1.1.1
```

Follow the instructions in the output to create the PR. Once it's merged, continue with the next step.

#### Actual release

With the PR already merged, you can now finish the process with the following command:

```sh
make release NEXT_VER=v1.1.1
```

`goreleaser` needs to use a Github token to create the release for you. You can define it inline with the `GITHUB_TOKEN` variable or write it to the default `~/.config/goreleaser/github_token` file. Read [`goreleaser` docs](https://goreleaser.com/scm/github/) for more info.

0 comments on commit 760a02b

Please sign in to comment.