Skip to content

Commit

Permalink
Externalise backport action (#1373)
Browse files Browse the repository at this point in the history
The back porting logic is integrated into each action, duplicated [many
times across the
codebase](https://github.com/search?q=org%3Ahazelcast+%22Checkout+maintenance+branch+and+cherry-pick%22&type=code).

Instead, the logic should be externalised to be re-used.

Changes:
- referenced new workflow instead of duplication
- refactored all and specified branch actions into a single action
   - maintained branches only needs to be specified once
- updated backporting process
   - re-ordered so `checkout` done only if required
- updated commit metadata to use the `ACTOR` (ie commit author) vs
hardcoded 🤖
- updated maintenance branches to reflect [supported
versions](https://support.hazelcast.com/s/article/Version-Support-Windows)

Tested via a [dummy
repo](https://github.com/JackPGreen2/hz-docs/actions/runs/11817864506).
  • Loading branch information
JackPGreen authored Nov 18, 2024
1 parent 41fd0e6 commit 5530198
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 285 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/backport-5-0.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/backport-5-1.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/backport-5-2.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/backport-5-3.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/backport-5-5.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
name: Backport changes to the 5.4.0 branch
name: Backport changes

on:
push:
branches:
- main
workflow_call:
inputs:
label-to-check-for:
required: true
type: string
target-branch:
required: true
type: string

jobs:
backport:
strategy:
matrix:
branch: ['v/5.4']
runs-on: ubuntu-latest
steps:

- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"

steps:
- name: Check PR for backport label
id: check_pr_labels
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["backport to 5.4"]'
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ inputs.label-to-check-for }}

- name: See result
run: echo "${{ steps.check_pr_labels.outputs.result }}"

- name: Checkout repository
if: ${{ steps.check_pr_labels.outputs.result == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout maintenance branch and cherry-pick
if: ${{ steps.check_pr_labels.outputs.result == 'true' }}
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git fetch
git checkout ${{ matrix.branch }}
git checkout ${{ inputs.target-branch }}
git cherry-pick -x --strategy=recursive -X theirs $GITHUB_SHA
git push
58 changes: 27 additions & 31 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
name: Backport changes to all maintenance branches
name: Backport changes to maintenance branches
on:
push:
branches:
- main
jobs:
backport:
strategy:
matrix:
branch: ['v/5.0', 'v/5.1', 'v/5.2', 'v/5.3', 'v/5.4', 'v/5.5']
get-maintenance-branches:
runs-on: ubuntu-latest
outputs:
branches: "['5.3', '5.4', '5.5']"
steps:

- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: exit 0

- name: Set up git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Check PR for backport label
id: check_pr_labels
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["backport to all versions"]'

- name: See result
run: echo "${{ steps.check_pr_labels.outputs.result }}"
backport-to-all-branch:
needs: get-maintenance-branches
strategy:
fail-fast: false
matrix:
branch: ${{ fromJSON(needs.get-maintenance-branches.outputs.branches) }}
uses: ./.github/workflows/backport-workflow.yml
with:
label-to-check-for: '["backport to all versions"]'
target-branch: v/${{ matrix.branch }}
secrets: inherit

- name: Checkout maintenance branch and cherry-pick
if: ${{ steps.check_pr_labels.outputs.result == 'true' }}
run: |
git fetch
git checkout ${{ matrix.branch }}
git cherry-pick -x --strategy=recursive -X theirs $GITHUB_SHA
git push
backport-to-specified-branch:
needs: get-maintenance-branches
strategy:
fail-fast: false
matrix:
branch: ${{ fromJSON(needs.get-maintenance-branches.outputs.branches) }}
uses: ./.github/workflows/backport-workflow.yml
with:
label-to-check-for: '["backport to ${{ matrix.branch }}"]'
target-branch: v/${{ matrix.branch }}
secrets: inherit
38 changes: 5 additions & 33 deletions .github/workflows/forwardport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,8 @@ on:
- v/*
jobs:
forwardport:
strategy:
matrix:
branch: ['main']
runs-on: ubuntu-latest
steps:

- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Check PR for forwardport label
id: check_pr_labels
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["forwardport to snapshot"]'

- name: See result
run: echo "${{ steps.check_pr_labels.outputs.result }}"

- name: Checkout branch and cherry-pick
if: ${{ steps.check_pr_labels.outputs.result == 'true' }}
run: |
git fetch
git checkout ${{ matrix.branch }}
git cherry-pick -x --strategy=recursive -X theirs $GITHUB_SHA
git push
uses: ./.github/workflows/backport-workflow.yml
with:
label: '["forwardport to snapshot"]'
target-branch: main
secrets: inherit

0 comments on commit 5530198

Please sign in to comment.