Skip to content

amitwinit/Multiplex-CICD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET Auto Deploy Script

A Python script that automatically downloads C# .NET projects from GitHub and restarts the server whenever changes are detected in the repository.

Features

  • GitHub Integration: Downloads repositories using GitHub API with personal access tokens
  • Change Detection: Monitors repository changes using file hashing
  • Auto Restart: Automatically restarts .NET server when changes are detected
  • No Git Required: Works without Git CLI or system Git configuration
  • Comprehensive Logging: Detailed logging to both file and console
  • Error Handling: Robust error handling and recovery
  • Configurable: Easy configuration via JSON file

Prerequisites

  1. Python 3.7+ installed on your system
  2. .NET SDK installed and accessible via dotnet command
  3. GitHub Personal Access Token with appropriate permissions

Installation

  1. Clone or download this repository
  2. Install Python dependencies:
    pip install -r requirements.txt

Setup

1. Generate GitHub Personal Access Token

  1. Go to GitHub Developer Settings → Tokens
  2. Click "Generate new token (classic)"
  3. Select the following scopes:
    • repo (for private repositories) or public_repo (for public repositories)
  4. Copy the generated token

2. Create Configuration File

Run the script with the --create-config flag to generate a sample configuration:

python dotnet_auto_deploy.py --create-config

This will create a config.json file. Edit it with your specific details:

{
  "github_user": "your-username",
  "repo_name": "your-repo-name",
  "branch": "main",
  "token": "ghp_your_github_token_here",
  "extract_path": "./repo",
  "dotnet_project_path": "src/YourProject",
  "check_interval": 60
}

Configuration Options

Field Description Required Default
github_user Your GitHub username -
repo_name Repository name -
branch Branch to monitor main
token GitHub personal access token -
extract_path Local path to extract repository -
dotnet_project_path Path to .NET project within repo -
check_interval Check interval in seconds 60

Usage

Basic Usage

python dotnet_auto_deploy.py

Custom Configuration File

python dotnet_auto_deploy.py --config my-config.json

Create Sample Configuration

python dotnet_auto_deploy.py --create-config

How It Works

  1. Repository Download: The script downloads the repository as a ZIP file using GitHub's API
  2. Change Detection: Generates SHA256 hashes of the repository contents to detect changes
  3. Auto Restart: When changes are detected, the script:
    • Stops the existing .NET process (if running)
    • Builds the project using dotnet build
    • Starts the application using dotnet run
  4. Monitoring: Continuously monitors the repository at the specified interval

Example Workflow

  1. Initial Setup:

    # Create sample config
    python dotnet_auto_deploy.py --create-config
    
    # Edit config.json with your details
    # Run the script
    python dotnet_auto_deploy.py
  2. Development Workflow:

    • Make changes to your .NET project
    • Push changes to GitHub
    • The script automatically detects changes and restarts the server

Logging

The script creates detailed logs in:

  • Console: Real-time output
  • File: dotnet_auto_deploy.log (in the same directory)

Log levels include:

  • INFO: General information and status updates
  • WARNING: Non-critical issues
  • ERROR: Critical errors that may affect operation

Troubleshooting

Common Issues

  1. "Download failed" error:

    • Check your GitHub token has the correct permissions
    • Verify the repository name and username are correct
    • Ensure the repository exists and is accessible
  2. ".NET project path does not exist" error:

    • Verify the dotnet_project_path in your config points to the correct directory
    • Check that the path is relative to the extracted repository root
  3. "Build failed" error:

    • Ensure .NET SDK is installed and accessible
    • Check the project has all required dependencies
    • Review the build output in the logs
  4. Permission errors:

    • Ensure the script has write permissions to the extract path
    • Check that .NET can access the project directory

Debug Mode

To enable debug logging, modify the logging level in the script:

logging.basicConfig(
    level=logging.DEBUG,  # Change from INFO to DEBUG
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler('dotnet_auto_deploy.log'),
        logging.StreamHandler(sys.stdout)
    ]
)

Security Considerations

  • Token Security: Keep your GitHub token secure and don't commit it to version control
  • File Permissions: Ensure the script runs with appropriate permissions
  • Network Security: The script downloads from GitHub over HTTPS

Contributing

Feel free to submit issues, feature requests, or pull requests to improve this script.

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors