major changes

- Added documentation via mdbook
- Created basic VS code extension
- Implemented if else blocks and changed some syntax
- fixed some issues
This commit is contained in:
2025-11-02 19:56:26 +01:00
parent 78959d4f22
commit af0a1632c0
40 changed files with 14014 additions and 177 deletions

View File

@@ -0,0 +1,65 @@
# CI/CD Pipeline
> ⚠️ This documentation is AI-generated and may contain errors.
Continuous Integration/Deployment pipeline with parallel testing.
## Script
See `/examples/ci_pipeline.rsh` in the repository.
```rush
#!/usr/bin/env rush
PROJECT = "my-rust-app"
BRANCH = "main"
BUILD_ID = "build-12345"
echo "=== CI/CD Pipeline ==="
echo "Project: $PROJECT"
# Environment validation
if $IS_ROOT {
echo "ERROR: Do not run CI/CD pipeline as root"
exit 1
}
# Build stages (sequential)
for stage in checkout lint test build package {
echo "[$BUILD_ID] Stage: $stage"
if $stage {
echo "[$BUILD_ID] ✓ $stage completed"
}
}
# Run tests in parallel
parallel {
run {
echo "[unit-tests] Running unit tests..."
echo "[unit-tests] 127 tests passed"
}
run {
echo "[integration-tests] Running integration tests..."
echo "[integration-tests] 45 tests passed"
}
run {
echo "[lint-check] Running cargo clippy..."
echo "[lint-check] No warnings found"
}
}
# Multi-environment deployment
for env in dev staging prod {
DEPLOY_URL = "https://$PROJECT.$env.example.com"
echo "[$env] Deployment target: $DEPLOY_URL"
}
```
## Key Concepts
- **Security check**: Refuse to run as root
- **Sequential build**: Steps that depend on each other
- **Parallel tests**: Independent test suites run simultaneously
- **Multi-environment deployment**: Same code deployed to different environments

View File

@@ -0,0 +1,52 @@
# Data Pipeline
> ⚠️ This documentation is AI-generated and may contain errors.
Data processing pipeline showing how to process multiple batches in parallel.
## Script
See `/examples/data_pipeline.rsh` in the repository.
```rush
#!/usr/bin/env rush
DATASET = "user_analytics"
INPUT_DIR = "$HOME/data/raw"
OUTPUT_DIR = "$HOME/data/processed"
BATCH_SIZE = "1000"
echo "Data Processing Pipeline: $DATASET"
# Pre-processing stages
for stage in validate clean normalize {
STAGE_UPPER = "$stage"
echo " Stage: $STAGE_UPPER"
}
# Process batches in parallel
BATCH_1_IN = "$INPUT_DIR/batch_001.csv"
BATCH_1_OUT = "$OUTPUT_DIR/batch_001.json"
# ... (define other batches)
parallel {
run {
echo "[batch_001] Processing $BATCH_1_IN -> $BATCH_1_OUT"
echo "[batch_001] Transformed 1000 records"
}
run {
echo "[batch_002] Processing $BATCH_2_IN -> $BATCH_2_OUT"
echo "[batch_002] Transformed 1000 records"
}
# ... (more batches)
}
echo "All batches processed successfully"
```
## Key Concepts
- **Parallel data processing**: Process multiple batches simultaneously
- **Path construction**: Building input/output file paths
- **Pipeline stages**: Sequential setup, parallel processing, sequential summary

View File

@@ -0,0 +1,72 @@
# Database Backup
> ⚠️ This documentation is AI-generated and may contain errors.
Database backup automation with validation and integrity checks.
## Script
See `/examples/db_backup.rsh` in the repository.
```rush
#!/usr/bin/env rush
DB_NAME = "production_db"
DB_HOST = "db.example.com"
BACKUP_ROOT = "/backups/databases"
BACKUP_PATH = "$BACKUP_ROOT/$DB_NAME"
TIMESTAMP = "2024-01-15-143022"
BACKUP_FILE = "$BACKUP_PATH/backup-$TIMESTAMP.sql.gz"
echo "Database Backup Script"
# Permission check
if not $IS_ROOT {
echo "Warning: Running as $USER (not root)"
echo "Ensure $USER has database access"
}
# Pre-backup validation
for check in connectivity disk_space permissions {
echo " Checking $check..."
if $check {
echo " ✓ $check OK"
}
}
# Backup stages
for stage in dump compress encrypt verify {
STAGE_FILE = "$BACKUP_PATH/$stage.tmp"
echo "[$stage] Processing..."
if $stage {
echo "[$stage] ✓ Complete"
}
}
# Parallel integrity verification
parallel {
run {
echo "[checksum] Computing SHA256..."
echo "[checksum] a1b2c3d4e5f6..."
}
run {
echo "[compression] Verifying gzip integrity..."
echo "[compression] OK"
}
run {
echo "[restore-test] Testing restore on sample..."
echo "[restore-test] Restore successful"
}
}
echo "Backup completed successfully!"
```
## Key Concepts
- **Pre-flight validation**: Check prerequisites before starting
- **Multi-stage processing**: Sequential backup pipeline
- **Parallel verification**: Simultaneously verify different aspects
- **Comprehensive reporting**: Clear status messages throughout

View File

