-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.yml
More file actions
114 lines (96 loc) · 3.54 KB
/
github.yml
File metadata and controls
114 lines (96 loc) · 3.54 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
name: Sync LeetCode Submissions
on:
# Manual trigger
workflow_dispatch:
inputs:
sync_mode:
description: 'Sync mode'
required: true
default: 'incremental'
type: choice
options:
- ac
- all
- incremental
dry_run:
description: 'Dry run (no files written)'
required: false
default: false
type: boolean
# Scheduled run (daily at 2 AM UTC)
schedule:
- cron: '0 2 * * *'
# Run on push to main (for testing)
push:
branches:
- main
paths:
- '.github/workflows/sync-leetcode.yml'
- 'lc_sync_v2.py'
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write # Required to commit changes
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper commits
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
pip install requests tqdm
- name: Run LeetCode Sync
env:
LEETCODE_SESSION: ${{ secrets.LEETCODE_SESSION }}
CSRF_TOKEN: ${{ secrets.CSRF_TOKEN }}
SYNC_MODE: ${{ github.event.inputs.sync_mode || 'incremental' }}
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
VERBOSE: 'true'
GITHUB_ACTIONS: 'true'
run: |
python lc_sync_v2.py
- name: Check for changes
id: changes
run: |
git diff --quiet && echo "has_changes=false" >> $GITHUB_OUTPUT || echo "has_changes=true" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true' && github.event.inputs.dry_run != 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Stage all changes
git add .
# Create commit message with stats
ADDED=$(git diff --cached --numstat | awk '{sum+=$1} END {print sum}')
DELETED=$(git diff --cached --numstat | awk '{sum+=$2} END {print sum}')
FILES=$(git diff --cached --name-only | wc -l)
git commit -m "🔄 Sync LeetCode submissions [$(date +'%Y-%m-%d')]" \
-m "Added: ${ADDED:-0} lines | Removed: ${DELETED:-0} lines | Files: ${FILES:-0}"
git push
- name: Upload sync state
if: always()
uses: actions/upload-artifact@v4
with:
name: sync-state
path: .leetcode_sync_state.json
retention-days: 90
- name: Summary
if: always()
run: |
echo "## 📊 Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Mode**: ${{ github.event.inputs.sync_mode || 'incremental' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry Run**: ${{ github.event.inputs.dry_run || 'false' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Timestamp**: $(date +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.changes.outputs.has_changes }}" == "true" ]; then
echo "✅ **Changes detected and committed**" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ **No changes detected**" >> $GITHUB_STEP_SUMMARY
fi