Skip to content

Commit

Permalink
Merge pull request #82 from ssotops/feat/integrate-hello-world-plugin
Browse files Browse the repository at this point in the history
feat/integrate hello world plugin
  • Loading branch information
alechp authored Sep 23, 2024
2 parents 3470c39 + c251ac2 commit c8f5a88
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 451 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore

.repositories/gitspace/gs/*
cmd/cmd
archive-*
.DS_Store
Expand Down
283 changes: 93 additions & 190 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,226 +2,129 @@

set -e

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Function to prompt for installation
prompt_install() {
read -p "Would you like to install $1? (y/n) " choice
case "$choice" in
y|Y ) return 0;;
n|N ) return 1;;
* ) echo "Invalid input. Please enter y or n."; prompt_install "$1";;
esac
}

# Function to install gum
install_gum() {
echo "Installing gum..."
if [[ "$OSTYPE" == "darwin"* ]]; then
if command_exists "brew"; then
brew install gum
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "For Ubuntu/Debian:"
echo "sudo mkdir -p /etc/apt/keyrings"
echo "curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg"
echo 'echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list'
echo "sudo apt update && sudo apt install gum"
echo ""
echo "For other Linux distributions, please visit: https://github.com/charmbracelet/gum#installation"
read -p "Do you want to proceed with the installation for Ubuntu/Debian? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum
else
echo "Please install gum manually and run this script again."
exit 1
fi
else
echo "Unsupported operating system. Please install gum manually:"
echo "https://github.com/charmbracelet/gum#installation"
exit 1
fi
}

# Function to install jq
install_jq() {
echo "Installing jq..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install jq
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get update && sudo apt-get install -y jq
elif command_exists "apt-get"; then
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum
else
echo "Unsupported operating system. Please install jq manually:"
echo "https://stedolan.github.io/jq/download/"
echo "Unable to install gum. Please install it manually: https://github.com/charmbracelet/gum#installation"
exit 1
fi
}

# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is not installed."
read -p "Do you want to install jq? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_jq
else
echo "Please install jq manually and run this script again."
exit 1
fi
fi

# Check if gum is installed
if ! command -v gum &> /dev/null; then
# Check and install gum if necessary
if ! command_exists gum; then
echo "gum is not installed."
read -p "Do you want to install gum? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if prompt_install "gum"; then
install_gum
else
echo "Please install gum manually and run this script again."
echo "gum is required for this script. Exiting."
exit 1
fi
fi

# Function to update gitspace-plugin version for main project
update_gitspace_plugin() {
local dir=$1
cd "$dir"

# Force-download the latest version
latest_version=$(curl -s https://api.github.com/repos/ssotops/gitspace-plugin/releases/latest | jq -r .tag_name)

# Function to print styled header
print_header() {
gum style \
--foreground 208 --border-foreground 208 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Updating gitspace-plugin to version: $latest_version in $dir"

go get -u "github.com/ssotops/gitspace-plugin@$latest_version"
go mod tidy
cd -
--foreground 212 --border-foreground 212 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
'Gitspace Builder'
}

# Function to update gitspace-plugin version for plugins
update_plugin_gitspace_plugin() {
local dir=$1
local version=$2
cd "$dir"

gum style \
--foreground 208 --border-foreground 208 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Updating gitspace-plugin to version: $version in $dir"

# Update go.mod file if it exists
if [ -f "go.mod" ]; then
sed -i '' "s|github.com/ssotops/gitspace-plugin v.*|github.com/ssotops/gitspace-plugin $version|g" go.mod
go mod tidy
else
echo "No go.mod file found in $dir. Skipping update."
fi
cd -
# Function to print styled log message
log() {
gum style --foreground 39 "$(gum style --bold "")" "$1"
}

# ASCII Art for gitspace builder using gum
gum style \
--foreground 212 --border-foreground 212 --border double \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Gitspace Builder"

# Function to update Charm library versions
update_charm_versions() {
local dir=$1
cd "$dir"
go get github.com/charmbracelet/huh@latest
go get github.com/charmbracelet/log@latest
go mod tidy
cd -
# Function to print styled success message
success() {
gum style --foreground 76 "$(gum style --bold "")" "$1"
}

# Update main application
update_charm_versions .
update_gitspace_plugin .

# Force update gitspace-plugin to the latest version in main project
gum spin --spinner dot --title "Updating gitspace-plugin in main project..." -- bash -c '
go get -u github.com/ssotops/gitspace-plugin@latest
go mod tidy
'
# Function to print styled error message
error() {
gum style --foreground 196 "$(gum style --bold "")" "$1" >&2
}

# Ensure we're using the latest version
latest_version=$(go list -m -json github.com/ssotops/gitspace-plugin | jq -r .Version)
current_version=$(grep "github.com/ssotops/gitspace-plugin" go.mod | awk '{print $2}')
# Print header
print_header

# Initialize variables to track changes
changes=()

# Update dependencies
log "Updating dependencies..."
go get -u ./...
if [ $? -eq 0 ]; then
success "Dependencies updated successfully."
changes+=("Dependencies updated")
else
error "Failed to update dependencies."
exit 1
fi

if [ "$latest_version" != "$current_version" ]; then
gum style \
--foreground 208 --border-foreground 208 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Warning: gitspace-plugin version mismatch detected.
Current: $current_version
Latest: $latest_version
Forcing update to the latest version..."

go get -u github.com/ssotops/gitspace-plugin@$latest_version
go mod tidy
# Tidy up the go.mod file
log "Tidying up go.mod..."
go mod tidy
if [ $? -eq 0 ]; then
success "go.mod tidied successfully."
changes+=("go.mod tidied")
else
error "Failed to tidy go.mod."
exit 1
fi

gum style \
--foreground 82 --border-foreground 82 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Using gitspace-plugin version: $latest_version"

# Update plugins
plugins_dir="$HOME/.ssot/gitspace/plugins"
for plugin_dir in "$plugins_dir"/*; do
if [ -d "$plugin_dir" ]; then
update_plugin_gitspace_plugin "$plugin_dir" "$latest_version"
fi
done
# Build the project
log "Building the project..."
go build -o gitspace .
if [ $? -eq 0 ]; then
success "Project built successfully."
changes+=("Project built")
else
error "Failed to build the project."
exit 1
fi

# Build main Gitspace application
gum spin --spinner dot --title "Building Gitspace main application..." -- sleep 2
CGO_ENABLED=1 go build -tags pluginload -buildmode=pie -o gitspace .

# Rebuild plugins
for plugin_dir in "$plugins_dir"/*; do
if [ -d "$plugin_dir" ]; then
plugin_name=$(basename "$plugin_dir")
gum spin --spinner dot --title "Rebuilding plugin: $plugin_name" -- bash -c "
cd '$plugin_dir'
go build -buildmode=plugin -o ${plugin_name}.so .
"
fi
done
# Run tests
log "Running tests..."
go test ./...
if [ $? -eq 0 ]; then
success "All tests passed."
changes+=("Tests passed")
else
error "Some tests failed."
exit 1
fi

# Verify versions
main_version=$(grep "github.com/ssotops/gitspace-plugin" go.mod | awk '{print $2}')
# Print summary
gum style \
--foreground 82 --border-foreground 82 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Main Gitspace using gitspace-plugin version: $main_version"

echo "Plugin versions:"
for plugin_dir in "$plugins_dir"/*; do
if [ -d "$plugin_dir" ]; then
plugin_name=$(basename "$plugin_dir")
plugin_version=$(grep "github.com/ssotops/gitspace-plugin" "$plugin_dir/go.mod" | awk '{print $2}')
echo " $plugin_name: $plugin_version"
fi
done
--foreground 226 --border-foreground 226 --border normal \
--align left --width 50 --margin "1 2" --padding "1 2" \
"Summary of Changes:"

# Print installed local plugins
echo "Currently installed local plugins:"
for plugin in ~/.ssot/gitspace/plugins/*.so; do
if [ -f "$plugin" ]; then
plugin_name=$(basename "$plugin" .so)
gum style \
--foreground 39 --border-foreground 39 --border normal \
--align left --width 50 --margin "0 2" --padding "0 1" \
"🔌 $plugin_name"
fi
for change in "${changes[@]}"; do
gum style --foreground 226 "$change"
done

# Print tree structure of plugins directory
tree_output=$(tree -L 2 ~/.ssot/gitspace/plugins)
gum style \
--foreground 226 --border-foreground 226 --border double \
--align left --width 70 --margin "1 2" --padding "1 2" \
"Local Plugins Directory Structure:
$tree_output"

# Inform about remote plugins and potential updates to gitspace-catalog
gum style \
--foreground 214 --border-foreground 214 --border normal \
--align center --width 70 --margin "1 2" --padding "1 2" \
"Note: Remote plugins like 'templater' are managed through the Gitspace Catalog. If there were version updates, a new branch may have been created in the gitspace-catalog repository. Please check and create a pull request if necessary."
success "Build process completed successfully!"
14 changes: 6 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.3
github.com/ssotops/gitspace-plugin-sdk v0.0.0-00010101000000-000000000000
golang.org/x/oauth2 v0.22.0
golang.org/x/oauth2 v0.23.0
google.golang.org/protobuf v1.34.2
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240919170804-a4978c8e603a // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/cloudflare/circl v1.4.0 // indirect
github.com/cyphar/filepath-securejoin v0.3.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
Expand All @@ -52,16 +52,14 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading

0 comments on commit c8f5a88

Please sign in to comment.