Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebd5bb0

Browse files
committed
feat: initial commit
0 parents  commit ebd5bb0

File tree

10 files changed

+796
-0
lines changed

10 files changed

+796
-0
lines changed

.github/workflows/lean-ci.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Lean 4 CI on Morph Cloud
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
workflow_dispatch:
9+
inputs:
10+
shards:
11+
description: 'Number of shards to run'
12+
required: false
13+
default: '4'
14+
type: choice
15+
options:
16+
- '4'
17+
- '8'
18+
19+
env:
20+
PYTHON_VERSION: '3.11'
21+
MORPH_PYTHON_VERSION: 'morphcloud'
22+
23+
jobs:
24+
build-snapshot:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
snapshot-id: ${{ steps.build.outputs.snapshot-id }}
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: ${{ env.PYTHON_VERSION }}
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install -U ${{ env.MORPH_PYTHON_VERSION }}
41+
42+
- name: Build Lean 4 snapshot
43+
id: build
44+
env:
45+
MORPH_API_KEY: ${{ secrets.MORPH_API_KEY }}
46+
run: |
47+
python scripts/build_snapshot.py
48+
echo "snapshot-id=$(cat lean_snapshot_id.txt)" >> $GITHUB_OUTPUT
49+
50+
- name: Upload snapshot ID
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: snapshot-id
54+
path: lean_snapshot_id.txt
55+
56+
test-shards:
57+
needs: build-snapshot
58+
runs-on: ubuntu-latest
59+
strategy:
60+
matrix:
61+
shard: ${{ fromJson(format('[0,1,2,3,4,5,6,7]')) }}
62+
shards: ${{ fromJson(format('[{0}]', github.event.inputs.shards || '4')) }}
63+
# Only run the number of shards requested
64+
max-parallel: ${{ github.event.inputs.shards || 4 }}
65+
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v4
69+
70+
- name: Download snapshot ID
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: snapshot-id
74+
path: .
75+
76+
- name: Set up Python
77+
uses: actions/setup-python@v5
78+
with:
79+
python-version: ${{ env.PYTHON_VERSION }}
80+
81+
- name: Install dependencies
82+
run: |
83+
python -m pip install --upgrade pip
84+
pip install -U ${{ env.MORPH_PYTHON_VERSION }}
85+
86+
- name: Run shard ${{ matrix.shard }}
87+
env:
88+
MORPH_API_KEY: ${{ secrets.MORPH_API_KEY }}
89+
run: |
90+
python scripts/run_shard.py \
91+
--shard ${{ matrix.shard }} \
92+
--shards ${{ matrix.shards }}
93+
94+
- name: Upload shard logs
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: logs-shard-${{ matrix.shard }}
98+
path: out/logs/
99+
100+
- name: Upload test output
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: test-output-shard-${{ matrix.shard }}
104+
path: out/logs/${{ matrix.shard }}_test_output.log
105+
if-no-files-found: ignore
106+
107+
summary:
108+
needs: test-shards
109+
runs-on: ubuntu-latest
110+
if: always()
111+
steps:
112+
- name: Download all logs
113+
uses: actions/download-artifact@v4
114+
with:
115+
path: logs/
116+
117+
- name: Generate summary
118+
run: |
119+
echo "## Lean 4 CI Results" >> $GITHUB_STEP_SUMMARY
120+
echo "" >> $GITHUB_STEP_SUMMARY
121+
echo "**Snapshot ID:** $(cat logs/snapshot-id/lean_snapshot_id.txt)" >> $GITHUB_STEP_SUMMARY
122+
echo "" >> $GITHUB_STEP_SUMMARY
123+
echo "**Shard Results:**" >> $GITHUB_STEP_SUMMARY
124+
125+
for log in logs/logs-shard-*/**/*.log; do
126+
if [ -f "$log" ]; then
127+
shard_num=$(basename "$log" .log)
128+
echo "- **Shard $shard_num:** ✅ Completed" >> $GITHUB_STEP_SUMMARY
129+
fi
130+
done
131+
132+
echo "" >> $GITHUB_STEP_SUMMARY
133+
echo "**Performance Targets:**" >> $GITHUB_STEP_SUMMARY
134+
echo "- Cold Start: ≤ p95 60s across ${{ github.event.inputs.shards || 4 }} shards" >> $GITHUB_STEP_SUMMARY
135+
echo "- Warm Cache: ≤ p95 20s across ${{ github.event.inputs.shards || 4 }} shards" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Lean
24+
*.olean
25+
*.olean.d
26+
*.olean.hash
27+
*.olean.trace
28+
*.olean.trace.d
29+
*.olean.trace.hash
30+
*.olean.trace.d.hash
31+
*.olean.trace.hash.d
32+
*.olean.trace.hash.d.hash
33+
34+
# Morph Cloud
35+
lean_snapshot_id.txt
36+
out/
37+
logs/
38+
39+
# IDE
40+
.vscode/
41+
.idea/
42+
*.swp
43+
*.swo
44+
45+
# OS
46+
.DS_Store
47+
Thumbs.db

