diff --git a/.ci/release.sh b/.ci/release.sh index c6f0666..469c6a0 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash ## This script runs the release given the different environment variables -## branch_specifier +## ref ## dry_run ## ## It relies on the .buildkite/hooks/pre-command so the Vault and other tooling @@ -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 @@ -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 + echo './mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode' 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 diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..1b0d351 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,70 @@ +--- +name: Prepare 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 + +env: + JAVA_VERSION: 17 + JAVA_DIST: temurin + RELEASE_VERSION: ${{ inputs.version }} + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }} + +jobs: + create_pr: + name: "Bump versions and create PR" + runs-on: ubuntu-latest + 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 || 'main' }} + token: ${{ env.GITHUB_TOKEN }} + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v3 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DIST }} + cache: 'maven' + + - name: Create a prepare release branch + run: git checkout -b prepare-release-v${{ env.RELEASE_VERSION }} + + - name: Bump versions + run: | + ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }} + git add --all + git commit -m "release: ecs-logging-java v${{ env.RELEASE_VERSION }}" + + - name: Push the prepare release branch + run: git push origin prepare-release-v${{ env.RELEASE_VERSION }} + + - name: Create the prepare release PR + run: gh pr create --title="Prepare Release Version v${{ env.RELEASE_VERSION }}" --base main --head prepare-release-v${{ env.RELEASE_VERSION }} -b "New Release v${{ env.RELEASE_VERSION }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc2e8dc..11ac65b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ --- -name: release +name: Release permissions: contents: read @@ -7,22 +7,27 @@ permissions: 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 +env: + JAVA_VERSION: 17 + JAVA_DIST: temurin + RELEASE_VERSION: ${{ inputs.version }} + jobs: release: name: Release runs-on: ubuntu-latest - steps: - id: buildkite name: Run Release @@ -32,10 +37,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 || 'main' }} dry_run=${{ inputs.dry_run || 'false' }} - if: ${{ success() }} @@ -58,3 +63,56 @@ 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" + runs-on: ubuntu-latest + needs: + - release + 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 || 'main' }} + token: ${{ env.GITHUB_TOKEN }} + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v3 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DIST }} + cache: 'maven' + + - name: Create the release tag + run: | + git tag "v${{ env.RELEASE_VERSION }}" + git push origin "v${{ env.RELEASE_VERSION }}" + + - name: Create a post release branch + run: | + git checkout -b "post-release-v${{ env.RELEASE_VERSION }}" + + - name: Bump versions + run: | + ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -nextSnapshot=true + git add --all + git commit -m "chore: prepare for next iteration" + + - name: Push the post release branch + run: git push origin "post-release-v${{ env.RELEASE_VERSION }}" + + - name: Create the post release PR + run: gh pr create --title="Post release process" --base main --head "post-release-v${{ env.RELEASE_VERSION }}" -b "Prepare for next iteration" diff --git a/pom.xml b/pom.xml index a0b7e8f..5572b4f 100644 --- a/pom.xml +++ b/pom.xml @@ -122,13 +122,9 @@ - maven-release-plugin - - false - gpg - true - v@{project.version} - + org.codehaus.mojo + versions-maven-plugin + 2.16.2 maven-deploy-plugin