diff --git a/hack/migrate-gitops-engine/merge.sh b/hack/migrate-gitops-engine/merge.sh new file mode 100755 index 0000000000..16e737ebcf --- /dev/null +++ b/hack/migrate-gitops-engine/merge.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Script to collect GitHub handle and branch name from user + +echo "Please provide the following information:" +echo + +# Prompt for GitHub handle +read -r -p "Enter your GitHub handle: " github_handle + +# Validate that GitHub handle is not empty +while [[ -z "$github_handle" ]]; do + echo "GitHub handle cannot be empty." + read -r -p "Enter your GitHub handle: " github_handle +done + +# Prompt for branch name +read -r -p "Enter the branch name: " branch_name + +# Validate that branch name is not empty +while [[ -z "$branch_name" ]]; do + echo "Branch name cannot be empty." + read -r -p "Enter the branch name: " branch_name +done + +echo "Merging migrated gitops-engine branch $branch_name from $github_handle/gitops-engine.git" + +git remote add ge-migrated git@github.com:"$github_handle"/gitops-engine.git +git fetch ge-migrated + +if git merge --no-edit ge-migrated/"$branch_name" --allow-unrelated-histories ; then + sh ./hack/migrate-gitops-engine/replace-vendor.sh + sh ./hack/migrate-gitops-engine/update-dockerfile.sh + echo "Merging of gitops-engine branch $branch_name from $github_handle/gitops-engine.git succeeded" +else + echo "Merging of gitops-engine branch $branch_name from $github_handle/gitops-engine.git failed" + exit 1 +fi + + diff --git a/hack/migrate-gitops-engine/replace-vendor.sh b/hack/migrate-gitops-engine/replace-vendor.sh new file mode 100755 index 0000000000..521ea4bc28 --- /dev/null +++ b/hack/migrate-gitops-engine/replace-vendor.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Script to replace all occurrences of "go mod vendor" with "go work vendor" recursively + +set -e + +# Add common Go binary path to PATH if not already present +export PATH=$PATH:/usr/local/go/bin + +go work init ./gitops-engine +go work use . +go work vendor +go mod tidy + +echo "Searching for files containing 'go work vendor'..." + +# Replace in each file +for file in Makefile Tiltfile hack/generate-proto.sh .github/workflows/bump-major-version.yaml .github/workflows/ci-build.yaml; do + echo "Processing: $file" + # Create a backup and replace + sed -i.bak 's/go mod vendor/go work vendor/g' "$file" + echo " - Replaced occurrences in $file" + echo " - Backup created: $file.bak" +done + +echo +echo "Replacement complete!" +echo "Removing backup files..." +find . -name '*.bak' -delete + +echo "Syncing go mod files..." +go work sync +go mod tidy +go work vendor + diff --git a/hack/migrate-gitops-engine/update-dockerfile.sh b/hack/migrate-gitops-engine/update-dockerfile.sh new file mode 100755 index 0000000000..2484f89a29 --- /dev/null +++ b/hack/migrate-gitops-engine/update-dockerfile.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Script to add two lines after the line containing "COPY go.* ./" in Dockerfile +# The first line adds "green" and the second adds "red" + +DOCKERFILE="Dockerfile" + +# Check if Dockerfile exists +if [[ ! -f "$DOCKERFILE" ]]; then + echo "Error: $DOCKERFILE not found!" + exit 1 +fi + +# Use sed to insert the two lines after the line containing "COPY go.* ./" +# The pattern looks for the line containing "COPY go.* ./" and adds two lines after it +sed -i.tmp '/COPY go\.\* \.\//{ +a\ +RUN mkdir -p gitops-engine +a\ +COPY gitops-engine/go.* ./gitops-engine +}' "$DOCKERFILE" + +# Remove the temporary file created by sed +rm "${DOCKERFILE}.tmp" 2>/dev/null || true + +echo "Successfully added required lines to $DOCKERFILE:" +echo "" +echo "Lines around the modification:" +grep -n -A 3 -B 1 "COPY go\.\* \./" "$DOCKERFILE"