DEPLOYMENT.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Deployment Guide for Lean 4 CI on Morph Cloud
2+
3+
This guide walks you through deploying the Lean 4 CI pipeline on your own repository.
4+
5+
## Prerequisites
6+
7+
1. **Morph Cloud Account**: Sign up at [cloud.morph.so](https://cloud.morph.so)
8+
2. **GitHub Repository**: Fork or clone this repository
9+
3. **Python 3.11+**: For local testing and development
10+
11+
## Step 1: Fork the Repository
12+
13+
1. Click the "Fork" button at the top-right of this repository
14+
2. Clone your forked repository locally:
15+
```bash
16+
git clone https://github.com/SentinelOps-CI/morph-lean-ci
17+
cd morph-lean-ci
18+
```
19+
20+
## Step 2: Set Up Morph Cloud API Key
21+
22+
1. Go to [cloud.morph.so](https://cloud.morph.so) and sign in
23+
2. Navigate to your account settings
24+
3. Generate an API key
25+
4. Copy the API key
26+
27+
## Step 3: Configure GitHub Secrets
28+
29+
1. Go to your forked repository on GitHub
30+
2. Navigate to Settings → Secrets and variables → Actions
31+
3. Click "New repository secret"
32+
4. Name: `MORPH_API_KEY`
33+
5. Value: Paste your Morph Cloud API key
34+
6. Click "Add secret"
35+
36+
## Step 4: Test Local Setup (Optional)
37+
38+
1. Install dependencies:
39+
```bash
40+
pip install -r requirements.txt
41+
```
42+
43+
2. Set your API key:
44+
```bash
45+
export MORPH_API_KEY="your_api_key_here"
46+
```
47+
48+
3. Test the setup:
49+
```bash
50+
python scripts/test_setup.py
51+
```
52+
53+
## Step 5: Trigger the CI Pipeline
54+
55+
1. Go to the "Actions" tab in your repository
56+
2. Select the "Lean 4 CI on Morph Cloud" workflow
57+
3. Click "Run workflow"
58+
4. Choose the number of shards (4 or 8)
59+
5. Click "Run workflow"
60+
61+
## Step 6: Monitor and Debug
62+
63+
### Viewing Results
64+
- Check the Actions tab for workflow progress
65+
- Download artifacts to see logs and test results
66+
- View the summary for performance metrics
67+
68+
### Debugging Failures
69+
When a shard fails, the logs will contain a snapshot ID. You can debug it:
70+
71+
```bash
72+
# Start an instance from the failure snapshot
73+
morphcloud instance start <snapshot-id>
74+
75+
# SSH into the instance
76+
morphcloud instance ssh <instance-id>
77+
78+
# Investigate the failure
79+
cd repo
80+
lake build
81+
lake test
82+
```
83+
84+
## Configuration Options
85+
86+
### Modifying Shard Count
87+
Edit `.github/workflows/lean-ci.yml`:
88+
```yaml
89+
matrix:
90+
shard: ${{ fromJson(format('[0,1,2,3,4,5,6,7]')) }}
91+
shards: ${{ fromJson(format('[{0}]', github.event.inputs.shards || '4')) }}
92+
```
93+
94+
### Resource Allocation
95+
Modify `scripts/build_snapshot.py`:
96+
```python
97+
base_snapshot = client.snapshots.create(
98+
image_id="morphvm-minimal",
99+
vcpus=4, # Adjust CPU cores
100+
memory=8192, # Adjust memory (MB)
101+
disk_size=32768 # Adjust disk size (MB)
102+
)
103+
```
104+
105+
### Timeout Settings
106+
Modify `scripts/run_shard.py`:
107+
```python
108+
instance = client.instances.start(
109+
snapshot_id=snapshot_id,
110+
name=f"lean-ci-shard-{args.shard}",
111+
ttl=3600 # Adjust TTL (seconds)
112+
)
113+
```
114+
115+
## Performance Optimization
116+
117+
### Caching Strategy
118+
- The base snapshot includes pre-warmed mathlib cache
119+
- Each shard runs from the same cached snapshot
120+
- Failed shards create new snapshots for instant repro
121+
122+
### Scaling Considerations
123+
- Start with 4 shards for testing
124+
- Scale to 8 shards for larger projects
125+
- Monitor Morph Cloud usage and costs
126+
127+
## Troubleshooting
128+
129+
### Common Issues
130+
131+
1. **API Key Error**
132+
- Verify `MORPH_API_KEY` is set in GitHub secrets
133+
- Check API key permissions in Morph Cloud
134+
135+
2. **Snapshot Creation Fails**
136+
- Verify Morph Cloud account has sufficient credits
137+
- Check image availability (`morphvm-minimal`)
138+
139+
3. **Lean Installation Fails**
140+
- Check network connectivity in Morph Cloud
141+
- Verify Lean 4 setup script is accessible
142+
143+
4. **Test Failures**
144+
- Check Lean syntax in your examples
145+
- Verify mathlib dependencies are correct
146+
147+
### Getting Help
148+
149+
- Check Morph Cloud documentation: [docs.morph.so](https://docs.morph.so)
150+
- Review Morph Python SDK: [github.com/morph-labs/morph-python-sdk](https://github.com/morph-labs/morph-python-sdk)
151+
- Open issues in this repository for CI-specific problems
152+
153+
## Next Steps
154+
155+
1. **Customize Examples**: Replace `examples/hello-lean` with your own Lean project
156+
2. **Add Tests**: Create more comprehensive test suites
157+
3. **Optimize Caching**: Add more sophisticated caching strategies
158+
4. **Monitor Performance**: Track build times and optimize resource allocation
159+
160+
## Support
161+
162+
For issues with:
163+
- **Morph Cloud**: Contact [email protected]
164+
- **Lean 4**: Check [leanprover-community.github.io](https://leanprover-community.github.io)
165+
- **CI Pipeline**: Open an issue in this repository

0 commit comments

Comments
 (0)