-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathcopy-latest-gh-action-failure.sh
More file actions
executable file
·58 lines (47 loc) · 1.75 KB
/
copy-latest-gh-action-failure.sh
File metadata and controls
executable file
·58 lines (47 loc) · 1.75 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
#!/bin/bash
# Get the repository in owner/repo format
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
# Get the latest failed workflow run
LATEST_FAILURE=$(gh run list --repo "$REPO" --status failure --limit 1 --json databaseId,displayTitle,conclusion -q '.[0]')
if [ -z "$LATEST_FAILURE" ]; then
echo "No failed workflow runs found"
exit 1
fi
RUN_ID=$(echo "$LATEST_FAILURE" | jq -r '.databaseId')
RUN_TITLE=$(echo "$LATEST_FAILURE" | jq -r '.displayTitle')
echo "Found failed run: $RUN_TITLE (ID: $RUN_ID)"
echo "Fetching logs..."
# Get all job logs for the failed run
LOGS=$(gh run view "$RUN_ID" --repo "$REPO" --log-failed 2>/dev/null)
if [ -z "$LOGS" ]; then
# If --log-failed doesn't work, try getting all logs
LOGS=$(gh run view "$RUN_ID" --repo "$REPO" --log 2>/dev/null)
fi
# Create a formatted output with run details and logs
OUTPUT="GitHub Action Failure Report
Repository: $REPO
Run: $RUN_TITLE
Run ID: $RUN_ID
URL: https://github.com/$REPO/actions/runs/$RUN_ID
================================================================================
LOGS:
================================================================================
$LOGS"
# Copy to clipboard (cross-platform)
if command -v pbcopy > /dev/null; then
# macOS
echo "$OUTPUT" | pbcopy
echo "✓ Failure logs copied to clipboard"
elif command -v xclip > /dev/null; then
# Linux with xclip
echo "$OUTPUT" | xclip -selection clipboard
echo "✓ Failure logs copied to clipboard"
elif command -v xsel > /dev/null; then
# Linux with xsel
echo "$OUTPUT" | xsel --clipboard --input
echo "✓ Failure logs copied to clipboard"
else
echo "Error: No clipboard utility found (pbcopy, xclip, or xsel)"
echo "Logs printed below:"
echo "$OUTPUT"
fi