@@ -0,0 +1,51 @@
# System Maintenance
> ⚠️ This documentation is AI-generated and may contain errors.
Example system maintenance script demonstrating permission checks, environment variables, and log rotation.
## Script
See the full script in `/examples/system_maintenance.rsh` in the repository.
```rush
#!/usr/bin/env rush
HOSTNAME = "prod-server-01"
MAX_DISK_USAGE = "85"
LOG_DIR = "/var/log"
BACKUP_DIR = "$HOME/backups"
echo "System Maintenance Script"
echo "Running on: $HOSTNAME"
echo "User: $USER"
# Permission-aware execution
if $IS_ROOT {
echo "Running with root privileges"
for check in disk memory services {
echo "Checking $check status..."
if $check {
echo " ✓ $check is healthy"
}
}
} else {
echo "Running as $USER (limited permissions)"
echo "Some checks may be skipped"
}
# Log rotation planning
echo "Preparing log rotation in $LOG_DIR"
for days in 1 7 30 {
LOG_ARCHIVE = "$BACKUP_DIR/logs-$days-days-old.tar.gz"
echo "Would archive logs older than $days days to $LOG_ARCHIVE"
}
```
## Key Concepts
- **Permission-aware execution**: Different behavior for root vs normal user
- **String interpolation**: Building paths with `$HOME`, `$USER`
- **Loops for maintenance tasks**: Iterating over checks and retention periods

View File

@@ -0,0 +1,184 @@
# Web Deployment
> ⚠️ This documentation is AI-generated and may contain errors.
This example demonstrates a web application deployment pipeline using Rush's parallel execution capabilities.
## Full Script
```rush
#!/usr/bin/env rush
# Web deployment pipeline example
# Shows conditional logic, loops, and parallel execution
APP_NAME = "my-app"
VERSION = "1.2.3"
ENV = "staging"
DEPLOY_DIR = "/var/www/$APP_NAME"
BUILD_DIR = "./dist"
echo "Starting deployment for $APP_NAME v$VERSION to $ENV"
# Check prerequisites
if not $IS_ROOT {
echo "Warning: Not running as root. Some operations may fail."
}
# Build steps
STEPS = "lint test build"
for step in lint test build {
echo "[$step] Running..."
if $step {
# Simulate the build step
echo "[$step] Complete"
}
}
# Deploy in parallel
echo "Deploying to multiple servers..."
parallel {
run {
echo "Server 1: Syncing files to web-1.$ENV.example.com"
echo "Server 1: Deployment complete"
}
run {
echo "Server 2: Syncing files to web-2.$ENV.example.com"
echo "Server 2: Deployment complete"
}
run {
echo "Server 3: Syncing files to web-3.$ENV.example.com"
echo "Server 3: Deployment complete"
}
}
echo "All servers updated with $APP_NAME v$VERSION"
# Post-deployment checks
for server in web-1 web-2 web-3 {
FULL_HOST = "$server.$ENV.example.com"
echo "Health check: $FULL_HOST - OK"
}
echo "Deployment complete!"
```
## Features Demonstrated
### 1. Configuration Variables
The script starts by defining configuration:
```rush
APP_NAME = "my-app"
VERSION = "1.2.3"
ENV = "staging"
DEPLOY_DIR = "/var/www/$APP_NAME"
```
These variables are used throughout the script, making it easy to adapt for different applications.
### 2. Permission Check
```rush
if not $IS_ROOT {
echo "Warning: Not running as root. Some operations may fail."
}
```
The script warns if not running as root, but continues anyway (since deployment might work without root depending on file permissions).
### 3. Sequential Build Steps
```rush
for step in lint test build {
echo "[$step] Running..."
if $step {
echo "[$step] Complete"
}
}
```
Build steps run sequentially since each step depends on the previous one completing successfully.
### 4. Parallel Server Deployment
```rush
parallel {
run {
echo "Server 1: Syncing files to web-1.$ENV.example.com"
echo "Server 1: Deployment complete"
}
run {
echo "Server 2: Syncing files to web-2.$ENV.example.com"
echo "Server 2: Deployment complete"
}
run {
echo "Server 3: Syncing files to web-3.$ENV.example.com"
echo "Server 3: Deployment complete"
}
}
```
Servers are updated in parallel since they're independent. This saves significant time vs deploying sequentially.
### 5. Post-Deployment Verification
```rush
for server in web-1 web-2 web-3 {
FULL_HOST = "$server.$ENV.example.com"
echo "Health check: $FULL_HOST - OK"
}
```
After deployment, verify each server is healthy.
## Example Output
```
Starting deployment for my-app v1.2.3 to staging
Warning: Not running as root. Some operations may fail.
[lint] Running...
[lint] Complete
[test] Running...
[test] Complete
[build] Running...
[build] Complete
Deploying to multiple servers...
Server 1: Syncing files to web-1.staging.example.com
Server 2: Syncing files to web-2.staging.example.com
Server 3: Syncing files to web-3.staging.example.com
Server 1: Deployment complete
Server 2: Deployment complete
Server 3: Deployment complete
All servers updated with my-app v1.2.3
Health check: web-1.staging.example.com - OK
Health check: web-2.staging.example.com - OK
Health check: web-3.staging.example.com - OK
Deployment complete!
```
Note: Output from parallel tasks may be interleaved.
## Adapting for Your Use
To use this for real deployments:
1. **Change configuration variables** to match your app
2. **Replace echo with actual commands** (rsync, scp, etc.)
3. **Add error handling** (check command exit codes)
4. **Customize server list** for your infrastructure
5. **Add real health checks** (curl, wget, etc.)
## Related
- [Parallel Execution](../language/parallel.md) - Learn more about parallel blocks
- [Loops](../language/loops.md) - Sequential iteration patterns
- [Variables](../language/variables.md) - Working with configuration