diff --git a/.ci/release.sh b/.ci/release.sh index c6f0666b..d2cf9669 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 -## 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. @@ -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 + ./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 diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index cbd27587..98996c9c 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 | tee snapshot.txt else ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt fi diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml new file mode 100644 index 00000000..4a2468a0 --- /dev/null +++ b/.github/workflows/maven-goal/action.yml @@ -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 }} diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml new file mode 100644 index 00000000..39690b02 --- /dev/null +++ b/.github/workflows/pre-post-release.yml @@ -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 }}" diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 00000000..34c83109 --- /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 dc2e8dcb..a5849fdf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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() }} @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b267508..744573ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 diff --git a/.github/workflows/validate-tag/action.yml b/.github/workflows/validate-tag/action.yml new file mode 100644 index 00000000..a982355e --- /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 diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 00000000..df90860a --- /dev/null +++ b/.mvn/maven.config @@ -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 \ No newline at end of file diff --git a/pom.xml b/pom.xml index a0b7e8f1..5572b4fd 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