-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdaily-release-test.sh
More file actions
executable file
·142 lines (111 loc) · 3.68 KB
/
daily-release-test.sh
File metadata and controls
executable file
·142 lines (111 loc) · 3.68 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Daily automated release test runner
# Runs release-comphy-tag.sh --test-only and opens a GitHub issue on failure
set -uo pipefail
# Ensure Homebrew paths are available (cron has minimal PATH)
if [[ -d "/opt/homebrew/bin" ]]; then
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOGS_DIR="$SCRIPT_DIR/logs"
DATE_STR="$(date -u +%Y-%m-%d)"
TIME_STR="$(date -u +%H:%M:%S)"
LOG_FILE="$LOGS_DIR/release-test-$DATE_STR.log"
mkdir -p "$LOGS_DIR"
log() {
echo "[$(date -u +%Y-%m-%d\ %H:%M:%S)] $1" | tee -a "$LOG_FILE"
}
cleanup_old_logs() {
# Keep only last 30 days of logs
find "$LOGS_DIR" -name "release-test-*.log" -mtime +30 -delete 2>/dev/null || true
}
sync_repo() {
if ! command -v git >/dev/null 2>&1; then
log "WARNING: git not found; skipping repo sync"
return
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
log "WARNING: not a git repo; skipping repo sync"
return
fi
local branch
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
if [[ -z "$branch" ]]; then
log "WARNING: unable to determine branch; skipping repo sync"
return
fi
if [[ "$branch" != "main" ]]; then
log "WARNING: on branch '$branch'; skipping repo sync"
return
fi
if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
log "WARNING: working tree not clean; skipping repo sync"
return
fi
if ! git remote get-url origin >/dev/null 2>&1; then
log "WARNING: missing origin remote; skipping repo sync"
return
fi
log "Syncing repo from origin/main"
if git fetch origin --tags && git pull --ff-only origin main; then
log "Repo sync complete"
else
log "WARNING: repo sync failed; continuing"
fi
}
open_issue_on_failure() {
local exit_code="$1"
if ! command -v gh >/dev/null 2>&1; then
log "WARNING: gh not found; skipping GitHub issue creation"
return
fi
# Check if an open issue with this label already exists
local existing_issue
existing_issue=$(gh issue list --repo comphy-lab/basilisk-C --label "automated-test-failure" --state open --limit 1 --json number --jq '.[0].number // empty' 2>/dev/null || true)
if [[ -n "$existing_issue" ]]; then
log "Open issue #$existing_issue already exists, adding comment instead of creating new issue"
local comment_body="**Test failed again on $DATE_STR at $TIME_STR UTC**
Exit code: \`$exit_code\`
<details>
<summary>Last 80 lines of log</summary>
\`\`\`
$(tail -80 "$LOG_FILE")
\`\`\`
</details>"
gh issue comment "$existing_issue" --repo comphy-lab/basilisk-C --body "$comment_body"
return
fi
# Create new issue
local issue_body="The daily automated release test failed on **$DATE_STR** at **$TIME_STR UTC**.
**Exit code:** \`$exit_code\`
## Log output (last 80 lines)
\`\`\`
$(tail -80 "$LOG_FILE")
\`\`\`
---
*This issue was created automatically by \`daily-release-test.sh\`*"
log "Creating GitHub issue for test failure..."
gh issue create \
--repo comphy-lab/basilisk-C \
--title "[Automated] Release test failed on $DATE_STR" \
--body "$issue_body" \
--label "automated-test-failure"
}
# Main execution
log "=========================================="
log "Starting daily release test"
log "=========================================="
cleanup_old_logs
cd "$SCRIPT_DIR"
sync_repo
# Run the test and capture output (use tee for verbose console output)
log "Running: ./release-comphy-tag.sh --test-only"
if ./release-comphy-tag.sh --test-only 2>&1 | tee -a "$LOG_FILE"; then
log "SUCCESS: Release test passed"
exit 0
else
exit_code=$?
log "FAILURE: Release test failed with exit code $exit_code"
open_issue_on_failure "$exit_code"
exit $exit_code
fi