chore: add script to replace dependencies in a dummy go.work file (#656)

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

* chore: use option to defined sdk directory
This commit is contained in:
Rüdiger Schmitz 2025-01-30 11:37:12 +01:00 committed by GitHub
parent b5ce160d13
commit 7f52013d96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 58 additions and 0 deletions

1
.gitignore vendored
View file

@ -30,3 +30,4 @@ vendor/
# Go workspace file
go.work
go.work.sum

57
scripts/replace.sh Executable file
View file

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