summaryrefslogtreecommitdiff
path: root/.github/workflows/cleanup-mirror-pr-branch.yml
blob: c5de9ab733cefbc9429823655e807c023e11862a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
name: Cleanup pr mirror branch

on:
  pull_request:
    types: [closed]
    branches:
        - current
  workflow_dispatch:
    inputs:
      branch:
        description: 'Branch to delete'
        required: true

permissions:
  contents: write

jobs:
  delete_branch:
    if: ${{ (github.event_name == 'workflow_dispatch' || startsWith(github.event.pull_request.head.ref, 'mirror/')) && github.repository_owner != 'vyos' }}
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Delete branch
        run: |
          branch=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.event.pull_request.head.ref }}
          if [[ $branch != mirror/* ]]; then
            echo "Branch name to clean must start with 'mirror/'"
            exit 1
          fi
          repo=${{ github.repository }}
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
          git push origin --delete $branch