Skip to content

Commit 6c673b8

Browse files
authored
feat: new release process with PRs (#3567)
* 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]>
1 parent 3b22aad commit 6c673b8

14 files changed

+326
-180
lines changed

.ci/release/post-release.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# Bash strict mode
4+
set -euo pipefail
5+
6+
# Found current script directory
7+
RELATIVE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
8+
9+
# Found project directory
10+
BASE_PROJECT="$(dirname $(dirname "${RELATIVE_DIR}"))"
11+
12+
# Import dependencies
13+
source "${RELATIVE_DIR}/util.sh"
14+
15+
# Constants
16+
BASE_URL="https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent"
17+
CF_FILE="${BASE_PROJECT}/cloudfoundry/index.yml"
18+
19+
# Requirements
20+
check_version "${RELEASE_VERSION}"
21+
22+
echo "Set next snapshot version"
23+
./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnextSnapshot=true
24+
25+
# make script idempotent if release is already in CF descriptor
26+
set +e
27+
grep -e "^${RELEASE_VERSION}:" ${CF_FILE}
28+
[[ $? == 0 ]] && exit 0
29+
set -e
30+
echo "Update cloudfoundry version"
31+
echo "${RELEASE_VERSION}: ${BASE_URL}/${RELEASE_VERSION}/elastic-apm-agent-${RELEASE_VERSION}.jar" >> "${CF_FILE}"

.ci/release/pre-release.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Bash strict mode
4+
set -euo pipefail
5+
6+
# Found current script directory
7+
RELATIVE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
8+
9+
# Found project directory
10+
BASE_PROJECT="$(dirname $(dirname "${RELATIVE_DIR}"))"
11+
12+
# Import dependencies
13+
source "${RELATIVE_DIR}/util.sh"
14+
15+
# Requirements
16+
check_version "${RELEASE_VERSION}"
17+
18+
echo "Set release version"
19+
./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion="${RELEASE_VERSION}"
20+
21+
echo "Prepare changelog for release"
22+
java "${BASE_PROJECT}/.ci/ReleaseChangelog.java" CHANGELOG.asciidoc "${RELEASE_VERSION}"

.ci/release/update_major_branch.sh renamed to .ci/release/update-major-branch.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ git checkout --force ${checkout_options}
6262

6363
echo -e "\n--- move local branch ${major_branch} to match tag ${tag}"
6464
git reset --hard ${tag}
65+
66+
echo -e "\n--- create new branch with updates"
67+
git checkout -b "update-major-${v}"
68+
git push origin "update-major-${v}"
69+
70+
echo -e "\n--- create PR to update major branch"
71+
gh pr create --title="post release v${v}: update major branch" --base "${major_branch}" --head "update-major-${v}" -b "post release v${v}"

