Skip to content

Commit

Permalink
ci: refactor using a reusable workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Adrien Mannocci <[email protected]>
  • Loading branch information
amannocci committed Jan 30, 2024
1 parent 736f187 commit 531e321
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 107 deletions.
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:
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 }}"
63 changes: 0 additions & 63 deletions .github/workflows/prepare-release.yml

This file was deleted.

50 changes: 6 additions & 44 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ on:
default: false
type: boolean

env:
RELEASE_VERSION: ${{ inputs.version }}

jobs:
release:
name: Release
Expand Down Expand Up @@ -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

0 comments on commit 531e321

Please sign in to comment.