From 33fd62eda153e7f25671ffe86288d9d1b5d3930e Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Mon, 29 Jan 2024 18:08:45 +0100 Subject: [PATCH 01/14] feat: new release process Signed-off-by: Adrien Mannocci --- .ci/release.sh | 11 ++-- .github/workflows/prepare-release.yml | 70 +++++++++++++++++++++++++ .github/workflows/release.yml | 74 ++++++++++++++++++++++++--- pom.xml | 10 ++-- 4 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/prepare-release.yml 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 From 1a83544c3ae6d381292790bf5b69dc34585b8ac7 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:04:28 +0100 Subject: [PATCH 02/14] feat: use a global maven config file Signed-off-by: Adrien Mannocci --- .github/workflows/maven-goal/action.yml | 45 +++++++++++++++++++++++++ .github/workflows/test.yml | 1 - .mvn/maven.config | 6 ++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/maven-goal/action.yml create mode 100644 .mvn/maven.config diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml new file mode 100644 index 0000000..a2ddbea --- /dev/null +++ b/.github/workflows/maven-goal/action.yml @@ -0,0 +1,45 @@ +--- + +name: common build tasks +description: Install specific JDK and run a command + +inputs: + test-java-version: + description: 'Testing Java version' + required: true + default: '17' + test-java-distribution: + description: 'Testing 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 testing JDK + if: ${{ inputs.test-java-version != '17' }} + uses: actions/setup-java@v4 + with: + java-version: ${{ inputs.test-java-version}} + distribution: ${{ inputs.test-java-distribution}} + - name: Set up build JDK + uses: actions/setup-java@v4 + with: + java-version: 17 # NOTE: This version is also defined in .buildkite/hooks/pre-command + distribution: temurin + cache: 'maven' + - name: Set up TEST_JAVA_BINARY environment variable + shell: bash + run: | + major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')" + java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }} + echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV + - run: ${{ inputs.command }} + shell: ${{ inputs.shell }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b26750..83cffbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,6 @@ 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 diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 0000000..f20e925 --- /dev/null +++ b/.mvn/maven.config @@ -0,0 +1,6 @@ +-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 \ No newline at end of file From 318fdc4ce4f5b455495f08532414a69ccad639d0 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:05:36 +0100 Subject: [PATCH 03/14] chore: execute package goal for dry-run release Signed-off-by: Adrien Mannocci --- .ci/release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/release.sh b/.ci/release.sh index 469c6a0..e74ea68 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -29,7 +29,7 @@ java -version set +x echo "--- Release the binaries to Maven Central :maven:" 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 else ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt fi From ae99e9780a0e9cae0b7c9fcd8ef67bfb5c2acbb6 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:08:00 +0100 Subject: [PATCH 04/14] ci: align pr title creation for release Signed-off-by: Adrien Mannocci --- .github/workflows/prepare-release.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 1b0d351..a4b007d 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -67,4 +67,4 @@ jobs: 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 }}" + run: gh pr create --title="Prepare Release 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 11ac65b..378dbd3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -115,4 +115,4 @@ jobs: 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" + run: gh pr create --title="Post Release v${{ env.RELEASE_VERSION }}" --base main --head "post-release-v${{ env.RELEASE_VERSION }}" -b "Prepare for next iteration" From bef4e60dec3b2fd84484b66f77c4baa77c0da66b Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:10:59 +0100 Subject: [PATCH 05/14] ci: add parameter documentations in CI scripts Signed-off-by: Adrien Mannocci --- .ci/release.sh | 4 ++-- .ci/snapshot.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.ci/release.sh b/.ci/release.sh index e74ea68..7cfa50c 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## This script runs the release given the different environment variables -## ref -## 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. diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index cbd2758..ae3cbfd 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -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. @@ -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 else ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt fi From aab1f0a927f5b9eb31c2c2924e831456bfe098d5 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:23:29 +0100 Subject: [PATCH 06/14] ci: centralize maven goal execution Signed-off-by: Adrien Mannocci --- .github/workflows/maven-goal/action.yml | 28 ++++++------------------- .github/workflows/prepare-release.yml | 19 ++++++----------- .github/workflows/release.yml | 19 ++++++----------- .github/workflows/test.yml | 11 ++-------- .java-version | 1 + 5 files changed, 21 insertions(+), 57 deletions(-) create mode 100644 .java-version diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml index a2ddbea..b5573e6 100644 --- a/.github/workflows/maven-goal/action.yml +++ b/.github/workflows/maven-goal/action.yml @@ -1,15 +1,11 @@ --- -name: common build tasks +name: maven-goal description: Install specific JDK and run a command inputs: - test-java-version: - description: 'Testing Java version' - required: true - default: '17' - test-java-distribution: - description: 'Testing Java distribution' + distribution: + description: 'Java distribution' required: true default: 'temurin' command: @@ -23,23 +19,11 @@ inputs: runs: using: "composite" steps: - - name: Set up testing JDK - if: ${{ inputs.test-java-version != '17' }} - uses: actions/setup-java@v4 - with: - java-version: ${{ inputs.test-java-version}} - distribution: ${{ inputs.test-java-distribution}} - - name: Set up build JDK + - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: 17 # NOTE: This version is also defined in .buildkite/hooks/pre-command - distribution: temurin + java-version: .java-version + distribution: ${{ inputs.distribution }} cache: 'maven' - - name: Set up TEST_JAVA_BINARY environment variable - shell: bash - run: | - major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')" - java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }} - echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV - run: ${{ inputs.command }} shell: ${{ inputs.shell }} diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index a4b007d..cd8e96f 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -13,8 +13,6 @@ on: required: true env: - JAVA_VERSION: 17 - JAVA_DIST: temurin RELEASE_VERSION: ${{ inputs.version }} permissions: @@ -47,24 +45,19 @@ jobs: 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 + uses: ./.github/workflows/maven-goal + with: + command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }} + + - name: Push the prepare release branch 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 }} + git push origin prepare-release-v${{ env.RELEASE_VERSION }} - name: Create the prepare release PR run: gh pr create --title="Prepare Release 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 378dbd3..c3753e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,8 +20,6 @@ on: type: boolean env: - JAVA_VERSION: 17 - JAVA_DIST: temurin RELEASE_VERSION: ${{ inputs.version }} jobs: @@ -89,13 +87,6 @@ jobs: 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 }}" @@ -106,13 +97,15 @@ jobs: git checkout -b "post-release-v${{ env.RELEASE_VERSION }}" - name: Bump versions + uses: ./.github/workflows/maven-goal + with: + command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -nextSnapshot=true + + - name: Push the post release branch 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 }}" + git push origin "post-release-v${{ env.RELEASE_VERSION }}" - name: Create the post release PR run: gh pr create --title="Post Release v${{ env.RELEASE_VERSION }}" --base main --head "post-release-v${{ env.RELEASE_VERSION }}" -b "Prepare for next iteration" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83cffbc..744573e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,10 +11,6 @@ on: permissions: contents: read -env: - JAVA_VERSION: 17 - JAVA_DIST: adopt - jobs: pre-commit: @@ -35,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 diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..8e2afd3 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17 \ No newline at end of file From 736f187a88c65fc653201828685e21a47bf065d5 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 16:28:52 +0100 Subject: [PATCH 07/14] fix: use directly java-version without file Signed-off-by: Adrien Mannocci --- .github/workflows/maven-goal/action.yml | 6 +++++- .java-version | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 .java-version diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml index b5573e6..4a2468a 100644 --- a/.github/workflows/maven-goal/action.yml +++ b/.github/workflows/maven-goal/action.yml @@ -4,6 +4,10 @@ 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 @@ -22,7 +26,7 @@ runs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: .java-version + java-version: ${{ inputs.version }} distribution: ${{ inputs.distribution }} cache: 'maven' - run: ${{ inputs.command }} diff --git a/.java-version b/.java-version deleted file mode 100644 index 8e2afd3..0000000 --- a/.java-version +++ /dev/null @@ -1 +0,0 @@ -17 \ No newline at end of file From 531e321ec4cb7643745e39e3dd9a2c2414d18314 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 17:10:12 +0100 Subject: [PATCH 08/14] ci: refactor using a reusable workflow Signed-off-by: Adrien Mannocci --- .github/workflows/pre-post-release.yml | 98 ++++++++++++++++++++++++++ .github/workflows/prepare-release.yml | 63 ----------------- .github/workflows/release.yml | 50 ++----------- 3 files changed, 104 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/pre-post-release.yml delete mode 100644 .github/workflows/prepare-release.yml diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml new file mode 100644 index 0000000..02fc79c --- /dev/null +++ b/.github/workflows/pre-post-release.yml @@ -0,0 +1,98 @@ +--- +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 + 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 + phase: + description: 'Pre or post release phase' + type: choice + options: + - pre + - post + default: 'pre' + +env: + 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: Create the release tag + 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 ${{ inputs.phase }}-release-v${{ env.RELEASE_VERSION }} + + - name: Pre bump versions + if: inputs.phase == 'pre' + uses: ./.github/workflows/maven-goal + with: + command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }} + + - name: Post bump versions + 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 "release(${{ inputs.phase }}): ecs-logging-java v${{ env.RELEASE_VERSION }}" + git push origin ${{ inputs.phase }}-release-v${{ env.RELEASE_VERSION }} + + - name: Create the ${{ inputs.phase }} release PR + run: gh pr create --title="${{ inputs.phase }} release v${{ env.RELEASE_VERSION }}" --base main --head ${{ inputs.phase }}-release-v${{ env.RELEASE_VERSION }} -b "${{ inputs.phase }} release v${{ env.RELEASE_VERSION }}" diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml deleted file mode 100644 index cd8e96f..0000000 --- a/.github/workflows/prepare-release.yml +++ /dev/null @@ -1,63 +0,0 @@ ---- -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: - 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: Create a prepare release branch - run: git checkout -b prepare-release-v${{ env.RELEASE_VERSION }} - - - name: Bump versions - uses: ./.github/workflows/maven-goal - with: - command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }} - - - name: Push the prepare release branch - run: | - git add --all - git commit -m "release: ecs-logging-java v${{ env.RELEASE_VERSION }}" - git push origin prepare-release-v${{ env.RELEASE_VERSION }} - - - name: Create the prepare release PR - run: gh pr create --title="Prepare Release 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 c3753e0..a579b42 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,9 +19,6 @@ on: default: false type: boolean -env: - RELEASE_VERSION: ${{ inputs.version }} - jobs: release: name: Release @@ -64,48 +61,13 @@ jobs: 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: 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 - uses: ./.github/workflows/maven-goal - with: - command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -nextSnapshot=true - - - name: Push the post release branch - run: | - git add --all - git commit -m "chore: prepare for next iteration" - git push origin "post-release-v${{ env.RELEASE_VERSION }}" - - - name: Create the post release PR - run: gh pr create --title="Post Release v${{ env.RELEASE_VERSION }}" --base main --head "post-release-v${{ env.RELEASE_VERSION }}" -b "Prepare for next iteration" + uses: ./.github/workflows/pre-post-release.yml + with: + ref: ${{ inputs.ref || 'main' }} + version: ${{ inputs.version }} + phase: 'post' + secrets: inherit From 0b8e19d6c13bfab72b4fa58cbcaa8095ea543789 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Wed, 31 Jan 2024 11:53:00 +0100 Subject: [PATCH 09/14] refactor: avoid duplicate hardcode branch name Signed-off-by: Adrien Mannocci --- .github/workflows/pre-post-release.yml | 15 ++++++++------- .github/workflows/release.yml | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index 02fc79c..79f1b17 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -36,6 +36,7 @@ on: env: RELEASE_VERSION: ${{ inputs.version }} + BRANCH_NAME: ${{ inputs.phase }}-release-v${{ inputs.version }} permissions: contents: read @@ -64,25 +65,25 @@ jobs: - uses: actions/checkout@v4 with: - ref: ${{ inputs.ref || 'main' }} + ref: ${{ inputs.ref }} token: ${{ env.GITHUB_TOKEN }} - - name: Create the release tag + - 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 ${{ inputs.phase }}-release-v${{ env.RELEASE_VERSION }} + run: git checkout -b ${{ env.BRANCH_NAME }} - - name: Pre bump versions + - name: Pre bump versions (pre phase) if: inputs.phase == 'pre' uses: ./.github/workflows/maven-goal with: command: ./mvnw -V versions:set -DprocessAllModules=true -DgenerateBackupPoms=false -DnewVersion=${{ env.RELEASE_VERSION }} - - name: Post bump versions + - name: Post bump versions (post phase) if: inputs.phase == 'post' uses: ./.github/workflows/maven-goal with: @@ -92,7 +93,7 @@ jobs: run: | git add --all git commit -m "release(${{ inputs.phase }}): ecs-logging-java v${{ env.RELEASE_VERSION }}" - git push origin ${{ inputs.phase }}-release-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 ${{ inputs.phase }}-release-v${{ env.RELEASE_VERSION }} -b "${{ inputs.phase }} release v${{ env.RELEASE_VERSION }}" + 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 }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a579b42..ab39f44 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,7 +67,7 @@ jobs: contents: write uses: ./.github/workflows/pre-post-release.yml with: - ref: ${{ inputs.ref || 'main' }} + ref: ${{ inputs.ref }} version: ${{ inputs.version }} phase: 'post' secrets: inherit From d436d1e367a2b5d6ccc009f94034b3589eac4622 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Wed, 31 Jan 2024 11:55:37 +0100 Subject: [PATCH 10/14] ci: create summary file in any case Signed-off-by: Adrien Mannocci --- .ci/release.sh | 2 +- .ci/snapshot.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/release.sh b/.ci/release.sh index 7cfa50c..d2cf966 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -29,7 +29,7 @@ java -version set +x echo "--- Release the binaries to Maven Central :maven:" if [[ "${dry_run}" == "true" ]] ; then - ./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode + ./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee release.txt else ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt fi diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index ae3cbfd..98996c9 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -26,7 +26,7 @@ java -version set +x echo "--- Deploy the snapshot :package:" if [[ "$dry_run" == "true" ]] ; then - ./mvnw -V -s .ci/settings.xml -Pgpg clean package --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 From 0579f47cfdc7c7b0b0a716ea81bf4032deb43d96 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Wed, 31 Jan 2024 12:34:30 +0100 Subject: [PATCH 11/14] feat: validate tag before anything Signed-off-by: Adrien Mannocci --- .github/workflows/pre-post-release.yml | 32 +++++++++++------------ .github/workflows/pre-release.yml | 26 ++++++++++++++++++ .github/workflows/release.yml | 25 +++++++++++++----- .github/workflows/validate-tag/action.yml | 25 ++++++++++++++++++ 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/pre-release.yml create mode 100644 .github/workflows/validate-tag/action.yml diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index 79f1b17..6c65394 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -17,22 +17,6 @@ on: - pre - post required: true - 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 - phase: - description: 'Pre or post release phase' - type: choice - options: - - pre - - post - default: 'pre' env: RELEASE_VERSION: ${{ inputs.version }} @@ -45,9 +29,23 @@ concurrency: group: ${{ github.workflow }} jobs: - create_pr: + 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: ${{ env.RELEASE_VERSION }} + + create-pr: name: "Bump versions and create PR" runs-on: ubuntu-latest + needs: + - validate-tag permissions: contents: write steps: diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000..34c8310 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab39f44..9ba1ca9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,6 @@ --- name: Release -permissions: - contents: read - on: workflow_dispatch: inputs: @@ -19,10 +16,27 @@ on: 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: ${{ env.RELEASE_VERSION }} + release: name: Release runs-on: ubuntu-latest + needs: + - validate-tag steps: - id: buildkite name: Run Release @@ -35,7 +49,7 @@ jobs: waitFor: true printBuildLogs: false buildEnvVars: | - ref=${{ inputs.ref || 'main' }} + ref=${{ inputs.ref }} dry_run=${{ inputs.dry_run || 'false' }} - if: ${{ success() }} @@ -63,9 +77,8 @@ jobs: name: "Bump versions and create PR" needs: - release - permissions: - contents: write uses: ./.github/workflows/pre-post-release.yml + if: inputs.dry_run == 'false' with: ref: ${{ inputs.ref }} version: ${{ inputs.version }} diff --git a/.github/workflows/validate-tag/action.yml b/.github/workflows/validate-tag/action.yml new file mode 100644 index 0000000..a982355 --- /dev/null +++ b/.github/workflows/validate-tag/action.yml @@ -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 From 8648221f313b4bdba9fa09d96046fba28783dbba Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Thu, 1 Feb 2024 16:43:40 +0100 Subject: [PATCH 12/14] chore: apply suggestions Signed-off-by: Adrien Mannocci --- .github/workflows/pre-post-release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index 6c65394..fa312e4 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -75,13 +75,13 @@ jobs: - name: Create a ${{ inputs.phase }} release branch run: git checkout -b ${{ env.BRANCH_NAME }} - - name: Pre bump versions (pre phase) + - 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: Post bump versions (post phase) + - name: Set next snapshot version (post release) if: inputs.phase == 'post' uses: ./.github/workflows/maven-goal with: @@ -90,7 +90,7 @@ jobs: - name: Push the ${{ inputs.phase }} release branch run: | git add --all - git commit -m "release(${{ inputs.phase }}): ecs-logging-java v${{ env.RELEASE_VERSION }}" + 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 From 7c2921734ae4426fbe693b57f462e2a1d8d408c5 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Thu, 1 Feb 2024 16:48:37 +0100 Subject: [PATCH 13/14] fix: validate correctly tags Signed-off-by: Adrien Mannocci --- .github/workflows/pre-post-release.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index fa312e4..39690b0 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -39,7 +39,7 @@ jobs: - name: Validate tag does not exist on current commit uses: ./.github/workflows/validate-tag with: - tag: ${{ env.RELEASE_VERSION }} + tag: v${{ env.RELEASE_VERSION }} create-pr: name: "Bump versions and create PR" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ba1ca9..15f5259 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: - name: Validate tag does not exist on current commit uses: ./.github/workflows/validate-tag with: - tag: ${{ env.RELEASE_VERSION }} + tag: v${{ env.RELEASE_VERSION }} release: name: Release From 16f61a6bde7cecd13553558e4b12a5ffce975cb6 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Thu, 1 Feb 2024 17:44:48 +0100 Subject: [PATCH 14/14] chore: add validation for tag and project version Signed-off-by: Adrien Mannocci --- .github/workflows/release.yml | 6 ++++++ .mvn/maven.config | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 15f5259..a5849fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,6 +31,12 @@ jobs: 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 diff --git a/.mvn/maven.config b/.mvn/maven.config index f20e925..df90860 100644 --- a/.mvn/maven.config +++ b/.mvn/maven.config @@ -1,4 +1,3 @@ --V -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dhttps.protocols=TLSv1.2