.ci/release/update_cloudfoundry.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.ci/release/util.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
check_version() {
44
v=${1:-}
55

6-
if [[ "${v}" == "" ]]; then
7-
echo "usage $0 <version>" # here $0 will be the calling script
8-
echo "where <version> in format '1.2.3'"
6+
if [ -z "${v}" ]; then
7+
>&2 echo "The environment variable 'RELEASE_VERSION' isn't defined"
98
exit 1
109
fi
11-
12-
if [[ ! "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
13-
echo "invalid version format '${v}'"
10+
if [[ ! "${v}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
11+
>&2 echo "The environment variable 'RELEASE_VERSION' should respect SemVer format"
1412
exit 1
1513
fi
1614
}

.ci/release/wait_maven_artifact_published.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ Every time there is a merge to main or any branches the whole workflow will comp
3535

3636
### Release process
3737

38-
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,
38+
To release a new version of apm-agent-java, you must use the two GitHub Workflows.
39+
Trigger the `Pre Release` workflow targeting the release version.
40+
After merging the PRs created by the first workflow, you can trigger the `Release` workflow targeting the release version.
41+
It runs then a Buildkite pipeline in charge of generating and publishing the artifacts,
3942
for further details please go to [the buildkite folder](../../.buildkite/README.md).
43+
Finally, merge the PRs created to bump version for the next iteration.
4044

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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
3+
name: Pre/Post Release
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
ref:
9+
description: 'Branch or tag ref to run the workflow on'
10+
type: string
11+
required: true
12+
default: "main"
13+
version:
14+
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
15+
type: string
16+
required: true
17+
phase:
18+
description: 'Pre or post release phase'
19+
type: string # valid values are 'pre' or 'post'
20+
required: true
21+
22+
env:
23+
RELEASE_VERSION: ${{ inputs.version }}
24+
RELEASE_VERSION_TAG: v${{ inputs.version }}
25+
BRANCH_NAME: ${{ inputs.phase }}-release-v${{ inputs.version }}
26+
27+
permissions:
28+
contents: read
29+
30+
jobs:
31+
validate-tag:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
- name: Validate release tag does not exist in repo
39+
uses: ./.github/workflows/validate-tag
40+
with:
41+
tag: ${{ env.RELEASE_VERSION_TAG }}
42+
43+
create-pr:
44+
name: "Bump versions and create PR"
45+
runs-on: ubuntu-latest
46+
needs:
47+
- validate-tag
48+
permissions:
49+
contents: write
50+
steps:
51+
- uses: elastic/apm-pipeline-library/.github/actions/github-token@current
52+
with:
53+
url: ${{ secrets.VAULT_ADDR }}
54+
roleId: ${{ secrets.VAULT_ROLE_ID }}
55+
secretId: ${{ secrets.VAULT_SECRET_ID }}
56+
57+
- uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
58+
with:
59+
username: ${{ env.GIT_USER }}
60+
email: ${{ env.GIT_EMAIL }}
61+
token: ${{ env.GITHUB_TOKEN }}
62+
63+
- uses: actions/checkout@v4
64+
with:
65+
ref: ${{ inputs.ref }}
66+
token: ${{ env.GITHUB_TOKEN }}
67+
68+
- name: Create the release tag (post phase)
69+
if: inputs.phase == 'post'
70+
run: |
71+
git tag "${{ env.RELEASE_VERSION_TAG }}"
72+
git push origin "${{ env.RELEASE_VERSION_TAG }}"
73+
74+
- name: Create a ${{ inputs.phase }} release branch
75+
run: git checkout -b ${{ env.BRANCH_NAME }}
76+
77+
- name: Perform pre release changes
78+
if: inputs.phase == 'pre'
79+
uses: ./.github/workflows/maven-goal-jdk
80+
with:
81+
command: ./.ci/release/pre-release.sh
82+
83+
- name: Perform post release changes
84+
if: inputs.phase == 'post'
85+
uses: ./.github/workflows/maven-goal
86+
with:
87+
command: ./.ci/release/post-release.sh
88+
89+
- name: Push the ${{ inputs.phase }} release branch
90+
run: |
91+
git add --all
92+
git commit -m "${{ inputs.phase }} release: elastic-apm-agent ${{ env.RELEASE_VERSION_TAG }}"
93+
git push origin ${{ env.BRANCH_NAME }}
94+
95+
- name: Create the ${{ inputs.phase }} release PR
96+
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 }}"
97+
env:
98+
GH_TOKEN: ${{ env.GITHUB_TOKEN }}

.github/workflows/pre-release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
3+
name: Pre release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
ref:
9+
description: 'Branch or tag ref to run the workflow on'
10+
required: true
11+
default: "main"
12+
version:
13+
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
14+
required: true
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}
21+
22+
jobs:
23+
pre-release:
24+
name: "Bump versions and create PR"
25+
uses: ./.github/workflows/pre-post-release.yml
26+
permissions:
27+
contents: write
28+
with:
29+
ref: ${{ inputs.ref }}
30+
version: ${{ inputs.version }}
31+
phase: 'pre'
32+
secrets: inherit

0 commit comments

Comments
 (0)