Skip to content

Commit

Permalink
feat: new release process with PRs
Browse files Browse the repository at this point in the history
Signed-off-by: Adrien Mannocci <[email protected]>
  • Loading branch information
amannocci committed Mar 20, 2024
1 parent 3b22aad commit 58d2f09
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 179 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
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.

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:
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 }}
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: 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: 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 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 }}"
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 58d2f09

Please sign in to comment.