-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathweekly-spec-update-cleanup.yaml
More file actions
59 lines (52 loc) · 2.08 KB
/
weekly-spec-update-cleanup.yaml
File metadata and controls
59 lines (52 loc) · 2.08 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: spec update cleanup (cron job)
on:
schedule:
- cron: '21 2 * * 1'
workflow_dispatch:
jobs:
find-stale-branches:
name: 'Find stale spec-update branches'
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.list.outputs.branches }}
steps:
- name: 'List spec-update branches older than 90 days'
id: list
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CUTOFF_DATE=$(date -d "90 days ago" +%s)
STALE=()
while IFS= read -r BRANCH; do
COMMITTED_AT=$(gh api "repos/SAP/ai-sdk-java/branches/$BRANCH" \
--jq '.commit.commit.committer.date' 2>/dev/null)
if [ -z "$COMMITTED_AT" ]; then
echo "Could not fetch date for $BRANCH, skipping."
continue
fi
if [ "$(date -d "$COMMITTED_AT" +%s)" -lt "$CUTOFF_DATE" ]; then
echo "Stale: $BRANCH (last commit: $COMMITTED_AT)"
# branch format: spec-update/<service>/<ref>
REMAINDER="${BRANCH#spec-update/}"
SERVICE="${REMAINDER%%/*}"
REF="${REMAINDER#*/}"
# Build a JSON object from the shell variables, jq handles proper escaping
ENTRY=$(jq -n --arg branch "$BRANCH" --arg service "$SERVICE" --arg ref "$REF" \
'{branch: $branch, service: $service, ref: $ref}')
STALE+=("$ENTRY")
fi
done < <(gh api "repos/SAP/ai-sdk-java/branches" --paginate --jq '.[].name' | grep '^spec-update/')
echo "Found ${#STALE[@]} stale branch(es)"
echo "branches=$(printf '%s\n' "${STALE[@]}" | jq -sc .)" >> "$GITHUB_OUTPUT"
cleanup-stale-branch:
name: 'Cleanup ${{ matrix.branch }}'
needs: find-stale-branches
if: ${{ needs.find-stale-branches.outputs.branches != '[]' }}
strategy:
matrix:
include: ${{ fromJson(needs.find-stale-branches.outputs.branches) }}
uses: ./.github/workflows/spec-update-cleanup.yaml
with:
service: ${{ matrix.service }}
ref: ${{ matrix.ref }}
secrets: inherit