👀 Collect Stale Environments 👾 JoshCarter-ops #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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_OUTPUT | |
- name: Test Fetch Commit Dates for All Branches | |
run: | | |
timeago='90 days ago' | |
for branch in $(jq -r '.[]' <<< '${{ steps.branches.outputs.branches }}'); do | |
commit_dates=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/dvsa/cvs-svc-app-logs/commits?sha="$branch" --jq '.[].commit.committer.date' 2>/dev/null) | |
for commit_date in $commit_dates; do | |
dtSec=$(date --date "$" +'%s') | |
taSec=$(date --date "$timeago" +'%s') | |
echo "INFO: dtSec=$dtSec, taSec=$taSec" >&2 | |
[ $dtSec -lt $taSec ] && "echo too old" | |
# # [ ("$commit_date" | date) < "$(date -v-3m)" ] && echo "New Commit" | |
# echo "$commit_date" | |
done | |
# Print commit dates | |
# echo "Commit dates for branch $branch:" | |
# echo "$commit_dates" | |
done |