Skip to content

Commit 537cd36

Browse files
authored
feat: new release process (#226)
* feat: new release process Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * feat: use a global maven config file Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * chore: execute package goal for dry-run release Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * ci: align pr title creation for release Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * ci: add parameter documentations in CI scripts Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * ci: centralize maven goal execution Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * fix: use directly java-version without file Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * ci: refactor using a reusable workflow Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * refactor: avoid duplicate hardcode branch name Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * ci: create summary file in any case Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * feat: validate tag before anything Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * chore: apply suggestions Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * fix: validate correctly tags Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> * chore: add validation for tag and project version Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co> --------- Signed-off-by: Adrien Mannocci <adrien.mannocci@elastic.co>
1 parent e112d03 commit 537cd36

File tree

10 files changed

+242
-37
lines changed

10 files changed

+242
-37
lines changed

.ci/release.sh

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
## This script runs the release given the different environment variables
3-
## branch_specifier
4-
## dry_run
3+
## ref : git reference (commit,branch, tag, ...)
4+
## dry_run : dry-run when set to 'true'
55
##
66
## It relies on the .buildkite/hooks/pre-command so the Vault and other tooling
77
## are prepared automatically by buildkite.
@@ -19,7 +19,7 @@ clean_up () {
1919
trap clean_up EXIT
2020

2121
# Avoid detached HEAD since the release plugin requires to be on a branch
22-
git checkout -f "${branch_specifier}"
22+
git checkout -f "${ref}"
2323

2424
echo "--- Debug JDK installation :coffee:"
2525
echo $JAVA_HOME
@@ -28,9 +28,8 @@ java -version
2828

2929
set +x
3030
echo "--- Release the binaries to Maven Central :maven:"
31-
if [[ "$dry_run" == "true" ]] ; then
32-
echo './mvnw -V release:prepare release:perform --settings .ci/settings.xml --batch-mode'
31+
if [[ "${dry_run}" == "true" ]] ; then
32+
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee release.txt
3333
else
34-
# providing settings in arguments to make sure they are propagated to the forked maven release process
35-
./mvnw -V release:prepare release:perform --settings .ci/settings.xml -Darguments="--settings .ci/settings.xml" --batch-mode | tee release.txt
34+
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt
3635
fi

.ci/snapshot.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
## This script runs the snapshot given the different environment variables
3-
## dry_run
3+
## dry_run : dry-run when set to 'true'
44
##
55
## It relies on the .buildkite/hooks/pre-command so the Vault and other tooling
66
## are prepared automatically by buildkite.
@@ -26,7 +26,7 @@ java -version
2626
set +x
2727
echo "--- Deploy the snapshot :package:"
2828
if [[ "$dry_run" == "true" ]] ; then
29-
echo './mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode'
29+
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee snapshot.txt
3030
else
3131
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt
3232
fi
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
3+
name: maven-goal
4+
description: Install specific JDK and run a command
5+
6+
inputs:
7+
version:
8+
description: 'Java version'
9+
required: true
10+
default: '17'
11+
distribution:
12+
description: 'Java distribution'
13+
required: true
14+
default: 'temurin'
15+
command:
16+
description: 'Command to execute'
17+
required: true
18+
shell:
19+
description: 'Default shell'
20+
default: 'bash'
21+
required: false
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Set up JDK
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: ${{ inputs.version }}
30+
distribution: ${{ inputs.distribution }}
31+
cache: 'maven'
32+
- run: ${{ inputs.command }}
33+
shell: ${{ inputs.shell }}
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
name: Pre/Post Release
3+
4+
on:
5+
workflow_call:
6+
ref:
7+
description: 'Branch or tag ref to run the workflow on'
8+
required: true
9+
default: 'main'
10+
version:
11+
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
12+
required: true
13+
phase:
14+
description: 'Pre or post release phase'
15+
type: choice
16+
options:
17+
- pre
18+
- post
19+
required: true
20+
21+
env:
22+
RELEASE_VERSION: ${{ inputs.version }}
23+
BRANCH_NAME: ${{ inputs.phase }}-release-v${{ inputs.version }}
24+
25+
permissions:
26+
contents: read
27+
28+
concurrency:
29+
group: ${{ github.workflow }}
30+
31+
jobs:
32+
validate-tag:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
- name: Validate tag does not exist on current commit
40+
uses: ./.github/workflows/validate-tag
41+
with:
42+
tag: v${{ env.RELEASE_VERSION }}
43+
44+
create-pr:
45+
name: "Bump versions and create PR"
46+
runs-on: ubuntu-latest
47+
needs:
48+
- validate-tag
49+
permissions:
50+
contents: write
51+
steps:
52+
- uses: elastic/apm-pipeline-library/.github/actions/github-token@current
53+
with:
54+
url: ${{ secrets.VAULT_ADDR }}
55+
roleId: ${{ secrets.VAULT_ROLE_ID }}
56+
secretId: ${{ secrets.VAULT_SECRET_ID }}
57+
58+
- uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
59+
with:
60+
username: ${{ env.GIT_USER }}
61+
email: ${{ env.GIT_EMAIL }}
62+
token: ${{ env.GITHUB_TOKEN }}
63+
64+
- uses: actions/checkout@v4
65+
with:
66+
ref: ${{ inputs.ref }}
67+
token: ${{ env.GITHUB_TOKEN }}
68+
69+
- name: Create the release tag (post phase)
70+
if: inputs.phase == 'post'
71+
run: |
72+
git tag "v${{ env.RELEASE_VERSION }}"
73+
git push origin "v${{ env.RELEASE_VERSION }}"
74+
75+
- name: Create a ${{ inputs.phase }} release branch
76+
run: git checkout -b ${{ env.BRANCH_NAME }}
77+
78+
- name: Set release version (pre release)
79+
if: inputs.phase == 'pre'
80+
uses: ./.github/workflows/maven-goal
81+
with:
82+
command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }}
83+
84+
- name: Set next snapshot version (post release)
85+
if: inputs.phase == 'post'
86+
uses: ./.github/workflows/maven-goal
87+
with:
88+
command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -nextSnapshot=true
89+
90+
- name: Push the ${{ inputs.phase }} release branch
91+
run: |
92+
git add --all
93+
git commit -m "${{ inputs.phase }} release: ecs-logging-java v${{ env.RELEASE_VERSION }}"
94+
git push origin ${{ env.BRANCH_NAME }}
95+
96+
- name: Create the ${{ inputs.phase }} release PR
97+
run: gh pr create --title="${{ inputs.phase }} release v${{ env.RELEASE_VERSION }}" --base main --head ${{ env.BRANCH_NAME }} -b "${{ inputs.phase }} release v${{ env.RELEASE_VERSION }}"

