Skip to content

Commit

Permalink
Merge pull request #28 from meta-automata-nix/master
Browse files Browse the repository at this point in the history
Add nix...y things
  • Loading branch information
ar4s-gh authored Jul 15, 2024
2 parents 9a678a1 + 319e6b5 commit fdf406c
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 1 deletion.
116 changes: 116 additions & 0 deletions .github/ISSUE_TEMPLATE/sweep-build-a-py-bi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Sweep Issue -- Build with Python
title: 'Sweep: Build-a-py-binary'
description: For small bugs, features, refactors, and tests to be handled by Sweep, an AI-powered junior developer.
labels: sweep
body:
- type: textarea
id: description
attributes:
label: Details
description: "[url.to/owner/project-repo-name.git] <- should be the only description"
placeholder: |
"Build-a-py-binary: Take a git repo URL that is python based and then
Step 1: Create a new script /examples/build-a-py-binary/[project-name].sh based on the below.
Step 2: Replace the environmental variables in the script based on the issue's description/url
Step 3: (conditional) Retrieve the projects README.md to:
a) add/modify/remove logic in the script
b) scan the code repository and create a README.md that sets up the environment for pyinstaller.
Step 4: Build-a-py-binary!
```
#!/bin/bash
# Exit immediately if a command exits with a non-zero status,
# and ensure that any command in a pipeline failing causes the pipeline to fail.
# Print each command before executing it.
set -e -x -o pipefail
# Variables
REPO_URL="https://url.to/owner/project-name.git"
REPO_DIR="project-name"
VENV_DIR="$REPO_DIR/venv"
UPLOADS_DIR="$REPO_DIR/uploads"
# Function to display messages
function message() {
echo "==> $1"
}
# Function to create aliases for python3 and pip3
function create_aliases() {
message "Creating aliases for python3 and pip3..."
alias python=python3
alias pip=pip3
}
# Ensure we are using the correct Python version
message "Ensuring correct Python version..."
create_aliases
# Clone the repository
message "Cloning the repository from $REPO_URL..."
git clone $REPO_URL
# Navigate into the repository directory
cd $REPO_DIR
# Set up a virtual environment
message "Setting up a virtual environment..."
python -m venv $VENV_DIR
# Activate the virtual environment
message "Activating the virtual environment..."
source $VENV_DIR/bin/activate
# Upgrade pip
message "Upgrading pip..."
pip install --upgrade pip
# Install the required dependencies
message "Installing the required dependencies..."
pip install -r requirements.txt
# Install PyInstaller
message "Installing PyInstaller..."
pip install pyinstaller
# Build the binary using PyInstaller
# Assuming the main script of the project is named 'main.py'
MAIN_SCRIPT="main.py"
message "Building the binary using PyInstaller..."
pyinstaller --onefile $MAIN_SCRIPT
# The output binary will be in the 'dist' directory
BINARY_PATH="dist/${MAIN_SCRIPT%.py}"
# Calculate the SHA-256 hash of the binary
message "Calculating the SHA-256 hash of the binary..."
SHA256_HASH=$(shasum -a 256 $BINARY_PATH | awk '{print $1}')
# Save the hash to a .txt file
HASH_FILE="${BINARY_PATH}.txt"
echo $SHA256_HASH > $HASH_FILE
# Create uploads directory if it doesn't exist
message "Creating uploads directory..."
mkdir -p $UPLOADS_DIR
# Move the binary and the hash file to the uploads directory
message "Moving the binary and the hash file to the uploads directory..."
mv $BINARY_PATH $UPLOADS_DIR/
mv $HASH_FILE $UPLOADS_DIR/
# Deactivate the virtual environment
message "Deactivating the virtual environment..."
deactivate
message "Build process completed successfully. Files are in the 'uploads' directory."
```
"
- type: input
id: branch
attributes:
label: Branch
description: The branch to work off of (optional)
placeholder: |
main
90 changes: 90 additions & 0 deletions examples/build-gaianet-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e
# Causes a pipeline to return the exit status of the last command in the pipe that failed
set -o pipefail

