Skip to content

test ci

test ci #6

Workflow file for this run

name: Clear Branch
on:
push:
branches:
- ci-test
workflow_dispatch:
inputs:
ref:
description: "Why trigger?"
required: true
type: string
jobs:
clear_branch:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: 'ci-test'
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Get protected branches
id: get_protected_branches
run: |
# Get the list of protected branches
protected_branches=$(gh api /repos/${{ github.repository }}/branches --jq '.[] | select(.protected == true) | .name' | tr '\n' ' ')
echo "PROTECTED_BRANCHES=${protected_branches}" >> $GITHUB_ENV
- name: List all branches
run: |
git fetch --prune
for branch in $(git branch -r | sed 's/origin\///'|grep -v origin); do
if [[ " ${protected_branches[@]} " =~ " ${branch} " ]]; then
echo "Skipping protected branch: $branch"
continue
fi
last_commit_date=$(git log -1 --format=%ci origin/$branch)
if [[ $(date -d "$last_commit_date" +%s) -lt $(date -d "10 minutes ago" +%s) ]]; then
if ! gh pr list --head $branch --repo https://github.com//${{ github.repository }} | grep $branch; then
echo "Deleting branch: $branch"
git push origin --delete $branch
fi
fi
done