.github/workflows/pre-release.yml

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

.github/workflows/release.yml

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
11
---
2-
name: release
3-
4-
permissions:
5-
contents: read
2+
name: Release
63

74
on:
85
workflow_dispatch:
96
inputs:
10-
branch_specifier:
11-
description: The branch to release ex. main or 0.6.
7+
ref:
8+
description: 'Branch or tag ref to run the workflow on'
129
required: true
1310
default: "main"
14-
type: string
15-
11+
version:
12+
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
13+
required: true
1614
dry_run:
1715
description: If set, run a dry-run release
1816
default: false
1917
type: boolean
2018

19+
permissions:
20+
contents: read
21+
2122
jobs:
23+
validate-tag:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
- name: Validate tag does not exist on current commit
31+
uses: ./.github/workflows/validate-tag
32+
with:
33+
tag: v${{ env.RELEASE_VERSION }}
34+
- name: Validate tag match current version
35+
run: |
36+
if [ "$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout)" != "${{ env.RELEASE_VERSION }}" ]; then
37+
echo "Tag should match pom.xml project.version"
38+
exit 1
39+
fi
40+
2241
release:
2342
name: Release
2443
runs-on: ubuntu-latest
25-
44+
needs:
45+
- validate-tag
2646
steps:
2747
- id: buildkite
2848
name: Run Release
@@ -32,10 +52,10 @@ jobs:
3252
vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
3353
vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
3454
pipeline: ecs-logging-java-release
35-
waitFor: false
55+
waitFor: true
3656
printBuildLogs: false
3757
buildEnvVars: |
38-
branch_specifier=${{ inputs.branch_specifier || 'main' }}
58+
ref=${{ inputs.ref }}
3959
dry_run=${{ inputs.dry_run || 'false' }}
4060
4161
- if: ${{ success() }}
@@ -58,3 +78,15 @@ jobs:
5878
message: |
5979
:ghost: [${{ github.repository }}] Release *${{ github.ref_name }}* didn't get triggered in Buildkite.
6080
Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>)
81+
82+
post-release:
83+
name: "Bump versions and create PR"
84+
needs:
85+
- release
86+
uses: ./.github/workflows/pre-post-release.yml
87+
if: inputs.dry_run == 'false'
88+
with:
89+
ref: ${{ inputs.ref }}
90+
version: ${{ inputs.version }}
91+
phase: 'post'
92+
secrets: inherit

