Skip to content

Commit

Permalink
ci(release): automate release steps for the patch (#12273)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Jan 11, 2024
1 parent d6b7c92 commit 1b36392
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/run-patch-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,29 @@ jobs:
# 0 indicates all history for all branches and tags.
fetch-depth: 0

# Required to use a service account, otherwise PRs created by
# GitHub bot won't trigger any CI builds.
# See https://github.com/peter-evans/create-pull-request/issues/48#issuecomment-537478081
- name: Configure github token
uses: elastic/apm-pipeline-library/.github/actions/github-token@current
with:
url: ${{ secrets.VAULT_ADDR }}
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}

- name: Configure git user
uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
with:
username: ${{ env.GIT_USER }}
email: ${{ env.GIT_EMAIL }}
token: ${{ env.GITHUB_TOKEN }}

- run: make patch-release
env:
GH_TOKEN: ${{ env.GITHUB_TOKEN }}

- uses: elastic/apm-pipeline-library/.github/actions/slack-message@current
if: success()
with:
url: ${{ secrets.VAULT_ADDR }}
roleId: ${{ secrets.VAULT_ROLE_ID }}
Expand All @@ -61,3 +81,14 @@ jobs:
message: |-
Feature freeze for `${{ github.repository }}@${{ env.RELEASE_VERSION }}` is Today.
All the relevant PRs and issues have been created.
- uses: elastic/apm-pipeline-library/.github/actions/slack-message@current
if: failure()
with:
url: ${{ secrets.VAULT_ADDR }}
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
channel: ${{ env.SLACK_CHANNEL }}
threadTimestamp: ${{ needs.prepare.outputs.slack-thread || '' }}
message: |-
:fire: Something went wrong with the patch release. See <${{ env.JOB_URL }}|logs>.
24 changes: 16 additions & 8 deletions release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export PATH := $(CURDIR)/bin:$(PATH)
#######################
## Tools
#######################
ARCH = $(shell uname -m)
OS = $(shell uname)

ifeq ($(OS),Darwin)
SED ?= sed -i ".bck"
else
SED ?= sed -i
endif

ARCH = $(shell uname -m)
ifeq ($(ARCH),x86_64)
YQ_ARCH ?= amd64
else
Expand All @@ -38,6 +39,7 @@ PROJECT_PATCH_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f3 -d.)
PROJECT_OWNER ?= elastic
RELEASE_TYPE ?= minor

CURRENT_RELEASE ?= $(shell gh api repos/elastic/apm-server/releases/latest | jq -r '.tag_name|sub("v"; ""; "")')
RELEASE_BRANCH ?= $(PROJECT_MAJOR_VERSION).$(PROJECT_MINOR_VERSION)
NEXT_PROJECT_MINOR_VERSION ?= $(PROJECT_MAJOR_VERSION).$(shell expr $(PROJECT_MINOR_VERSION) + 1).0
NEXT_RELEASE ?= $(RELEASE_BRANCH).$(shell expr $(PROJECT_PATCH_VERSION) + 1)
Expand Down Expand Up @@ -107,18 +109,23 @@ minor-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"
$(MAKE) create-pull-request BRANCH=changelog-$(RELEASE_BRANCH) TARGET_BRANCH=$(RELEASE_BRANCH) TITLE="$(RELEASE_BRANCH): update docs"
$(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."
$(MAKE) create-pull-request BRANCH=changelog-$(RELEASE_BRANCH) TARGET_BRANCH=$(RELEASE_BRANCH) TITLE="$(RELEASE_BRANCH): update docs" BODY="Merge as soon as $(TARGET_BRANCH) branch is created and the GitHub checks are green."

# This is the contract with the GitHub action .github/workflows/run-patch-release.yml
# The GitHub action will provide the below environment variables:
# - RELEASE_VERSION
#
.PHONY: patch-release
patch-release:
@echo "VERSION: $${RELEASE_VERSION}"
@echo 'TODO: prepare-patch-release'
@echo 'TODO: create-prs-patch-release'
@echo "INFO: Create feature branch and update the versions. Target branch $(RELEASE_BRANCH)"
$(MAKE) create-branch NAME=update-$(NEXT_RELEASE) BASE=$(RELEASE_BRANCH)
$(MAKE) update-version VERSION=$(RELEASE_VERSION)
$(MAKE) update-version-makefile VERSION=$(PROJECT_MAJOR_VERSION)\.$(PROJECT_MINOR_VERSION)
$(MAKE) update-version-legacy VERSION=$(NEXT_RELEASE) PREVIOUS_VERSION=$(CURRENT_RELEASE)
$(MAKE) create-commit COMMIT_MESSAGE="docs: update docs versions to $(NEXT_RELEASE)"
@echo "INFO: Push changes to $(PROJECT_OWNER)/apm-server and create the relevant Pull Requests"
$(MAKE) create-pull-request BRANCH=update-$(NEXT_RELEASE) TARGET_BRANCH=$(RELEASE_BRANCH) TITLE="$(NEXT_RELEASE): update docs" BODY="Merge before the final Release build."

############################################
## Internal make goals to bump versions
Expand Down Expand Up @@ -261,13 +268,14 @@ create-commit:

## @help:create-pull-request:Create pull request
.PHONY: create-pull-request
create-pull-request: BRANCH=$${BRANCH} TITLE=$${TITLE} TARGET_BRANCH=$${TARGET_BRANCH}
create-pull-request: BRANCH=$${BRANCH} TITLE=$${TITLE} TARGET_BRANCH=$${TARGET_BRANCH} BODY=$${BODY}

create-pull-request:
@echo "::group::create-pull-request"
git push origin $(BRANCH)
gh pr create \
--title "$(TITLE)" \
--body "Merge as soon as $(TARGET_BRANCH) branch is created." \
--body "$(BODY)" \
--base $(TARGET_BRANCH) \
--head $(BRANCH) \
--label 'release' \
Expand Down

0 comments on commit 1b36392

Please sign in to comment.