From 1b363922640adceac4edb20800b1b22f56755c12 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 11 Jan 2024 17:06:49 +0100 Subject: [PATCH] ci(release): automate release steps for the patch (#12273) --- .github/workflows/run-patch-release.yml | 31 +++++++++++++++++++++++++ release.mk | 24 ++++++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/workflows/run-patch-release.yml b/.github/workflows/run-patch-release.yml index ae289d06075..a40979f119b 100644 --- a/.github/workflows/run-patch-release.yml +++ b/.github/workflows/run-patch-release.yml @@ -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 }} @@ -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>. diff --git a/release.mk b/release.mk index aac084e8065..cd22c20ed80 100644 --- a/release.mk +++ b/release.mk @@ -7,6 +7,8 @@ export PATH := $(CURDIR)/bin:$(PATH) ####################### ## Tools ####################### +ARCH = $(shell uname -m) +OS = $(shell uname) ifeq ($(OS),Darwin) SED ?= sed -i ".bck" @@ -14,7 +16,6 @@ else SED ?= sed -i endif -ARCH = $(shell uname -m) ifeq ($(ARCH),x86_64) YQ_ARCH ?= amd64 else @@ -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) @@ -107,8 +109,8 @@ 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: @@ -116,9 +118,14 @@ minor-release: # .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 @@ -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' \