-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci-run.sh
More file actions
executable file
Β·167 lines (137 loc) Β· 4.36 KB
/
Copy pathci-run.sh
File metadata and controls
executable file
Β·167 lines (137 loc) Β· 4.36 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# CI Script for Guess the Number Game
# This script builds, tests, and records results to Nexus
set -e # Exit immediately if a command exits with a non-zero status
# Configuration
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/guess-the-number"
GAME_NAME="guess-the-number"
BUILD_START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "π Starting CI run for $GAME_NAME"
echo "Build start time: $BUILD_START_TIME"
# Change to project directory
cd "$PROJECT_DIR"
# Initialize variables
BUILD_STATUS=""
TEST_STATUS=""
BUILD_DURATION=0
TEST_DURATION=0
OVERALL_STATUS=""
# Build the project
echo "π¨ Building $GAME_NAME..."
BUILD_TIME_START=$(date +%s)
if npm run build >/tmp/build_output 2>&1; then
BUILD_DURATION=$(($(date +%s) - BUILD_TIME_START))
echo "β
Build successful (took ${BUILD_DURATION}s)"
BUILD_STATUS="success"
BUILD_SUCCESS=true
else
BUILD_DURATION=$(($(date +%s) - BUILD_TIME_START))
echo "β Build failed (took ${BUILD_DURATION}s)" >&2
BUILD_STATUS="failed"
BUILD_SUCCESS=false
# Show build output for debugging
echo "--- Build Output ---" >&2
cat /tmp/build_output >&2
fi
# Test the project
echo "π§ͺ Testing $GAME_NAME..."
TEST_TIME_START=$(date +%s)
if npm run test >/tmp/test_output 2>&1; then
TEST_DURATION=$(($(date +%s) - TEST_TIME_START))
echo "β
Tests passed (took ${TEST_DURATION}s)"
TEST_STATUS="success"
TEST_SUCCESS=true
else
TEST_DURATION=$(($(date +%s) - TEST_TIME_START))
echo "β Tests failed (took ${TEST_DURATION}s)" >&2
TEST_STATUS="failed"
TEST_SUCCESS=false
# Show test output for debugging
echo "--- Test Output ---" >&2
cat /tmp/test_output >&2
fi
# Overall result
if [ "$BUILD_SUCCESS" = true ] && [ "$TEST_SUCCESS" = true ]; then
OVERALL_STATUS="success"
echo "π All checks passed!"
else
OVERALL_STATUS="failed"
echo "π₯ Some checks failed!" >&2
fi
# Record results to Nexus
echo "π Recording results to Nexus..."
# Try to find the appropriate project in Nexus
PROJECT_ID=$(npx pnpm --filter nexus-backend exec tsx src/cli.ts project list 2>/dev/null | grep -v "No projects found" | grep -v "Projects" | head -1 | awk '{print $1}' | cut -c1-24)
if [ -z "$PROJECT_ID" ]; then
echo "β οΈ No projects found in Nexus, creating a default project..."
# Create a temporary project for CI results
PROJECT_ID="temp-ci-project-$(date +%s)"
TEMP_PROJECT_JSON=$(mktemp)
cat > "$TEMP_PROJECT_JSON" <<EOF
{
"id": "$PROJECT_ID",
"name": "CI Results Project",
"description": "Temporary project for CI results storage",
"status": "active",
"category": "ci"
}
EOF
# We don't have direct database access commands, so we'll just note this
echo "Created temporary project ID: $PROJECT_ID"
else
echo "Using existing project ID: $PROJECT_ID"
fi
# Prepare command outputs for the summary
if [ "$BUILD_SUCCESS" = true ]; then
BUILD_OUTPUT_SUMMARY="Build Output: Success"
else
BUILD_OUTPUT_SUMMARY=$(cat /tmp/build_output)
fi
if [ "$TEST_SUCCESS" = true ]; then
TEST_OUTPUT_SUMMARY="Test Output: Success"
else
TEST_OUTPUT_SUMMARY=$(cat /tmp/test_output)
fi
# Create CI result summary
CI_SUMMARY=$(cat <<EOF
# CI Run Summary - $GAME_NAME
**Build Start Time:** $BUILD_START_TIME
## Build Results
- Status: $BUILD_STATUS
- Duration: ${BUILD_DURATION}s
## Test Results
- Status: $TEST_STATUS
- Duration: ${TEST_DURATION}s
## Overall Status
- $OVERALL_STATUS
## Command Output
\`\`\`
Build Command: npm run build
$BUILD_OUTPUT_SUMMARY
Test Command: npm run test
$TEST_OUTPUT_SUMMARY
\`\`\`
---
*Automated CI run generated on $(date -u +"%Y-%m-%d %H:%M:%S UTC")*
EOF
)
# Save the CI results to a file that can be added to Nexus
CI_RESULT_FILE="/tmp/ci-result-$(date +%s).md"
echo "$CI_SUMMARY" > "$CI_RESULT_FILE"
echo "CI results saved to: $CI_RESULT_FILE"
# Add to project notes/chat if possible
echo "The CI results have been saved to: $CI_RESULT_FILE"
echo "This file would normally be added to the Nexus project's chat or notes."
echo ""
echo "To add this to a project manually:"
echo "1. Import the file to the appropriate project"
echo "2. Add it to the project's roadmap/chat notes"
echo ""
echo "Build status: $OVERALL_STATUS"
# Clean up temporary files
rm -f /tmp/build_output /tmp/test_output
exit_code=0
if [ "$BUILD_SUCCESS" != true ] || [ "$TEST_SUCCESS" != true ]; then
exit_code=1
fi
exit $exit_code