Skip to content

Commit 4688e5e

Browse files
committed
Updated test runner for MaxOSX
1 parent a35c203 commit 4688e5e

File tree

7 files changed

+819
-4
lines changed

7 files changed

+819
-4
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Error Reporter
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Test Suite", "CI/CD Pipeline"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
report-errors:
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Download artifacts
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: ${{ github.event.workflow_run.id }}
30+
});
31+
32+
console.log(`Found ${artifacts.data.artifacts.length} artifacts`);
33+
34+
- name: Parse test results
35+
id: parse-results
36+
run: |
37+
echo "## Test Failure Summary" > error_summary.md
38+
echo "" >> error_summary.md
39+
echo "Workflow: ${{ github.event.workflow_run.name }}" >> error_summary.md
40+
echo "Run ID: ${{ github.event.workflow_run.id }}" >> error_summary.md
41+
echo "Branch: ${{ github.event.workflow_run.head_branch }}" >> error_summary.md
42+
echo "" >> error_summary.md
43+
44+
# Export for use in other steps
45+
echo "summary_file=error_summary.md" >> $GITHUB_OUTPUT
46+
47+
- name: Comment on PR (if applicable)
48+
if: github.event.workflow_run.event == 'pull_request'
49+
uses: actions/github-script@v7
50+
with:
51+
script: |
52+
const fs = require('fs');
53+
const summary = fs.readFileSync('error_summary.md', 'utf8');
54+
55+
const issue_number = context.payload.workflow_run.pull_requests[0]?.number;
56+
if (issue_number) {
57+
await github.rest.issues.createComment({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
issue_number: issue_number,
61+
body: summary + '\n\n[View full logs](' + context.payload.workflow_run.html_url + ')'
62+
});
63+
}
64+
65+
- name: Create issue for persistent failures
66+
if: github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'master'
67+
uses: actions/github-script@v7
68+
with:
69+
script: |
70+
const fs = require('fs');
71+
const summary = fs.readFileSync('error_summary.md', 'utf8');
72+
73+
await github.rest.issues.create({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
title: `Test Failure in ${context.payload.workflow_run.name}`,
77+
body: summary + '\n\n[View full logs](' + context.payload.workflow_run.html_url + ')',
78+
labels: ['test-failure', 'automated']
79+
});

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
scripts/
2+
*.sh
13
*.pyc
24
.idea
35
build/

