From 81ab6d5d9d797fe227d15683be20c181aa608c1a Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Thu, 11 Jul 2024 01:31:50 +1200 Subject: [PATCH] Fix delete backport branch workflow (#704) Signed-off-by: Thomas Farr (cherry picked from commit b8cc8ec9c44d5570db60b68271d84eee7d2b2297) --- .github/workflows/backport.yml | 3 ++- .github/workflows/delete_backport_branch.yml | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index e47d8d88c0..8e0dced4e4 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -15,6 +15,7 @@ jobs: steps: - name: GitHub App token id: github_app_token + if: github.repository == 'opensearch-project/opensearch-net' uses: tibdex/github-app-token@v1.5.0 with: app_id: ${{ secrets.APP_ID }} @@ -24,5 +25,5 @@ jobs: - name: Backport uses: VachaShah/backport@v1.1.4 with: - github_token: ${{ steps.github_app_token.outputs.token }} + github_token: ${{ steps.github_app_token.outputs.token || secrets.GITHUB_TOKEN }} branch_name: backport/backport-${{ github.event.number }} diff --git a/.github/workflows/delete_backport_branch.yml b/.github/workflows/delete_backport_branch.yml index f24f022b09..57e82c52d0 100644 --- a/.github/workflows/delete_backport_branch.yml +++ b/.github/workflows/delete_backport_branch.yml @@ -7,9 +7,16 @@ on: jobs: delete-branch: runs-on: ubuntu-latest - if: startsWith(github.event.pull_request.head.ref,'backport/') + if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && startsWith(github.event.pull_request.head.ref, 'backport/') + permissions: + contents: write steps: - name: Delete merged branch - uses: SvanBoxel/delete-merged-branch@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/github-script@v7 + with: + script: | + github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/${context.payload.pull_request.head.ref}`, + })