Compare commits
4 Commits
v2025.0719
...
v2025.0720
Author | SHA1 | Date | |
---|---|---|---|
bfeaf4d0db | |||
6a3ca6bc10 | |||
7f8312ed59 | |||
1b03087c02 |
@ -189,4 +189,19 @@ When creating tools for getpkg:
|
|||||||
3. The tool should support `version` and `autocomplete` subcommands
|
3. The tool should support `version` and `autocomplete` subcommands
|
||||||
4. Use `getpkg publish` to upload to the registry
|
4. Use `getpkg publish` to upload to the registry
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
The test script creates all temporary files and directories in `test_temp/` to keep the main directory clean:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run tests
|
||||||
|
./test.sh
|
||||||
|
|
||||||
|
# Clean up orphaned test files from old test runs (one-time)
|
||||||
|
bash cleanup_old_test_files.sh
|
||||||
|
|
||||||
|
# Clean up orphaned test packages from getpkg.xyz
|
||||||
|
bash cleanup_test_packages.sh
|
||||||
|
```
|
||||||
|
|
||||||
For more details, see the development documentation in each tool's directory.
|
For more details, see the development documentation in each tool's directory.
|
||||||
|
98
getpkg/cleanup_test_packages.sh
Executable file
98
getpkg/cleanup_test_packages.sh
Executable file
@ -0,0 +1,98 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Cleanup script for orphaned test packages from getpkg testing
|
||||||
|
# This script removes test packages that start with "test-" from getpkg.xyz
|
||||||
|
# Run from the getpkg directory: bash cleanup_test_packages.sh
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
GETPKG="./output/getpkg"
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Cleaning up orphaned test packages...${NC}"
|
||||||
|
|
||||||
|
# Check if getpkg binary exists
|
||||||
|
if [ ! -f "$GETPKG" ]; then
|
||||||
|
echo -e "${RED}Error: getpkg binary not found at $GETPKG${NC}"
|
||||||
|
echo "Please run ./build.sh first to build getpkg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if SOS_WRITE_TOKEN is set
|
||||||
|
if [ -z "${SOS_WRITE_TOKEN:-}" ]; then
|
||||||
|
echo -e "${RED}Error: SOS_WRITE_TOKEN environment variable is not set${NC}"
|
||||||
|
echo "This token is required to unpublish packages from getpkg.xyz"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using getpkg binary: $GETPKG"
|
||||||
|
echo "SOS_WRITE_TOKEN is set (${#SOS_WRITE_TOKEN} characters)"
|
||||||
|
|
||||||
|
# Get list of all packages from /dir endpoint
|
||||||
|
echo "Fetching package list from getpkg.xyz/dir..."
|
||||||
|
DIR_RESPONSE=$(curl -s "https://getpkg.xyz/dir" 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
if [ -z "$DIR_RESPONSE" ]; then
|
||||||
|
echo -e "${RED}Failed to fetch package list from server${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract test package labeltags from JSON response
|
||||||
|
# Try with jq first, fallback to grep/sed if jq is not available
|
||||||
|
if command -v jq >/dev/null 2>&1; then
|
||||||
|
TEST_PACKAGES=$(echo "$DIR_RESPONSE" | jq -r '.entries[]?.labeltags[]? // empty' 2>/dev/null | grep "^test-" | sort -u || echo "")
|
||||||
|
else
|
||||||
|
# Fallback: extract labeltags using grep and sed (less reliable but works without jq)
|
||||||
|
TEST_PACKAGES=$(echo "$DIR_RESPONSE" | grep -o '"test-[^"]*"' | sed 's/"//g' | sort -u || echo "")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$TEST_PACKAGES" ]; then
|
||||||
|
echo -e "${GREEN}No test packages found to clean up${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Found test packages to clean up:${NC}"
|
||||||
|
echo "$TEST_PACKAGES" | while read -r package; do
|
||||||
|
echo " - $package"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Cleaning up test packages...${NC}"
|
||||||
|
|
||||||
|
CLEANED_COUNT=0
|
||||||
|
FAILED_COUNT=0
|
||||||
|
|
||||||
|
# Use process substitution to avoid subshell issues
|
||||||
|
while IFS= read -r package; do
|
||||||
|
if [ -n "$package" ]; then
|
||||||
|
echo -n "Cleaning up $package... "
|
||||||
|
|
||||||
|
# Try to unpublish the package (temporarily disable set -e)
|
||||||
|
set +e
|
||||||
|
$GETPKG unpublish "$package" >/dev/null 2>&1
|
||||||
|
UNPUBLISH_RESULT=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ $UNPUBLISH_RESULT -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}OK${NC}"
|
||||||
|
((CLEANED_COUNT++))
|
||||||
|
else
|
||||||
|
echo -e "${RED}FAILED${NC}"
|
||||||
|
((FAILED_COUNT++))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done <<< "$TEST_PACKAGES"
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Cleanup Summary:${NC}"
|
||||||
|
echo "Packages cleaned: $CLEANED_COUNT"
|
||||||
|
echo "Failed cleanups: $FAILED_COUNT"
|
||||||
|
|
||||||
|
if [ $FAILED_COUNT -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}All test packages cleaned up successfully!${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}Some packages failed to clean up. They may need manual removal.${NC}"
|
||||||
|
fi
|
@ -1 +0,0 @@
|
|||||||
Debug content
|
|
@ -1 +0,0 @@
|
|||||||
test
|
|
@ -1,7 +0,0 @@
|
|||||||
#\!/bin/bash
|
|
||||||
if [ "$1" = "version" ]; then
|
|
||||||
echo "1.0.0"
|
|
||||||
elif [ "$1" = "autocomplete" ]; then
|
|
||||||
echo "help"
|
|
||||||
echo "version"
|
|
||||||
fi
|
|
@ -1,7 +0,0 @@
|
|||||||
#\!/bin/bash
|
|
||||||
if [ "$1" = "version" ]; then
|
|
||||||
echo "1.0.0"
|
|
||||||
elif [ "$1" = "autocomplete" ]; then
|
|
||||||
echo "help"
|
|
||||||
echo "version"
|
|
||||||
fi
|
|
@ -68,6 +68,28 @@ cleanup() {
|
|||||||
# Clean up noarch variant
|
# Clean up noarch variant
|
||||||
$GETPKG unpublish "${TEST_TOOL_NAME}-noarch:universal" 2>/dev/null || true
|
$GETPKG unpublish "${TEST_TOOL_NAME}-noarch:universal" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Clean up any remaining test packages that start with "test-"
|
||||||
|
echo "Cleaning up any remaining test packages..."
|
||||||
|
DIR_RESPONSE=$(curl -s "https://getpkg.xyz/dir" 2>/dev/null || echo "")
|
||||||
|
if [ -n "$DIR_RESPONSE" ]; then
|
||||||
|
# Extract test package labeltags from JSON response
|
||||||
|
if command -v jq >/dev/null 2>&1; then
|
||||||
|
TEST_PACKAGES=$(echo "$DIR_RESPONSE" | jq -r '.entries[]?.labeltags[]? // empty' 2>/dev/null | grep "^test-" | sort -u || echo "")
|
||||||
|
else
|
||||||
|
# Fallback: extract labeltags using grep and sed
|
||||||
|
TEST_PACKAGES=$(echo "$DIR_RESPONSE" | grep -o '"test-[^"]*"' | sed 's/"//g' | sort -u || echo "")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$TEST_PACKAGES" ]; then
|
||||||
|
echo "$TEST_PACKAGES" | while read -r package; do
|
||||||
|
if [ -n "$package" ]; then
|
||||||
|
echo " Cleaning up orphaned test package: $package"
|
||||||
|
$GETPKG unpublish "$package" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Cleaned up test tools from getpkg.xyz"
|
echo "Cleaned up test tools from getpkg.xyz"
|
||||||
else
|
else
|
||||||
echo "Note: SOS_WRITE_TOKEN not set, cannot clean up remote test objects"
|
echo "Note: SOS_WRITE_TOKEN not set, cannot clean up remote test objects"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#!/bin/bash\necho debug
|
|
@ -1 +0,0 @@
|
|||||||
#!/bin/bash\necho debug2
|
|
@ -1 +0,0 @@
|
|||||||
#!/bin/bash\necho display test
|
|
@ -1 +0,0 @@
|
|||||||
#!/bin/bash\necho multi arch
|
|
@ -1 +0,0 @@
|
|||||||
#!/bin/bash\necho robust test
|
|
@ -1 +0,0 @@
|
|||||||
test content
|
|
187
gp/gp
187
gp/gp
@ -49,27 +49,43 @@ EOF
|
|||||||
|
|
||||||
# Function to generate commit message based on changes
|
# Function to generate commit message based on changes
|
||||||
generate_commit_message() {
|
generate_commit_message() {
|
||||||
local files_changed
|
# First check if we have staged changes
|
||||||
files_changed=$(git diff --cached --name-only)
|
local has_staged_changes=false
|
||||||
local files_count
|
if ! git diff --cached --quiet; then
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
has_staged_changes=true
|
||||||
|
|
||||||
if [ -z "$files_changed" ]; then
|
|
||||||
files_changed=$(git diff --name-only)
|
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If add-all is enabled, also include untracked files
|
# Determine which changes to analyze based on staging status and ADD_ALL setting
|
||||||
if [ "$ADD_ALL" = true ] && [ -z "$files_changed" ]; then
|
local status_command=""
|
||||||
files_changed=$(git ls-files --others --exclude-standard)
|
if [ "$has_staged_changes" = true ]; then
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
status_command="git diff --cached --name-status"
|
||||||
|
else
|
||||||
|
status_command="git diff --name-status"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$files_changed" ]; then
|
# Get all changes (staged or unstaged depending on context)
|
||||||
|
local all_changes
|
||||||
|
all_changes=$($status_command)
|
||||||
|
|
||||||
|
# If no changes from diff, check for untracked files when add-all is enabled
|
||||||
|
if [ -z "$all_changes" ] && [ "$ADD_ALL" = true ]; then
|
||||||
|
local untracked_files
|
||||||
|
untracked_files=$(git ls-files --others --exclude-standard)
|
||||||
|
if [ -n "$untracked_files" ]; then
|
||||||
|
# Convert untracked files to "A" (added) status format
|
||||||
|
all_changes=$(echo "$untracked_files" | sed 's/^/A\t/')
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$all_changes" ]; then
|
||||||
echo "No changes to commit"
|
echo "No changes to commit"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Count total files
|
||||||
|
local files_count
|
||||||
|
files_count=$(echo "$all_changes" | wc -l)
|
||||||
|
|
||||||
# Generate smart commit message based on file types and changes
|
# Generate smart commit message based on file types and changes
|
||||||
local has_source_files=false
|
local has_source_files=false
|
||||||
local has_config_files=false
|
local has_config_files=false
|
||||||
@ -77,7 +93,8 @@ generate_commit_message() {
|
|||||||
local has_tests=false
|
local has_tests=false
|
||||||
local message=""
|
local message=""
|
||||||
|
|
||||||
while IFS= read -r file; do
|
# Extract just the filenames for type detection
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
[ -z "$file" ] && continue
|
[ -z "$file" ] && continue
|
||||||
|
|
||||||
case "$file" in
|
case "$file" in
|
||||||
@ -94,15 +111,18 @@ generate_commit_message() {
|
|||||||
has_tests=true
|
has_tests=true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done <<< "$files_changed"
|
done <<< "$all_changes"
|
||||||
|
|
||||||
# Create descriptive commit message
|
# Create descriptive commit message
|
||||||
if [ "$files_count" -eq 1 ]; then
|
if [ "$files_count" -eq 1 ]; then
|
||||||
|
local change_line
|
||||||
|
change_line=$(echo "$all_changes" | head -1)
|
||||||
|
local status
|
||||||
local single_file
|
local single_file
|
||||||
single_file=$(echo "$files_changed" | head -1)
|
status=$(echo "$change_line" | cut -f1)
|
||||||
local change_type
|
single_file=$(echo "$change_line" | cut -f2)
|
||||||
change_type=$(git diff --cached --name-status -- "$single_file" 2>/dev/null || git diff --name-status -- "$single_file")
|
|
||||||
case "${change_type:0:1}" in
|
case "${status:0:1}" in
|
||||||
A) message="Add $single_file" ;;
|
A) message="Add $single_file" ;;
|
||||||
M) message="Update $single_file" ;;
|
M) message="Update $single_file" ;;
|
||||||
D) message="Remove $single_file" ;;
|
D) message="Remove $single_file" ;;
|
||||||
@ -110,6 +130,58 @@ generate_commit_message() {
|
|||||||
*) message="Modify $single_file" ;;
|
*) message="Modify $single_file" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
|
# For multiple files, analyze the types of changes
|
||||||
|
local added_count=0
|
||||||
|
local modified_count=0
|
||||||
|
local deleted_count=0
|
||||||
|
local renamed_count=0
|
||||||
|
|
||||||
|
# Use the all_changes variable we already have
|
||||||
|
|
||||||
|
# Count different types of changes
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
|
[ -z "$status" ] && continue
|
||||||
|
case "${status:0:1}" in
|
||||||
|
A) ((added_count++)) ;;
|
||||||
|
M) ((modified_count++)) ;;
|
||||||
|
D) ((deleted_count++)) ;;
|
||||||
|
R) ((renamed_count++)) ;;
|
||||||
|
esac
|
||||||
|
done <<< "$all_changes"
|
||||||
|
|
||||||
|
# Also count untracked files if add-all is enabled
|
||||||
|
if [ "$ADD_ALL" = true ]; then
|
||||||
|
local untracked_files
|
||||||
|
untracked_files=$(git ls-files --others --exclude-standard)
|
||||||
|
if [ -n "$untracked_files" ]; then
|
||||||
|
local untracked_count
|
||||||
|
untracked_count=$(echo "$untracked_files" | wc -l)
|
||||||
|
((added_count += untracked_count))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate message based on change types
|
||||||
|
local change_parts=()
|
||||||
|
[ $added_count -gt 0 ] && change_parts+=("add $added_count")
|
||||||
|
[ $modified_count -gt 0 ] && change_parts+=("update $modified_count")
|
||||||
|
[ $deleted_count -gt 0 ] && change_parts+=("remove $deleted_count")
|
||||||
|
[ $renamed_count -gt 0 ] && change_parts+=("rename $renamed_count")
|
||||||
|
|
||||||
|
local change_desc=""
|
||||||
|
if [ ${#change_parts[@]} -eq 1 ]; then
|
||||||
|
change_desc="${change_parts[0]}"
|
||||||
|
elif [ ${#change_parts[@]} -eq 2 ]; then
|
||||||
|
change_desc="${change_parts[0]} and ${change_parts[1]}"
|
||||||
|
else
|
||||||
|
# Join all but last with commas, last with "and"
|
||||||
|
local last_idx=$((${#change_parts[@]} - 1))
|
||||||
|
for i in $(seq 0 $((last_idx - 1))); do
|
||||||
|
[ $i -gt 0 ] && change_desc+=", "
|
||||||
|
change_desc+="${change_parts[i]}"
|
||||||
|
done
|
||||||
|
change_desc+=" and ${change_parts[last_idx]}"
|
||||||
|
fi
|
||||||
|
|
||||||
local prefix=""
|
local prefix=""
|
||||||
if $has_tests; then
|
if $has_tests; then
|
||||||
prefix="test: "
|
prefix="test: "
|
||||||
@ -121,7 +193,10 @@ generate_commit_message() {
|
|||||||
prefix="feat: "
|
prefix="feat: "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message="${prefix}Update $files_count files"
|
# Capitalize first letter of change description
|
||||||
|
change_desc="$(echo "${change_desc:0:1}" | tr '[:lower:]' '[:upper:]')${change_desc:1}"
|
||||||
|
|
||||||
|
message="${prefix}${change_desc} files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$message"
|
echo "$message"
|
||||||
@ -225,19 +300,77 @@ show_status_and_confirm() {
|
|||||||
|
|
||||||
# Show staged changes
|
# Show staged changes
|
||||||
if ! git diff --cached --quiet; then
|
if ! git diff --cached --quiet; then
|
||||||
print_info "Staged changes:"
|
local staged_modified=""
|
||||||
git diff --cached --name-only -- | while IFS= read -r line; do echo " $line"; done
|
local staged_deleted=""
|
||||||
|
local staged_added=""
|
||||||
|
|
||||||
|
# Get staged file status and categorize
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
|
[ -z "$status" ] && continue
|
||||||
|
case "${status:0:1}" in
|
||||||
|
A) staged_added="${staged_added}${file}\n" ;;
|
||||||
|
M) staged_modified="${staged_modified}${file}\n" ;;
|
||||||
|
D) staged_deleted="${staged_deleted}${file}\n" ;;
|
||||||
|
*) staged_modified="${staged_modified}${file}\n" ;; # Default to modified for other statuses
|
||||||
|
esac
|
||||||
|
done < <(git diff --cached --name-status)
|
||||||
|
|
||||||
|
# Show staged added files
|
||||||
|
if [ -n "$staged_added" ]; then
|
||||||
|
print_info "Staged new files:"
|
||||||
|
echo -e "$staged_added" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show staged modified files
|
||||||
|
if [ -n "$staged_modified" ]; then
|
||||||
|
print_info "Staged modified files:"
|
||||||
|
echo -e "$staged_modified" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show staged deleted files
|
||||||
|
if [ -n "$staged_deleted" ]; then
|
||||||
|
print_info "Staged deleted files:"
|
||||||
|
echo -e "$staged_deleted" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done
|
||||||
|
fi
|
||||||
|
|
||||||
has_staged_changes=true
|
has_staged_changes=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show unstaged changes
|
# Show unstaged changes
|
||||||
if ! git diff --quiet; then
|
if ! git diff --quiet; then
|
||||||
if [ "$ADD_ALL" = true ]; then
|
local modified_files=""
|
||||||
print_info "Modified files (will be added):"
|
local deleted_files=""
|
||||||
else
|
|
||||||
print_info "Modified files (unstaged, will NOT be included):"
|
# Get file status and categorize
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
|
[ -z "$status" ] && continue
|
||||||
|
case "${status:0:1}" in
|
||||||
|
M) modified_files="${modified_files}${file}\n" ;;
|
||||||
|
D) deleted_files="${deleted_files}${file}\n" ;;
|
||||||
|
*) modified_files="${modified_files}${file}\n" ;; # Default to modified for other statuses
|
||||||
|
esac
|
||||||
|
done < <(git diff --name-status)
|
||||||
|
|
||||||
|
# Show modified files
|
||||||
|
if [ -n "$modified_files" ]; then
|
||||||
|
if [ "$ADD_ALL" = true ]; then
|
||||||
|
print_info "Modified files (will be added):"
|
||||||
|
else
|
||||||
|
print_info "Modified files (unstaged, will NOT be included):"
|
||||||
|
fi
|
||||||
|
echo -e "$modified_files" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done
|
||||||
fi
|
fi
|
||||||
git diff --name-only -- | while IFS= read -r line; do echo " $line"; done
|
|
||||||
|
# Show deleted files
|
||||||
|
if [ -n "$deleted_files" ]; then
|
||||||
|
if [ "$ADD_ALL" = true ]; then
|
||||||
|
print_info "Deleted files (will be removed):"
|
||||||
|
else
|
||||||
|
print_info "Deleted files (unstaged, will NOT be included):"
|
||||||
|
fi
|
||||||
|
echo -e "$deleted_files" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done
|
||||||
|
fi
|
||||||
|
|
||||||
has_unstaged_changes=true
|
has_unstaged_changes=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user