Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 504a45d

Browse files
committed
enhancement: Add logging for debugging
This commit adds logging to the `get-latest-failed-gha-logs.sh` script to improve debugging and troubleshooting. The script now logs key information such as the repository owner and name, the run ID, and the run conclusion. This provides more visibility into the script's execution flow and helps identify any issues.
1 parent 0259e7b commit 504a45d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

get-latest-failed-gha-logs.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
#!/bin/bash
22

3+
# Log the start of the script
4+
echo "Starting script to get latest failed workflow logs..."
5+
36
# Get the repository owner and name from the origin remote
47
remote_url=$(git remote get-url origin)
58
repo_owner=$(echo "$remote_url" | sed -E 's#.*github.com[:/]([^/]+)/.*#\1#')
69
repo_name=$(echo "$remote_url" | sed -E 's#.*github.com[:/].*/([^/]+).*#\1#')
710

11+
# Log the repository information
12+
echo "Repository owner: $repo_owner"
13+
echo "Repository name: $repo_name"
14+
815
# Get the latest workflow run ID (using jq)
916
run_id=$(gh run list -L 1 --json databaseId -R "$repo_owner/$repo_name" | jq -r '.[0].databaseId')
1017

18+
# Log the run ID
19+
echo "Latest workflow run ID: $run_id"
20+
1121
# Get the run conclusion (e.g., "success", "failure")
1222
conclusion=$(gh run view $run_id --json conclusion -R "$repo_owner/$repo_name" | jq -r '.conclusion')
1323

24+
# Log the run conclusion
25+
echo "Workflow run conclusion: $conclusion"
26+
1427
# Check if the run failed
1528
if [[ "$conclusion" == "failure" ]]; then
16-
# View the failed logs
29+
# Log the failure and view the failed logs
30+
echo "Workflow run failed. Viewing failed logs..."
1731
gh run view $run_id --log-failed -R "$repo_owner/$repo_name"
1832
else
1933
echo "The latest workflow run was successful."
20-
fi
34+
fi
35+
36+
# Log the end of the script
37+
echo "Script finished."

0 commit comments

Comments
 (0)