From 00c9e4d874b313fe539b090a5146842e3d53f51f Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Tue, 12 Sep 2023 13:54:40 -0700 Subject: [PATCH] Adds backport workflow (#28) Added backport workflow Signed-off-by: Owais Kazi --- .github/workflows/add-backport-label.yml | 14 +++++++ .github/workflows/backport.yml | 39 ++++++++++++++++++++ .github/workflows/delete-backport-branch.yml | 15 ++++++++ 3 files changed, 68 insertions(+) create mode 100644 .github/workflows/add-backport-label.yml create mode 100644 .github/workflows/backport.yml create mode 100644 .github/workflows/delete-backport-branch.yml diff --git a/.github/workflows/add-backport-label.yml b/.github/workflows/add-backport-label.yml new file mode 100644 index 000000000..89eca1976 --- /dev/null +++ b/.github/workflows/add-backport-label.yml @@ -0,0 +1,14 @@ +name: Add Backport Label +on: + pull_request_target: + branches: main + types: opened + +jobs: + add_labels: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-ecosystem/action-add-labels@v1 + with: + labels: backport 2.x diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 000000000..26a7aa496 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,39 @@ +name: Backport +on: + pull_request_target: + types: + - closed + - labeled + +jobs: + backport: + name: Backport + runs-on: ubuntu-latest + # Only react to merged PRs for security reasons. + # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. + if: > + github.event.pull_request.merged + && ( + github.event.action == 'closed' + || ( + github.event.action == 'labeled' + && contains(github.event.label.name, 'backport') + ) + ) + permissions: + contents: write + pull-requests: write + steps: + - name: GitHub App token + id: github_app_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + installation_id: 22958780 + + - name: Backport + uses: VachaShah/backport@v2.2.0 + with: + github_token: ${{ steps.github_app_token.outputs.token }} + head_template: backport/backport-<%= number %>-to-<%= base %> diff --git a/.github/workflows/delete-backport-branch.yml b/.github/workflows/delete-backport-branch.yml new file mode 100644 index 000000000..f24f022b0 --- /dev/null +++ b/.github/workflows/delete-backport-branch.yml @@ -0,0 +1,15 @@ +name: Delete merged branch of the backport PRs +on: + pull_request: + types: + - closed + +jobs: + delete-branch: + runs-on: ubuntu-latest + if: startsWith(github.event.pull_request.head.ref,'backport/') + steps: + - name: Delete merged branch + uses: SvanBoxel/delete-merged-branch@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}