From d8459c1a94dd96fe437f8bb5e3959ee74db67bfc Mon Sep 17 00:00:00 2001 From: Marcelo Vargas Date: Thu, 20 Jul 2023 16:59:25 -0700 Subject: [PATCH] use an existing github action for that --- .github/workflows/delete-old-branches.yml | 46 +++++------------------ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/.github/workflows/delete-old-branches.yml b/.github/workflows/delete-old-branches.yml index c940831a..5c012030 100644 --- a/.github/workflows/delete-old-branches.yml +++ b/.github/workflows/delete-old-branches.yml @@ -7,42 +7,16 @@ on: [push] jobs: delete-old-branches: + name: Delete old branches runs-on: ubuntu-latest steps: - - name: Checkout Repository + - name: Checkout repository uses: actions/checkout@v2 - - - name: Fetch All Branches - run: git fetch --prune --all - - - name: Delete branches older than 7 days - run: | - # Get the current date in Unix timestamp format - current_date=$(date +%s) - - # Get the list of remote branches and iterate over each branch - git branch -r | while read branch; do - # Extract the branch name from the full reference (e.g., "origin/branch-name") - branch_name=${branch#"origin/"} - - # Skip the 'master' branch - if [ "$branch_name" = "master" ]; then - continue - fi - - # Get the last commit date of the branch in Unix timestamp format - last_commit_date=$(git show -s --format=%ct "origin/$branch_name") - - # Calculate the time difference in seconds between the current date and last commit date - time_difference=$((current_date - last_commit_date)) - - # Define the threshold in seconds (7 days: 7 days * 24 hours/day * 60 minutes/hour * 60 seconds/minute) - threshold=$((7 * 24 * 60 * 60)) - - # Check if the branch is stale (not updated in the last 7 days) and list it if so - if [ "$time_difference" -gt "$threshold" ]; then - echo "Stale branch: $branch_name" - # git push --delete origin "$branch_name" - # git branch -d "$branch_name" - fi - done \ No newline at end of file + - name: Run delete-old-branches-action + uses: beatlabs/delete-old-branches-action@v0.0.10 + with: + repo_token: ${{ github.token }} + date: '7 days ago' + default_branches: main,master,staging + dry_run: true + exclude_open_pr_branches: true \ No newline at end of file