chore: adds scripts to perform gitops-engine migration (#24291)

Signed-off-by: Patroklos Papapetrou <ppapapetrou76@gmail.com>
Signed-off-by: Papapetrou Patroklos <1743100+ppapapetrou76@users.noreply.github.com>
Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: Leonardo Luz Almeida <leoluz@users.noreply.github.com>
This commit is contained in:
Papapetrou Patroklos
2025-09-10 16:44:58 +03:00
committed by GitHub
parent 12d3f5dba1
commit 93148b52c4
3 changed files with 104 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"