Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new release process with PRs #3567

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +26 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
set +e
grep -e "^${RELEASE_VERSION}:" ${CF_FILE}
[[ $? == 0 ]] && exit 0
set -e
grep -e "^${RELEASE_VERSION}:" ${CF_FILE} && exit 0 || true

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"
amannocci marked this conversation as resolved.
Show resolved Hide resolved
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.

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 }}
amannocci marked this conversation as resolved.
Show resolved Hide resolved
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
Loading