# Define the base directory for GaiaNet installation (default is $HOME/gaianet)
BASE_DIR=${1:-$HOME/gaianet}

# Function to install the GaiaNet node software stack
install_gaianet_node() {
echo "Installing GaiaNet node software stack..."
# Download and execute the installation script from the official GaiaNet GitHub repository
curl -sSfL 'https://github.com/GaiaNet-AI/gaianet-node/releases/latest/download/install.sh' | bash -s -- --base $BASE_DIR
}

# Function to initialize the GaiaNet node
initialize_gaianet_node() {
echo "Initializing GaiaNet node..."
# Initialize the node, which downloads necessary model and vector database files
$BASE_DIR/gaianet init
}

# Function to start the GaiaNet node
start_gaianet_node() {
echo "Starting GaiaNet node..."
# Start the GaiaNet node
$BASE_DIR/gaianet start
}

# Function to stop the GaiaNet node
stop_gaianet_node() {
echo "Stopping GaiaNet node..."
# Stop the GaiaNet node
$BASE_DIR/gaianet stop
}

# Function to update the configuration of the GaiaNet node
update_gaianet_config() {
local chat_url=$1
local chat_ctx_size=$2
echo "Updating GaiaNet node configuration..."
# Update the chat model URL and context size in the GaiaNet node configuration
$BASE_DIR/gaianet config --chat-url "$chat_url" --chat-ctx-size "$chat_ctx_size"
echo "Reinitializing GaiaNet node after configuration update..."
# Reinitialize the node to apply the updated configuration
$BASE_DIR/gaianet init
}

# Parse command-line arguments for configuration updates
while [[ "$#" -gt 0 ]]; do
case $1 in
# Handle chat model URL update
--chat-url) chat_url="$2"; shift ;;
# Handle chat context size update
--chat-ctx-size) chat_ctx_size="$2"; shift ;;
# Flag to indicate that configuration needs to be updated
--update-config) update_config=true ;;
# Unknown parameter handler
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

# Execute the installation and setup process
install_gaianet_node
initialize_gaianet_node

# Update the configuration if the update-config flag is set
if [ "$update_config" = true ]; then
# Ensure both chat model URL and context size are provided
if [ -z "$chat_url" ] || [ -z "$chat_ctx_size" ]; then
echo "Error: Both --chat-url and --chat-ctx-size must be provided to update the configuration."
exit 1
fi
# Update the GaiaNet node configuration
update_gaianet_config "$chat_url" "$chat_ctx_size"
fi

# Start the GaiaNet node
start_gaianet_node

# Print completion message and instructions to stop the node
echo "GaiaNet node setup complete."
echo "To stop the node, run the following command:"
echo "$BASE_DIR/gaianet stop"

# If you want to update the chat URL and context size during setup, you can run the script with the following options:
# ./setup_gaianet.sh --update-config --chat-url "https://huggingface.co/second-state/Llama-2-13B-Chat-GGUF/resolve/main/Llama-2-13b-chat-hf-Q5_K_M.gguf" --chat-ctx-size 5120
14 changes: 14 additions & 0 deletions examples/curl-noblerom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e -x -o pipefail

# Example by Alex Ellis

curl -s https://checkip.amazonaws.com > ip.txt
curl -L https://1drv.ms/u/s!AqGdTk4hyeaFiLN7YfczXkKMsylQVg?e=s1vO0s -o noblerom.zip

mkdir -p uploads
cp ip.txt ./uploads/
mv noblerom.zip ./uploads/
sha256sum ./uploads/noblerom.zip > SHA256-noblerom.zip.txt
mv SHA256-noblerom.zip.txt ./uploads/
35 changes: 35 additions & 0 deletions examples/install_nix_and_hive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Exit on any error, and set pipefail to catch any errors in pipelines
set -eo pipefail