.github/workflows/test.yml

+2-10
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ on:
1111
permissions:
1212
contents: read
1313

14-
env:
15-
MAVEN_CONFIG: "-V -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dhttps.protocols=TLSv1.2 -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=25"
16-
JAVA_VERSION: 17
17-
JAVA_DIST: adopt
18-
1914
jobs:
2015

2116
pre-commit:
@@ -36,12 +31,9 @@ jobs:
3631
fail-fast: false
3732
steps:
3833
- uses: actions/checkout@v3
39-
- uses: actions/setup-java@v3
34+
- uses: ./.github/workflows/maven-goal
4035
with:
41-
java-version: ${{ env.JAVA_VERSION }}
42-
distribution: ${{ env.JAVA_DIST }}
43-
cache: 'maven'
44-
- run: ./mvnw ${{ matrix.goal }}
36+
command: ./mvnw ${{ matrix.goal }}
4537
- name: Store test results
4638
if: ${{ matrix.goal == 'test' }} && (success() || failure())
4739
uses: actions/upload-artifact@v3
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
3+
name: validate-tag
4+
description: Validate tag format
5+
6+
inputs:
7+
tag:
8+
description: 'Tag to validate'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Validate tag does not exist on current commit
15+
id: validate-tag
16+
shell: 'bash'
17+
run: |
18+
if ! [ $(echo "${{ inputs.tag }}" | grep -P "(\d{1,2})\.(\d{1,2})\.(\d{1,2})") ]; then
19+
echo "Tag should be a SemVer format"
20+
exit 1
21+
fi
22+
if [ $(git tag -l "${{ inputs.tag }}") ]; then
23+
echo "The tag ${{ inputs.tag }} already exists"
24+
exit 1
25+
fi

.mvn/maven.config

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-B
2+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
3+
-Dhttps.protocols=TLSv1.2
4+
-Dmaven.wagon.http.retryHandler.count=3
5+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=25

pom.xml

+3-7
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,9 @@
122122
<build>
123123
<plugins>
124124
<plugin>
125-
<artifactId>maven-release-plugin</artifactId>
126-
<configuration>
127-
<useReleaseProfile>false</useReleaseProfile>
128-
<releaseProfiles>gpg</releaseProfiles>
129-
<autoVersionSubmodules>true</autoVersionSubmodules>
130-
<tagNameFormat>v@{project.version}</tagNameFormat>
131-
</configuration>
125+
<groupId>org.codehaus.mojo</groupId>
126+
<artifactId>versions-maven-plugin</artifactId>
127+
<version>2.16.2</version>
132128
</plugin>
133129
<plugin>
134130
<artifactId>maven-deploy-plugin</artifactId>

0 commit comments

Comments
 (0)