-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (161 loc) · 6.73 KB
/
daily-challenge.yml
File metadata and controls
183 lines (161 loc) · 6.73 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Daily LeetCode Challenge
on:
schedule:
# Run at 00:30 UTC every day (08:30 Beijing time)
- cron: '30 0 * * *'
workflow_dispatch:
inputs:
problem_id:
description: 'Problem ID to solve (optional)'
required: false
default: ''
# Prevent concurrent runs
concurrency:
group: daily-challenge
cancel-in-progress: false
jobs:
solve:
name: Solve Daily Challenge
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential ccache ninja-build just
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
# Daily challenge uses its own primary cache key
# but can restore from CI's full build cache for faster initial builds
key: ${{ runner.os }}-gcc-daily-challenge-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-gcc-daily-challenge-
${{ runner.os }}-gcc-full-
${{ runner.os }}-gcc-incremental-
${{ runner.os }}-gcc-
max-size: 500M
- name: Set up Python virtual environment
run: |
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
- name: Run AI solver
env:
MOONSHOT_API_KEY: ${{ secrets.MOONSHOT_API_KEY }}
AI_SOLVER_GENERATE_REPORT: 'true'
LEETCODE_COOKIE: ${{ secrets.LEETCODE_COOKIE }}
run: |
source venv/bin/activate
if [ -n "${{ github.event.inputs.problem_id }}" ]; then
python -m script.leetcode.ai.solver ${{ github.event.inputs.problem_id }} --report
else
python -m script.leetcode.ai.solver --report
fi
continue-on-error: true
- name: Get problem info
id: get_info
run: |
# Check SKIP_PR flag first
if [ -f "SKIP_PR" ]; then
echo "should_skip=true" >> $GITHUB_OUTPUT
echo "skip_reason=$(cat SKIP_PR)" >> $GITHUB_OUTPUT
echo "Skipping PR creation - $(cat SKIP_PR)"
exit 0
else
echo "should_skip=false" >> $GITHUB_OUTPUT
fi
REPORT_FILE=$(ls SOLUTION_REPORT_*.md 2>/dev/null | head -1)
PROBLEM_ID=$(echo ${REPORT_FILE#SOLUTION_REPORT_} | sed 's/\.md$//')
echo "problem_id=${PROBLEM_ID:-}" >> $GITHUB_OUTPUT
echo "report_file=${REPORT_FILE:-}" >> $GITHUB_OUTPUT
echo "has_solution=false" >> $GITHUB_OUTPUT
[ -z "$REPORT_FILE" ] && echo "No solution report found" && exit 0
echo "Found report: $REPORT_FILE (ID: $PROBLEM_ID)"
# Check both new files (??) and modified files (M)
SOURCE_FILE=$(git status --porcelain | grep -E '^(\?\?| M)' | grep 'src/leetcode/problems/.*\.cpp$' | awk '{print $2}' | head -1)
HEADER_FILE=$(git status --porcelain | grep -E '^(\?\?| M)' | grep 'include/leetcode/problems/.*\.h$' | awk '{print $2}' | head -1)
TEST_FILE=$(git status --porcelain | grep -E '^(\?\?| M)' | grep 'test/leetcode/problems/.*\.cpp$' | awk '{print $2}' | head -1)
if [ -n "$SOURCE_FILE" ] && [ -n "$HEADER_FILE" ] && [ -n "$TEST_FILE" ]; then
PROBLEM_SLUG=$(basename "$SOURCE_FILE" .cpp)
echo "problem_slug=$PROBLEM_SLUG" >> $GITHUB_OUTPUT
echo "has_solution=true" >> $GITHUB_OUTPUT
echo "source_file=$SOURCE_FILE" >> $GITHUB_OUTPUT
echo "header_file=$HEADER_FILE" >> $GITHUB_OUTPUT
echo "test_file=$TEST_FILE" >> $GITHUB_OUTPUT
echo "All required files found for: $PROBLEM_SLUG"
else
echo "Incomplete files generated"
[ -z "$SOURCE_FILE" ] && echo " - Missing source file"
[ -z "$HEADER_FILE" ] && echo " - Missing header file"
[ -z "$TEST_FILE" ] && echo " - Missing test file"
fi
- name: Build and test solution
if: steps.get_info.outputs.has_solution == 'true'
run: |
PROBLEM_SLUG="${{ steps.get_info.outputs.problem_slug }}"
echo "Building and testing: $PROBLEM_SLUG"
mkdir -p build && cd build
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLEETCODE_SINGLE_PROBLEM="$PROBLEM_SLUG"
cmake --build . -j
./bin/single_problem_test
- name: Update documentation
if: steps.get_info.outputs.has_solution == 'true'
run: |
# Generate updated SOLVED.md
source venv/bin/activate
just doc
# Check if SOLVED.md was updated
if git diff --quiet SOLVED.md 2>/dev/null; then
echo "No changes to SOLVED.md"
else
echo "SOLVED.md updated"
fi
- name: Upload artifacts
if: steps.get_info.outputs.report_file != ''
uses: actions/upload-artifact@v4
with:
name: solution-problem-${{ steps.get_info.outputs.problem_id }}
path: |
${{ steps.get_info.outputs.report_file }}
${{ steps.get_info.outputs.source_file }}
${{ steps.get_info.outputs.header_file }}
${{ steps.get_info.outputs.test_file }}
retention-days: 7
if-no-files-found: ignore
- name: Create Pull Request
if: steps.get_info.outputs.has_solution == 'true' && steps.get_info.outputs.should_skip != 'true' && success()
uses: peter-evans/create-pull-request@v5
with:
commit-message: "feat: Add solution for LeetCode #${{ steps.get_info.outputs.problem_id }}"
title: "🤖 Daily Challenge: Problem #${{ steps.get_info.outputs.problem_id }}"
body-path: ${{ steps.get_info.outputs.report_file }}
branch: daily-challenge/${{ steps.get_info.outputs.problem_id }}
base: main
labels: |
daily-challenge
ai-generated
draft: false
delete-branch: true
# Include all changes: new problem files + updated SOLVED.md
add-paths: |
src/leetcode/problems/
include/leetcode/problems/
test/leetcode/problems/
SOLVED.md