# Install Nix using the Determinate Nix Installer
echo "Installing Nix..."
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- --daemon

# Ensure the Nix profile script is sourced
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
else
echo "Nix profile script not found. Installation may have failed."
exit 1
fi

# Clone the divnix/hive repository
echo "Cloning divnix/hive repository..."
git clone https://github.com/divnix/hive.git
cd hive

# Check for presence of flake.nix configuration file
if [ -f flake.nix ]; then
# Build the environment using Nix flakes
echo "Building the environment..."
nix build .# --no-link

# Run the built environment
echo "Running the environment..."
nix run .#defaultPackage
else
echo "flake.nix not found in the repository. Please ensure the repository contains a flake.nix file."
exit 1
fi
9 changes: 9 additions & 0 deletions examples/wget-warpsetupscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e -x -o pipefail

wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh
bash menu.sh [option] [lisence/url/token]

mkdir -p uploads
cp *.txt ./uploads/
5 changes: 4 additions & 1 deletion sweep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

# This setting contains a list of rules that Sweep will check for. If any of these rules are broken in a new commit, Sweep will create an pull request to fix the broken rule.
rules:
- "Each example script in /examples should have a corresponding manual GitHub action created in .github/workflows/example-sh.yml"
- "All new business logic should have corresponding unit tests."
- "Refactor large functions to be more modular."
- "Add docstrings to all functions and file headers."
- "Add and use fabric (https://github.com/danielmiessler/fabric) as a library for this repository"
- "Commend all of your code like -> https://github.com/divnix/std"

# This is the branch that Sweep will develop from and make pull requests to. Most people use 'main' or 'master' but some users also use 'dev' or 'staging'.
branch: 'main'
Expand All @@ -18,7 +21,7 @@ gha_enabled: True
# Example:
#
# description: sweepai/sweep is a python project. The main api endpoints are in sweepai/api.py. Write code that adheres to PEP8.
description: ''
description: 'This project is an "agentic fork" of https://github.com/alexellis/actions-batch with manual github actions that run the scripts found in /examples. It can be used to create new scripts [sweep ai](https://sweep.dev) via Github Issue's'

# This sets whether to create pull requests as drafts. If this is set to True, then all pull requests will be created as drafts and GitHub Actions will not be triggered.
draft: False
Expand Down
13 changes: 13 additions & 0 deletions templates/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,45 @@ import (
"text/template"
)

// Render executes the workflow template with the provided parameters and returns the rendered output.
func Render(p RenderParams) (string, error) {

// Check if the template file exists at ./templates/workflow.yaml, falling back to ./workflow.yaml if not found.
tmplPath := "./templates/workflow.yaml"
if _, err := os.Stat(tmplPath); err != nil && os.IsNotExist(err) {
tmplPath = "./workflow.yaml"
}

// Parse the template file into a *template.Template object. Panic if parsing fails.
tmpl := template.Must(template.ParseFiles(tmplPath))
workflowT, err := tmpl.ParseFiles(tmplPath)
if err != nil {
log.Panicf("failed to parse workflow template: %s", err)
}

// Create a new buffer to hold the rendered template output.
buf := bytes.NewBuffer(nil)

// Execute the template with the provided RenderParams, writing the result to the buffer.
// Panic if template execution fails.
if err := workflowT.Execute(buf, p); err != nil {
log.Panicf("failed to execute workflow template: %s", err)
}

// Return the rendered template output as a string.
return buf.String(), nil
}

// RenderParams contains the data used to populate the workflow template.
type RenderParams struct {
// Name is the name of the workflow.
Name string
// Login is the GitHub user or organization that owns the repository.
Login string
// Date is the date the workflow is being generated.
Date string
// RunsOn specifies the environment the workflow should run on.
RunsOn string
// Secrets contains any secrets that need to be passed to the workflow.
Secrets map[string]string
}

0 comments on commit fdf406c

Please sign in to comment.