From 531e321ec4cb7643745e39e3dd9a2c2414d18314 Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Tue, 30 Jan 2024 17:10:12 +0100 Subject: [PATCH] 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