Skip to content
24 changes: 0 additions & 24 deletions .github/workflows/prepare-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,6 @@ runs:
echo "::error::${FAILURE_MESSAGE}" ; exit 1
shell: 'bash'

- name: validate if branch already exists (major only)
if: ${{ inputs.type == 'major' }}
run: |-
if git ls-remote --exit-code --heads "https://github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" > /dev/null ; then
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
echo "::error::${FAILURE_MESSAGE}" ; exit 1
fi
shell: 'bash'
env:
BRANCH: ${{ steps.generate.outputs.release-branch }}
FAILURE_MESSAGE: Branch already exists. This is not a major release.

- name: validate if branch already exists (minor only)
if: ${{ inputs.type == 'minor' }}
run: |-
if git ls-remote --exit-code --heads https://github.com/${{ github.repository }}.git "$BRANCH" > /dev/null ; then
FAILURE_MESSAGE='Branch already exists. This is not a minor release.'
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
echo "::error::${FAILURE_MESSAGE}" ; exit 1
fi
shell: 'bash'
env:
BRANCH: ${{ steps.generate.outputs.release-branch }}

- name: validate if tag already exists
run: |-
if git ls-remote --exit-code https://github.com/${{ github.repository }}.git "$TAG" > /dev/null ; then
Expand Down
49 changes: 31 additions & 18 deletions release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ PROJECT_MINOR_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f2 -d.)
PROJECT_PATCH_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f3 -d.)
PROJECT_OWNER ?= elastic
RELEASE_TYPE ?= minor
FORCE_PR_CREATION ?=

# if gh is installed only
ifneq ($(shell command -v gh 2>/dev/null),)
Expand Down Expand Up @@ -74,21 +75,18 @@ endif
minor-release:
@echo "INFO: Create GitHub label backport for the version $(RELEASE_VERSION)"
$(MAKE) create-github-label NAME=backport-$(RELEASE_BRANCH)

@echo "INFO: Create release branch and update new version $(RELEASE_VERSION)"
$(MAKE) create-branch NAME=$(RELEASE_BRANCH) BASE=$(BASE_BRANCH)
$(MAKE) update-version VERSION=$(RELEASE_VERSION)
$(MAKE) update-version-makefile VERSION=$(PROJECT_MAJOR_VERSION)\.$(PROJECT_MINOR_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update version $(RELEASE_VERSION)"

@echo "INFO: Create feature branch and update the versions. Target branch $(BASE_BRANCH)"
$(MAKE) create-branch NAME=update-$(RELEASE_VERSION) BASE=$(BASE_BRANCH)
$(MAKE) update-mergify VERSION=$(RELEASE_BRANCH)
$(MAKE) update-version VERSION=$(NEXT_PROJECT_MINOR_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update version $(NEXT_PROJECT_MINOR_VERSION)"
$(MAKE) update-changelog VERSION=$(RELEASE_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update changelogs for $(RELEASE_BRANCH) release"

@echo "INFO: Push changes to $(PROJECT_OWNER)/apm-server and create the relevant Pull Requests"
git push origin $(RELEASE_BRANCH)
$(MAKE) create-pull-request BRANCH=update-$(RELEASE_VERSION) TARGET_BRANCH=$(BASE_BRANCH) TITLE="$(RELEASE_BRANCH): update docs, mergify, versions and changelogs" BODY="Merge as soon as the GitHub checks are green."
Expand Down Expand Up @@ -170,14 +168,21 @@ update-version-makefile:
############################################

## Create a new branch
## It will delete the branch if it already exists before the creation.
## If the branch already exists on the remote, fetch and check it out instead.
## Otherwise, delete the local branch if it exists and recreate it from BASE.
.PHONY: create-branch
create-branch: NAME=$${NAME} BASE=$${BASE}
create-branch:
@echo "::group::create-branch $(NAME)"
git checkout $(BASE)
git branch -D $(NAME) &>/dev/null || true
git checkout $(BASE) -b $(NAME)
@if git ls-remote --exit-code --heads origin "$(NAME)" > /dev/null 2>&1; then \
echo "WARNING: Branch $(NAME) already exists. Fetching and checking out." ; \
git fetch origin $(NAME):$(NAME) ; \
git checkout $(NAME) ; \
else \
git branch -D $(NAME) &>/dev/null || true ; \
git checkout $(BASE) ; \
git checkout $(BASE) -b $(NAME) ; \
fi
@echo "::endgroup::"

## Create a new commit only if there is a diff.
Expand Down Expand Up @@ -211,17 +216,25 @@ create-pull-request: BRANCH=$${BRANCH} TITLE=$${TITLE} TARGET_BRANCH=$${TARGET_B

create-pull-request:
@echo "::group::create-pull-request $(BRANCH) -> $(TARGET_BRANCH)"
git push origin $(BRANCH)
echo "--label $(BACKPORT_LABEL)"
gh pr create \
--title "$(TITLE)" \
--body "$(BODY)" \
--base $(TARGET_BRANCH) \
--head $(BRANCH) \
--label 'release' \
--label "$(BACKPORT_LABEL)" \
--reviewer "$(PROJECT_REVIEWERS)" \
--repo $(PROJECT_OWNER)/apm-server || echo "There is no changes"
@PR_COUNT=0 ; \
if [ "$(FORCE_PR_CREATION)" != "true" ]; then \
PR_COUNT=$$(gh pr list --head "$(BRANCH)" --base "$(TARGET_BRANCH)" --label release --state all --json number,headRefName --jq '[.[] | select(.headRefName == "$(BRANCH)")] | length' --repo $(PROJECT_OWNER)/apm-server) ; \
fi ; \
if [ "$$PR_COUNT" -gt 0 ]; then \
echo "PR for $(BRANCH) -> $(TARGET_BRANCH) already exists, skipping." ; \
else \
echo "--label $(BACKPORT_LABEL)" ; \
git push origin $(BRANCH) ; \
gh pr create \
--title "$(TITLE)" \
--body "$(BODY)" \
--base $(TARGET_BRANCH) \
--head $(BRANCH) \
--label 'release' \
--label "$(BACKPORT_LABEL)" \
--reviewer "$(PROJECT_REVIEWERS)" \
--repo $(PROJECT_OWNER)/apm-server || echo "There is no changes" ; \
fi
@echo "::endgroup::"

## Diff output
Expand Down
Loading