Skip to content

👀 Collect Stale Environments 👾 TaylorHalf #42

👀 Collect Stale Environments 👾 TaylorHalf

👀 Collect Stale Environments 👾 TaylorHalf #42

name: 👀 Collect Stale Environments
run-name: 👀 Collect Stale Environments 👾 ${{ github.actor }}
on:
push:
branches:
- feature/CB2-11814
permissions:
id-token: write
contents: write
jobs:
collect-stale-branches:
name: Collect Stale branches
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
runs-on: X64
steps:
- name: checkout
uses: actions/checkout@v4
- name: List all branches with pagination
id: branches
run: |
page=1
per_page=100
branches=()
while true; do
response=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/dvsa/cvs-svc-app-logs/branches?per_page=$per_page\&page=$page \
--jq '.[].name | select(test("^(main|master|develop|devops|HEAD)$|^(release/.*)$") | not)')
if [[ -z "$response" ]]; then
break # Exit loop if no more results
fi
branches+=($response)
((page++))
done
branches_json=$(printf '%s\n' "${branches[@]}" | jq -R . | jq -s .)
echo "Fetched branches: $branches_json"
echo "branches=$(echo $branches_json | jq -c)" >> $GITHUB_ENV
- name: Get commit dates older than stale branch threshold
env:
stale-branch-threshold: "3m"
run: |
three_months_ago=$(date -v-${{ env.stale-branch-threshold }} '+%Y-%m-%d')
echo "Branches: $branches"
for branch in $(jq -r '.[]' <<< '${{ steps.branches.outputs.branches }}'); do
# Search commits in the branch where the author date is older than 3 months
commits=$(gh search commits --author-date="<${three_months_ago}" --repo dvsa/cvs-svc-app-logs --branch $branch --limit 100 --json commit,committerDate --jq '.[] | "\(.commit.oid) \(.committerDate)"')
if [ -n "$commits" ]; then
echo "Branch $branch has commits older than $three_months_ago:"
echo "$commits"
fi
done