Repository navigation
115 lines (94 loc) · 3.61 KB
/
Copy pathscheduled-maintenance.yml
File metadata and controls
115 lines (94 loc) · 3.61 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Weekly maintenance: apply LTS security patches and prune stale Keystatic branches.
# Crawling hadylauw.com (publications, team photos) lives in update-publications-and-team.yml.
name: Scheduled Maintenance
on:
# Run every Sunday at 06:00 UTC (14:00 Singapore time), 12h after the daily
# publications & team photos sync (18:00 UTC) so the two never overlap
schedule:
- cron: "0 6 * * 0"
push:
branches: ["main"]
paths:
- ".github/workflows/scheduled-maintenance.yml"
# Allow manual trigger
workflow_dispatch:
permissions:
contents: write
pull-requests: read
# Shared with update-publications-and-team.yml so bot pushes to main never race
concurrency:
group: main-bot-writes
cancel-in-progress: false
jobs:
maintenance:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: "22"
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Auto-patch security vulnerabilities
run: |
pnpm audit --fix update || true
pnpm install
- name: Validate application integrity
run: |
pnpm lint
pnpm typecheck:prepared
- name: Audit all dependencies
run: pnpm audit:dependencies
- name: Check for changes
id: check-changes
run: |
git add pnpm-lock.yaml pnpm-workspace.yaml package.json apps/admin/package.json
git diff --cached --quiet || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: steps.check-changes.outputs.changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "chore: update security patches [automated]"
git pull --rebase origin main
git push
- name: Trigger deploy notice
if: steps.check-changes.outputs.changed == 'true'
run: |
echo "Changes detected and pushed to main. Cloudflare Pages deployment will be triggered automatically."
- name: Clean up stale empty Keystatic branches
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
git fetch --prune origin
now_ts="$(date +%s)"
min_age_seconds=$((7 * 24 * 60 * 60))
while IFS=' ' read -r remote_ref commit_ts; do
[[ -z "$remote_ref" ]] && continue
branch_name="${remote_ref#origin/}"
age=$((now_ts - commit_ts))
if (( age < min_age_seconds )); then
continue
fi
ahead_count="$(git rev-list --count "origin/main..$remote_ref")"
if [[ "$ahead_count" != "0" ]]; then
continue
fi
open_prs="$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --head "$branch_name" --json number --jq 'length')"
if [[ "$open_prs" != "0" ]]; then
continue
fi
echo "Deleting abandoned empty Keystatic branch: $branch_name (idle $((age / 86400))d)"
git push origin --delete "$branch_name" || true
done < <(git for-each-ref --format='%(refname:short) %(committerdate:unix)' refs/remotes/origin/keystatic/)