nixbot

builds

failed treefmt-check checks.aarch64-darwin.treefmt · build #154 · raw

1build04: building kpl6ra7q3bwxaxdqqk3ri07yk0n95gdb-treefmt-check.drv2treefmt v2.5.0traversed 204 files3emitted 159 files for processing4formatted 159 files (1 changed) in 3.389s5 M nix/packages/update-go-modules/update-go-modules.sh6diff --git a/nix/packages/update-go-modules/update-go-modules.sh b/nix/packages/update-go-modules/update-go-modules.sh7index 6f88c09..146e90c 1007558--- a/nix/packages/update-go-modules/update-go-modules.sh9+++ b/nix/packages/update-go-modules/update-go-modules.sh10@@ -22,198 +22,198 @@ YELLOW='\033[1;33m'11 NC='\033[0m' # No Color12 13 log() {14- echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*"15+ echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*"16 }17 18 error() {19- echo -e "${RED}[ERROR]${NC} $*" >&220+ echo -e "${RED}[ERROR]${NC} $*" >&221 }22 23 warning() {24- echo -e "${YELLOW}[WARNING]${NC} $*"25+ echo -e "${YELLOW}[WARNING]${NC} $*"26 }27 28 # Validate required environment variables29 validate_env() {30- local missing=()31+ local missing=()32 33- if [[ -z ${GITEA_TOKEN:-} ]]; then34- missing+=("GITEA_TOKEN")35- fi36+ if [[ -z ${GITEA_TOKEN:-} ]]; then37+ missing+=("GITEA_TOKEN")38+ fi39 40- if [[ -z ${GITEA_URL:-} ]]; then41- missing+=("GITEA_URL")42- fi43+ if [[ -z ${GITEA_URL:-} ]]; then44+ missing+=("GITEA_URL")45+ fi46 47- if [[ -z ${REPO_OWNER:-} ]]; then48- missing+=("REPO_OWNER")49- fi50+ if [[ -z ${REPO_OWNER:-} ]]; then51+ missing+=("REPO_OWNER")52+ fi53 54- if [[ -z ${REPO_NAME:-} ]]; then55- missing+=("REPO_NAME")56- fi57+ if [[ -z ${REPO_NAME:-} ]]; then58+ missing+=("REPO_NAME")59+ fi60 61- if [[ ${#missing[@]} -gt 0 ]]; then62- error "Missing required environment variables: ${missing[*]}"63- error "Please set these variables before running the script"64- exit 165- fi66+ if [[ ${#missing[@]} -gt 0 ]]; then67+ error "Missing required environment variables: ${missing[*]}"68+ error "Please set these variables before running the script"69+ exit 170+ fi71 }72 73 # Clean up worktrees on exit74 cleanup() {75- if [[ -d $WORKTREE_BASE ]]; then76- log "Cleaning up worktrees..."77- find "$WORKTREE_BASE" -mindepth 1 -maxdepth 1 -type d | while read -r worktree; do78- git worktree remove --force "$worktree" 2>/dev/null || true79- done80- rm -rf "$WORKTREE_BASE"81- fi82+ if [[ -d $WORKTREE_BASE ]]; then83+ log "Cleaning up worktrees..."84+ find "$WORKTREE_BASE" -mindepth 1 -maxdepth 1 -type d | while read -r worktree; do85+ git worktree remove --force "$worktree" 2>/dev/null || true86+ done87+ rm -rf "$WORKTREE_BASE"88+ fi89 }90 91 trap cleanup EXIT92 93 # Find all Go modules in the repository94 find_go_modules() {95- find "$REPO_ROOT" -name "go.mod" -type f | while read -r mod_file; do96- dirname "$mod_file"97- done98+ find "$REPO_ROOT" -name "go.mod" -type f | while read -r mod_file; do99+ dirname "$mod_file"100+ done101 }102 103 # Get list of outdated dependencies for a module104 get_outdated_dependencies() {105- local module_dir="$1"106+ local module_dir="$1"107 108- cd "$module_dir"109+ cd "$module_dir"110 111- # Get list of all direct dependencies and their available updates112- go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}|{{.Version}}|{{.Update.Version}}{{end}}' -m all 2>/dev/null | grep -v '^$' || true113+ # Get list of all direct dependencies and their available updates114+ go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}|{{.Version}}|{{.Update.Version}}{{end}}' -m all 2>/dev/null | grep -v '^$' || true115 }116 117 # Create pull request using curl API118 create_pull_request() {119- local branch_name="$1"120- local pr_title="$2"121- local pr_body="$3"122+ local branch_name="$1"123+ local pr_title="$2"124+ local pr_body="$3"125 126- log "Creating pull request for branch: $branch_name"127+ log "Creating pull request for branch: $branch_name"128 129- # Push the branch130- git push origin "+HEAD:${branch_name}"131+ # Push the branch132+ git push origin "+HEAD:${branch_name}"133 134- # Create PR using curl135- local resp136- resp=$(curl -s -X POST \137- -H "Authorization: token $GITEA_TOKEN" \138- -H "Content-Type: application/json" \139- -d "{140+ # Create PR using curl141+ local resp142+ resp=$(curl -s -X POST \143+ -H "Authorization: token $GITEA_TOKEN" \144+ -H "Content-Type: application/json" \145+ -d "{146 \"head\": \"${branch_name}\",147 \"base\": \"${BASE_BRANCH}\",148 \"title\": \"${pr_title}\",149 \"body\": \"${pr_body}\"150 }" \151- "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls")152+ "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls")153 154- local pr_number155- pr_number=$(echo "$resp" | jq -r '.number')156+ local pr_number157+ pr_number=$(echo "$resp" | jq -r '.number')158 159- # Check if PR already exists160- local error_msg161- error_msg=$(echo "$resp" | jq -r '.message // empty')162+ # Check if PR already exists163+ local error_msg164+ error_msg=$(echo "$resp" | jq -r '.message // empty')165 166- if [[ $error_msg == *"pull request already exists"* ]]; then167- log "Pull request already exists for branch: $branch_name"168- return 0169- fi170+ if [[ $error_msg == *"pull request already exists"* ]]; then171+ log "Pull request already exists for branch: $branch_name"172+ return 0173+ fi174 175- if [[ $pr_number == "null" ]]; then176- error "Error creating pull request:"177- echo "$resp" | jq . >&2178- return 1179- fi180+ if [[ $pr_number == "null" ]]; then181+ error "Error creating pull request:"182+ echo "$resp" | jq . >&2183+ return 1184+ fi185 186- local pr_url="${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/pulls/${pr_number}"187- log "Created pull request #$pr_number: $pr_url"188+ local pr_url="${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/pulls/${pr_number}"189+ log "Created pull request #$pr_number: $pr_url"190 191- # Enable auto-merge for the newly created PR192- enable_auto_merge "$pr_number"193+ # Enable auto-merge for the newly created PR194+ enable_auto_merge "$pr_number"195 }196 197 # Enable auto-merge for a pull request198 enable_auto_merge() {199- local pr_number="$1"200+ local pr_number="$1"201 202- log "Enabling auto-merge for PR #$pr_number"203+ log "Enabling auto-merge for PR #$pr_number"204 205- # Merge when checks succeed206- while true; do207- local resp208- resp=$(curl -s -X POST \209- -H "Authorization: token $GITEA_TOKEN" \210- -H "Content-Type: application/json" \211- -d '{212+ # Merge when checks succeed213+ while true; do214+ local resp215+ resp=$(curl -s -X POST \216+ -H "Authorization: token $GITEA_TOKEN" \217+ -H "Content-Type: application/json" \218+ -d '{219 "Do": "merge",220 "merge_when_checks_succeed": true,221 "delete_branch_after_merge": true222 }' \223- "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls/$pr_number/merge")224-225- local msg226- msg=$(echo "$resp" | jq -r '.message')227- if [[ $msg != "Please try again later" ]]; then228- break229- fi230- log "Retrying auto-merge in 2 seconds..."231- sleep 2232- done233-234- log "Pull request #$pr_number merge initiated"235+ "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls/$pr_number/merge")236+237+ local msg238+ msg=$(echo "$resp" | jq -r '.message')239+ if [[ $msg != "Please try again later" ]]; then240+ break241+ fi242+ log "Retrying auto-merge in 2 seconds..."243+ sleep 2244+ done245+246+ log "Pull request #$pr_number merge initiated"247 }248 249 # Update a single dependency250 update_single_dependency() {251- local module_dir="$1"252- local dep_path="$2"253- local current_version="$3"254- local new_version="$4"255- local module_name="$5"256-257- # Create safe branch name (replace special characters)258- local safe_dep_name="${dep_path//\//-}"259- safe_dep_name="${safe_dep_name//./-}"260- local branch_name261- branch_name="update-go-dep-${safe_dep_name}-${new_version}"262- local worktree_dir="$WORKTREE_BASE/$branch_name"263-264- log "Updating $dep_path from $current_version to $new_version"265-266- # Create worktree267- mkdir -p "$WORKTREE_BASE"268- git worktree add -b "$branch_name" "$worktree_dir" "$BASE_BRANCH"269-270- # Change to module directory in worktree271- # module_dir is an absolute path - make it relative to repo root272- local relative_module_dir="${module_dir#"$REPO_ROOT"}"273- relative_module_dir="${relative_module_dir#/}" # Remove leading slash if present274- cd "$worktree_dir/${relative_module_dir:-.}" # Default to . if at repo root275-276- # Update specific dependency277- log "Updating dependency $dep_path to $new_version..."278- go get "${dep_path}@${new_version}"279- go mod tidy280-281- # Check if there are any changes282- if ! git diff --quiet; then283- # Update vendor hash if needed284- nix run .#data-mesher.update-vendor-hash -- "$worktree_dir"285-286- # Commit changes287- git add -A288- git commit -m "fix(deps): update module $dep_path to $new_version"289-290- # Create pull request291- local pr_title="fix(deps): update module $dep_path to $new_version"292- local pr_body="## Automated Go Dependency Update293+ local module_dir="$1"294+ local dep_path="$2"295+ local current_version="$3"296+ local new_version="$4"297+ local module_name="$5"298+299+ # Create safe branch name (replace special characters)300+ local safe_dep_name="${dep_path//\//-}"301+ safe_dep_name="${safe_dep_name//./-}"302+ local branch_name303+ branch_name="update-go-dep-${safe_dep_name}-${new_version}"304+ local worktree_dir="$WORKTREE_BASE/$branch_name"305+306+ log "Updating $dep_path from $current_version to $new_version"307+308+ # Create worktree309+ mkdir -p "$WORKTREE_BASE"310+ git worktree add -b "$branch_name" "$worktree_dir" "$BASE_BRANCH"311+312+ # Change to module directory in worktree313+ # module_dir is an absolute path - make it relative to repo root314+ local relative_module_dir="${module_dir#"$REPO_ROOT"}"315+ relative_module_dir="${relative_module_dir#/}" # Remove leading slash if present316+ cd "$worktree_dir/${relative_module_dir:-.}" # Default to . if at repo root317+318+ # Update specific dependency319+ log "Updating dependency $dep_path to $new_version..."320+ go get "${dep_path}@${new_version}"321+ go mod tidy322+323+ # Check if there are any changes324+ if ! git diff --quiet; then325+ # Update vendor hash if needed326+ nix run .#data-mesher.update-vendor-hash -- "$worktree_dir"327+328+ # Commit changes329+ git add -A330+ git commit -m "fix(deps): update module $dep_path to $new_version"331+332+ # Create pull request333+ local pr_title="fix(deps): update module $dep_path to $new_version"334+ local pr_body="## Automated Go Dependency Update335 336 This pull request updates a single Go dependency for the module \`$module_name\`:337 338@@ -227,86 +227,86 @@ https://pkg.go.dev/$dep_path?tab=versions339 340 This is an automated update generated by the update-go-modules script."341 342- create_pull_request "$branch_name" "$pr_title" "$pr_body"343+ create_pull_request "$branch_name" "$pr_title" "$pr_body"344 345- log "Successfully processed $dep_path update"346- else347- log "No changes detected for $dep_path update"348- fi349+ log "Successfully processed $dep_path update"350+ else351+ log "No changes detected for $dep_path update"352+ fi353 354- # Clean up worktree355- cd "$REPO_ROOT"356- git worktree remove --force "$worktree_dir"357+ # Clean up worktree358+ cd "$REPO_ROOT"359+ git worktree remove --force "$worktree_dir"360 }361 362 # Process a single Go module363 process_go_module() {364- local module_dir="$1"365- local module_name366- module_name=$(cd "$module_dir" && go list -m)367-368- log "Processing Go module: $module_name in $module_dir"369-370- # Get outdated dependencies371- local outdated_deps372- outdated_deps=$(get_outdated_dependencies "$module_dir")373-374- if [[ -z $outdated_deps ]]; then375- log "No outdated dependencies found for $module_name"376- return377- fi378-379- # Count dependencies380- local dep_count381- dep_count=$(echo "$outdated_deps" | wc -l)382- log "Found $dep_count outdated dependencies for $module_name"383-384- # Process each outdated dependency385- while IFS='|' read -r dep_path current_version new_version; do386- if [[ -n $dep_path ]]; then387- update_single_dependency "$module_dir" "$dep_path" "$current_version" "$new_version" "$module_name"388-389- # Add a small delay between PRs to avoid overwhelming the API390- sleep 2391- fi392- done <<<"$outdated_deps"393+ local module_dir="$1"394+ local module_name395+ module_name=$(cd "$module_dir" && go list -m)396+397+ log "Processing Go module: $module_name in $module_dir"398+399+ # Get outdated dependencies400+ local outdated_deps401+ outdated_deps=$(get_outdated_dependencies "$module_dir")402+403+ if [[ -z $outdated_deps ]]; then404+ log "No outdated dependencies found for $module_name"405+ return406+ fi407+408+ # Count dependencies409+ local dep_count410+ dep_count=$(echo "$outdated_deps" | wc -l)411+ log "Found $dep_count outdated dependencies for $module_name"412+413+ # Process each outdated dependency414+ while IFS='|' read -r dep_path current_version new_version; do415+ if [[ -n $dep_path ]]; then416+ update_single_dependency "$module_dir" "$dep_path" "$current_version" "$new_version" "$module_name"417+418+ # Add a small delay between PRs to avoid overwhelming the API419+ sleep 2420+ fi421+ done <<<"$outdated_deps"422 }423 424 # Main execution425 main() {426- log "Starting Go module update process"427+ log "Starting Go module update process"428 429- # Validate environment430- validate_env431+ # Validate environment432+ validate_env433 434- # Ensure we're in a git repository435- if ! git rev-parse --git-dir >/dev/null 2>&1; then436- error "Not in a git repository"437- exit 1438- fi439+ # Ensure we're in a git repository440+ if ! git rev-parse --git-dir >/dev/null 2>&1; then441+ error "Not in a git repository"442+ exit 1443+ fi444 445- # Fetch latest changes446- git fetch origin447+ # Fetch latest changes448+ git fetch origin449 450- # Find and process all Go modules451- local modules=()452- while IFS= read -r module; do453- modules+=("$module")454- done < <(find_go_modules)455+ # Find and process all Go modules456+ local modules=()457+ while IFS= read -r module; do458+ modules+=("$module")459+ done < <(find_go_modules)460 461- if [[ ${#modules[@]} -eq 0 ]]; then462- warning "No Go modules found in the repository"463- exit 0464- fi465+ if [[ ${#modules[@]} -eq 0 ]]; then466+ warning "No Go modules found in the repository"467+ exit 0468+ fi469 470- log "Found ${#modules[@]} Go module(s)"471+ log "Found ${#modules[@]} Go module(s)"472 473- # Process each module474- for module in "${modules[@]}"; do475- process_go_module "$module"476- done477+ # Process each module478+ for module in "${modules[@]}"; do479+ process_go_module "$module"480+ done481 482- log "Go module update process completed"483+ log "Go module update process completed"484 }485 486 # Run main function