Skip to content

chore: add script to replace dependencies in a dummy go.work file #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ dist/

# OS generated files
.DS_Store

# Go workspace file
go.work
go.work.sum
57 changes: 57 additions & 0 deletions scripts/replace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# Add replace directives to local files to go.work
set -eo pipefail

while getopts "s:" option; do
case "${option}" in
s)
SDK_DIR=${OPTARG}
;;

*)
echo "call: $0 [-s sdk-dir] <apis*>"
exit 0
;;
esac
done
shift $((OPTIND-1))

if [ -z "$SDK_DIR" ]; then
SDK_DIR=../stackit-sdk-generator/sdk-repo-updated
echo "No SDK_DIR set, using $SDK_DIR"
fi


if [ ! -f go.work ]; then
go work init
go work use .
else
echo "go.work already exists"
fi

if [ $# -gt 0 ];then
# modules passed via commandline
for service in $*; do
if [ ! -d $SDK_DIR/services/$service ]; then
echo "service directory $SDK_DIR/services/$service does not exist"
exit 1
fi
echo "replacing selected service $service"
if [ "$service" = "core" ]; then
go work edit -replace github.com/stackitcloud/stackit-sdk-go/core=$SDK_DIR/core
else
go work edit -replace github.com/stackitcloud/stackit-sdk-go/services/$service=$SDK_DIR/services/$service
fi
done
else
# replace all modules
echo "replacing all services"
go work edit -replace github.com/stackitcloud/stackit-sdk-go/core=$SDK_DIR/core
for n in $(find ${SDK_DIR}/services -name go.mod);do
service=$(dirname $n)
service=${service#${SDK_DIR}/services/}
go work edit -replace github.com/stackitcloud/stackit-sdk-go/services/$service=$(dirname $n)
done
fi
go work edit -fmt
go work sync