Skip to content

Commit

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

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

* feat: use a global maven config file

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

* chore: execute package goal for dry-run release

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

* ci: align pr title creation for release

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

* ci: add parameter documentations in CI scripts

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

* ci: centralize maven goal execution

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

* fix: use directly java-version without file

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

* ci: refactor using a reusable workflow

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

* refactor: avoid duplicate hardcode branch name

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

* ci: create summary file in any case

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

* feat: validate tag before anything

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

* chore: apply suggestions

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

* fix: validate correctly tags

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

* chore: add validation for tag and project version

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

---------

Signed-off-by: Adrien Mannocci <[email protected]>
  • Loading branch information
amannocci authored Feb 2, 2024
1 parent e112d03 commit 537cd36
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 37 deletions.
13 changes: 6 additions & 7 deletions .ci/release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
## This script runs the release given the different environment variables
## branch_specifier
## dry_run
## ref : git reference (commit,branch, tag, ...)
## dry_run : dry-run when set to 'true'
##
## It relies on the .buildkite/hooks/pre-command so the Vault and other tooling
## are prepared automatically by buildkite.
Expand All @@ -19,7 +19,7 @@ clean_up () {
trap clean_up EXIT

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

echo "--- Debug JDK installation :coffee:"
echo $JAVA_HOME
Expand All @@ -28,9 +28,8 @@ java -version

set +x
echo "--- Release the binaries to Maven Central :maven:"
if [[ "$dry_run" == "true" ]] ; then
echo './mvnw -V release:prepare release:perform --settings .ci/settings.xml --batch-mode'
if [[ "${dry_run}" == "true" ]] ; then
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee release.txt
else
# providing settings in arguments to make sure they are propagated to the forked maven release process
./mvnw -V release:prepare release:perform --settings .ci/settings.xml -Darguments="--settings .ci/settings.xml" --batch-mode | tee release.txt
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt
fi
4 changes: 2 additions & 2 deletions .ci/snapshot.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
## This script runs the snapshot given the different environment variables
## dry_run
## dry_run : dry-run when set to 'true'
##
## It relies on the .buildkite/hooks/pre-command so the Vault and other tooling
## are prepared automatically by buildkite.
Expand All @@ -26,7 +26,7 @@ java -version
set +x
echo "--- Deploy the snapshot :package:"
if [[ "$dry_run" == "true" ]] ; then
echo './mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode'
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee snapshot.txt
else
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt
fi
33 changes: 33 additions & 0 deletions .github/workflows/maven-goal/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---

name: maven-goal
description: Install specific JDK and run a command

inputs:
version:
description: 'Java version'
required: true
default: '17'
distribution:
description: 'Java distribution'
required: true
default: 'temurin'
command:
description: 'Command to execute'
required: true
shell:
description: 'Default shell'
default: 'bash'
required: false

runs:
using: "composite"
steps:
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.version }}
distribution: ${{ inputs.distribution }}
cache: 'maven'
- run: ${{ inputs.command }}
shell: ${{ inputs.shell }}
97 changes: 97 additions & 0 deletions .github/workflows/pre-post-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
name: Pre/Post Release

on:
workflow_call:
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
phase:
description: 'Pre or post release phase'
type: choice
options:
- pre
- post
required: true

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

permissions:
contents: read

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

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

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 "v${{ env.RELEASE_VERSION }}"
git push origin "v${{ env.RELEASE_VERSION }}"
- name: Create a ${{ inputs.phase }} release branch
run: git checkout -b ${{ env.BRANCH_NAME }}

- name: Set release version (pre release)
if: inputs.phase == 'pre'
uses: ./.github/workflows/maven-goal
with:
command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }}

- name: Set next snapshot version (post release)
if: inputs.phase == 'post'
uses: ./.github/workflows/maven-goal
with:
command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -nextSnapshot=true

- name: Push the ${{ inputs.phase }} release branch
run: |
git add --all
git commit -m "${{ inputs.phase }} release: ecs-logging-java v${{ env.RELEASE_VERSION }}"
git push origin ${{ env.BRANCH_NAME }}
- name: Create the ${{ inputs.phase }} release PR
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 }}"
26 changes: 26 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
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

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

jobs:
pre-release:
name: "Bump versions and create PR"
uses: ./.github/workflows/pre-post-release.yml
with:
ref: ${{ inputs.ref }}
version: ${{ inputs.version }}
phase: 'pre'
secrets: inherit
54 changes: 43 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
---
name: release

permissions:
contents: read
name: Release

on:
workflow_dispatch:
inputs:
branch_specifier:
description: The branch to release ex. main or 0.6.
ref:
description: 'Branch or tag ref to run the workflow on'
required: true
default: "main"
type: string

version:
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
required: true
dry_run:
description: If set, run a dry-run release
default: false
type: boolean

permissions:
contents: read

jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate tag does not exist on current commit
uses: ./.github/workflows/validate-tag
with:
tag: v${{ env.RELEASE_VERSION }}
- name: Validate tag match current version
run: |
if [ "$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout)" != "${{ env.RELEASE_VERSION }}" ]; then
echo "Tag should match pom.xml project.version"
exit 1
fi
release:
name: Release
runs-on: ubuntu-latest

needs:
- validate-tag
steps:
- id: buildkite
name: Run Release
Expand All @@ -32,10 +52,10 @@ jobs:
vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
pipeline: ecs-logging-java-release
waitFor: false
waitFor: true
printBuildLogs: false
buildEnvVars: |
branch_specifier=${{ inputs.branch_specifier || 'main' }}
ref=${{ inputs.ref }}
dry_run=${{ inputs.dry_run || 'false' }}
- if: ${{ success() }}
Expand All @@ -58,3 +78,15 @@ jobs:
message: |
:ghost: [${{ github.repository }}] Release *${{ github.ref_name }}* didn't get triggered in Buildkite.
Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>)
post-release:
name: "Bump versions and create PR"
needs:
- release
uses: ./.github/workflows/pre-post-release.yml
if: inputs.dry_run == 'false'
with:
ref: ${{ inputs.ref }}
version: ${{ inputs.version }}
phase: 'post'
secrets: inherit
12 changes: 2 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ on:
permissions:
contents: read

env:
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"
JAVA_VERSION: 17
JAVA_DIST: adopt

jobs:

pre-commit:
Expand All @@ -36,12 +31,9 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: ./.github/workflows/maven-goal
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DIST }}
cache: 'maven'
- run: ./mvnw ${{ matrix.goal }}
command: ./mvnw ${{ matrix.goal }}
- name: Store test results
if: ${{ matrix.goal == 'test' }} && (success() || failure())
uses: actions/upload-artifact@v3
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/validate-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

name: validate-tag
description: Validate tag format

inputs:
tag:
description: 'Tag to validate'
required: true

runs:
using: "composite"
steps:
- name: Validate tag does not exist on current commit
id: validate-tag
shell: 'bash'
run: |
if ! [ $(echo "${{ inputs.tag }}" | grep -P "(\d{1,2})\.(\d{1,2})\.(\d{1,2})") ]; then
echo "Tag should be a SemVer format"
exit 1
fi
if [ $(git tag -l "${{ inputs.tag }}") ]; then
echo "The tag ${{ inputs.tag }} already exists"
exit 1
fi
5 changes: 5 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-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
10 changes: 3 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,9 @@
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>gpg</releaseProfiles>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.16.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down

0 comments on commit 537cd36

Please sign in to comment.