scripts/ci_interface.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/bin/bash
2+
# CI Interface Script - Direct interface with GitHub Actions
3+
4+
set -e
5+
6+
# Configuration
7+
REPO="rowingdude/analyzeMFT"
8+
BRANCH=$(git branch --show-current 2>/dev/null || echo "main")
9+
10+
# Colors
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m'
16+
17+
echo -e "${BLUE}GitHub Actions CI Interface${NC}"
18+
echo "Repository: $REPO"
19+
echo "Branch: $BRANCH"
20+
echo ""
21+
22+
# Function to setup GitHub CLI
23+
setup_gh() {
24+
if ! command -v gh &> /dev/null; then
25+
echo -e "${YELLOW}GitHub CLI not found. Installing...${NC}"
26+
27+
# Detect OS and install
28+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
29+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
30+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
31+
sudo apt update
32+
sudo apt install gh
33+
elif [[ "$OSTYPE" == "darwin"* ]]; then
34+
brew install gh
35+
else
36+
echo -e "${RED}Please install GitHub CLI manually: https://cli.github.com${NC}"
37+
exit 1
38+
fi
39+
fi
40+
41+
# Check authentication
42+
if ! gh auth status &> /dev/null; then
43+
echo -e "${YELLOW}Please authenticate with GitHub:${NC}"
44+
gh auth login
45+
fi
46+
}
47+
48+
# Function to push and monitor
49+
push_and_monitor() {
50+
echo -e "${YELLOW}Pushing current branch to GitHub...${NC}"
51+
git push origin $BRANCH
52+
53+
echo -e "${YELLOW}Waiting for workflow to start...${NC}"
54+
sleep 5
55+
56+
# Get the latest run for this branch
57+
run_id=$(gh run list --branch $BRANCH --limit 1 --json databaseId --jq '.[0].databaseId' -R $REPO)
58+
59+
if [ -z "$run_id" ]; then
60+
echo -e "${RED}No workflow run found${NC}"
61+
exit 1
62+
fi
63+
64+
echo -e "${GREEN}Monitoring run $run_id...${NC}"
65+
gh run watch $run_id -R $REPO
66+
67+
# Get conclusion
68+
conclusion=$(gh run view $run_id --json conclusion --jq '.conclusion' -R $REPO)
69+
70+
if [ "$conclusion" = "failure" ]; then
71+
echo -e "${RED}Run failed! Getting error details...${NC}"
72+
gh run view $run_id --log-failed -R $REPO | head -100
73+
74+
# Parse and show test failures
75+
echo -e "\n${YELLOW}Test Failures Summary:${NC}"
76+
gh run view $run_id --log-failed -R $REPO | grep -E "FAILED|ERROR" | head -20
77+
78+
return 1
79+
else
80+
echo -e "${GREEN}All tests passed!${NC}"
81+
return 0
82+
fi
83+
}
84+
85+
# Function to run tests locally first
86+
local_test() {
87+
echo -e "${BLUE}Running local tests first...${NC}"
88+
89+
if [ -f "run_tests.sh" ]; then
90+
bash run_tests.sh
91+
else
92+
python -m pytest tests/ -q --tb=no --maxfail=5
93+
fi
94+
95+
if [ $? -ne 0 ]; then
96+
echo -e "${RED}Local tests failed. Fix them before pushing.${NC}"
97+
return 1
98+
fi
99+
100+
echo -e "${GREEN}Local tests passed!${NC}"
101+
return 0
102+
}
103+
104+
# Function to get real-time logs
105+
stream_logs() {
106+
local run_id=$1
107+
if [ -z "$run_id" ]; then
108+
run_id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId' -R $REPO)
109+
fi
110+
111+
echo -e "${BLUE}Streaming logs for run $run_id...${NC}"
112+
113+
# Stream logs in real-time
114+
while true; do
115+
status=$(gh run view $run_id --json status --jq '.status' -R $REPO)
116+
117+
if [ "$status" = "completed" ]; then
118+
break
119+
fi
120+
121+
# Get current logs
122+
gh run view $run_id --log -R $REPO | tail -50
123+
124+
sleep 5
125+
done
126+
127+
conclusion=$(gh run view $run_id --json conclusion --jq '.conclusion' -R $REPO)
128+
echo -e "\nRun completed: $conclusion"
129+
}
130+
131+
# Function to fetch errors as JSON
132+
get_errors_json() {
133+
local run_id=$1
134+
if [ -z "$run_id" ]; then
135+
run_id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId' -R $REPO)
136+
fi
137+
138+
# Create JSON output
139+
echo "{"
140+
echo " \"run_id\": $run_id,"
141+
echo " \"errors\": ["
142+
143+
gh run view $run_id --log-failed -R $REPO | grep -E "FAILED|ERROR" | while read -r line; do
144+
escaped=$(echo "$line" | sed 's/"/\\"/g')
145+
echo " \"$escaped\","
146+
done | sed '$ s/,$//'
147+
148+
echo " ]"
149+
echo "}"
150+
}
151+
152+
# Main menu
153+
case "${1:-}" in
154+
setup)
155+
setup_gh
156+
;;
157+
test)
158+
local_test
159+
;;
160+
push)
161+
local_test && push_and_monitor
162+
;;
163+
monitor)
164+
push_and_monitor
165+
;;
166+
stream)
167+
stream_logs $2
168+
;;
169+
errors)
170+
get_errors_json $2
171+
;;
172+
status)
173+
gh run list --limit 5 -R $REPO
174+
;;
175+
*)
176+
echo "Usage: $0 [command] [options]"
177+
echo ""
178+
echo "Commands:"
179+
echo " setup - Setup GitHub CLI"
180+
echo " test - Run local tests"
181+
echo " push - Run tests locally, then push and monitor"
182+
echo " monitor - Push and monitor GitHub Actions"
183+
echo " stream - Stream logs from a run"
184+
echo " errors - Get errors as JSON"
185+
echo " status - Show recent runs"
186+
echo ""
187+
echo "Examples:"
188+
echo " $0 setup"
189+
echo " $0 test"
190+
echo " $0 push"
191+
echo " $0 errors"
192+
;;
193+
esac

0 commit comments

Comments
 (0)