Skip to content

Commit

Permalink
feat: new release process with PRs (#3567)
Browse files Browse the repository at this point in the history
* feat: new release process with PRs

Signed-off-by: Adrien Mannocci <[email protected]>

* chore: redirect to stderr for both message

Signed-off-by: Adrien Mannocci <[email protected]>

* chore: apply suggest

Signed-off-by: Adrien Mannocci <[email protected]>

* ci(chore): use env var instead of prefix v

Signed-off-by: Adrien Mannocci <[email protected]>

* ci: use maven wrapper instead of direct maven

Signed-off-by: Adrien Mannocci <[email protected]>

* feat: validate snapshot for snapshot workflow

Signed-off-by: Adrien Mannocci <[email protected]>

* docs: add new release process

Signed-off-by: Adrien Mannocci <[email protected]>

---------

Signed-off-by: Adrien Mannocci <[email protected]>
  • Loading branch information
amannocci authored Mar 25, 2024
1 parent 3b22aad commit 6c673b8
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 180 deletions.
31 changes: 31 additions & 0 deletions .ci/release/post-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Bash strict mode
set -euo pipefail

# Found current script directory
RELATIVE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Found project directory
BASE_PROJECT="$(dirname $(dirname "${RELATIVE_DIR}"))"

# Import dependencies
source "${RELATIVE_DIR}/util.sh"

# Constants
BASE_URL="https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent"
CF_FILE="${BASE_PROJECT}/cloudfoundry/index.yml"

# Requirements
check_version "${RELEASE_VERSION}"

echo "Set next snapshot version"
./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnextSnapshot=true

# make script idempotent if release is already in CF descriptor
set +e
grep -e "^${RELEASE_VERSION}:" ${CF_FILE}
[[ $? == 0 ]] && exit 0
set -e
echo "Update cloudfoundry version"
echo "${RELEASE_VERSION}: ${BASE_URL}/${RELEASE_VERSION}/elastic-apm-agent-${RELEASE_VERSION}.jar" >> "${CF_FILE}"
22 changes: 22 additions & 0 deletions .ci/release/pre-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# Bash strict mode
set -euo pipefail

# Found current script directory
RELATIVE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Found project directory
BASE_PROJECT="$(dirname $(dirname "${RELATIVE_DIR}"))"

# Import dependencies
source "${RELATIVE_DIR}/util.sh"

# Requirements
check_version "${RELEASE_VERSION}"

echo "Set release version"
./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion="${RELEASE_VERSION}"

echo "Prepare changelog for release"
java "${BASE_PROJECT}/.ci/ReleaseChangelog.java" CHANGELOG.asciidoc "${RELEASE_VERSION}"
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ git checkout --force ${checkout_options}

echo -e "\n--- move local branch ${major_branch} to match tag ${tag}"
git reset --hard ${tag}

echo -e "\n--- create new branch with updates"
git checkout -b "update-major-${v}"
git push origin "update-major-${v}"

echo -e "\n--- create PR to update major branch"
gh pr create --title="post release v${v}: update major branch" --base "${major_branch}" --head "update-major-${v}" -b "post release v${v}"
28 changes: 0 additions & 28 deletions .ci/release/update_cloudfoundry.sh

This file was deleted.

10 changes: 4 additions & 6 deletions .ci/release/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
check_version() {
v=${1:-}

if [[ "${v}" == "" ]]; then
echo "usage $0 <version>" # here $0 will be the calling script
echo "where <version> in format '1.2.3'"
if [ -z "${v}" ]; then
>&2 echo "The environment variable 'RELEASE_VERSION' isn't defined"
exit 1
fi

if [[ ! "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "invalid version format '${v}'"
if [[ ! "${v}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
>&2 echo "The environment variable 'RELEASE_VERSION' should respect SemVer format"
exit 1
fi
}
Expand Down
13 changes: 0 additions & 13 deletions .ci/release/wait_maven_artifact_published.sh

This file was deleted.

6 changes: 5 additions & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ Every time there is a merge to main or any branches the whole workflow will comp

### Release process

This process has been fully automated and it gets triggered manually when running the [release](https://github.com/elastic/apm-agent-java/actions/workflows/release.yml) workflow. It runs then a Buildkite pipeline in charge of generating and publishing the artifacts,
To release a new version of apm-agent-java, you must use the two GitHub Workflows.
Trigger the `Pre Release` workflow targeting the release version.
After merging the PRs created by the first workflow, you can trigger the `Release` workflow targeting the release version.
It runs then a Buildkite pipeline in charge of generating and publishing the artifacts,
for further details please go to [the buildkite folder](../../.buildkite/README.md).
Finally, merge the PRs created to bump version for the next iteration.

The tag release follows the naming convention: `v.<major>.<minor>.<patch>`, where `<major>`, `<minor>` and `<patch>`.

Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/pre-post-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---

name: Pre/Post Release

on:
workflow_call:
inputs:
ref:
description: 'Branch or tag ref to run the workflow on'
type: string
required: true
default: "main"
version:
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
type: string
required: true
phase:
description: 'Pre or post release phase'
type: string # valid values are 'pre' or 'post'
required: true

env:
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_VERSION_TAG: v${{ inputs.version }}
BRANCH_NAME: ${{ inputs.phase }}-release-v${{ inputs.version }}

permissions:
contents: read

jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate release tag does not exist in repo
uses: ./.github/workflows/validate-tag
with:
tag: ${{ env.RELEASE_VERSION_TAG }}

create-pr:
name: "Bump versions and create PR"
runs-on: ubuntu-latest
needs:
- validate-tag
permissions:
contents: write
steps:
- 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 }}

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

- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
token: ${{ env.GITHUB_TOKEN }}

- name: Create the release tag (post phase)
if: inputs.phase == 'post'
run: |
git tag "${{ env.RELEASE_VERSION_TAG }}"
git push origin "${{ env.RELEASE_VERSION_TAG }}"
- name: Create a ${{ inputs.phase }} release branch
run: git checkout -b ${{ env.BRANCH_NAME }}

- name: Perform pre release changes
if: inputs.phase == 'pre'
uses: ./.github/workflows/maven-goal-jdk
with:
command: ./.ci/release/pre-release.sh

- name: Perform post release changes
if: inputs.phase == 'post'
uses: ./.github/workflows/maven-goal
with:
command: ./.ci/release/post-release.sh

- name: Push the ${{ inputs.phase }} release branch
run: |
git add --all
git commit -m "${{ inputs.phase }} release: elastic-apm-agent ${{ env.RELEASE_VERSION_TAG }}"
git push origin ${{ env.BRANCH_NAME }}
- name: Create the ${{ inputs.phase }} release PR
run: gh pr create --title="${{ inputs.phase }} release ${{ env.RELEASE_VERSION_TAG }}" --base main --head ${{ env.BRANCH_NAME }} -b "${{ inputs.phase }} release ${{ env.RELEASE_VERSION_TAG }}"
env:
GH_TOKEN: ${{ env.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

name: Pre release

on:
workflow_dispatch:
inputs:
ref:
description: 'Branch or tag ref to run the workflow on'
required: true
default: "main"
version:
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
required: true

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}

jobs:
pre-release:
name: "Bump versions and create PR"
uses: ./.github/workflows/pre-post-release.yml
permissions:
contents: write
with:
ref: ${{ inputs.ref }}
version: ${{ inputs.version }}
phase: 'pre'
secrets: inherit
Loading

0 comments on commit 6c673b8

Please sign in to comment.