From 8f14ed0995188894fb5d5b0a79f3ba844d6604a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:52:14 +0100 Subject: [PATCH 1/2] chore: add script to replace dependencies in a dummy go.work file --- .gitignore | 4 ++++ scripts/replace.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 scripts/replace.sh diff --git a/.gitignore b/.gitignore index 428e142ad..47aabc929 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ dist/ # OS generated files .DS_Store + +# Go workspace file +go.work +go.work.sum \ No newline at end of file diff --git a/scripts/replace.sh b/scripts/replace.sh new file mode 100755 index 000000000..50947612f --- /dev/null +++ b/scripts/replace.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Add replace directives to local files to go.work +set -eo pipefail + +if [ -d $1 ]; then + SDK_DIR=$1 + shift +fi + +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 From a59290d18c3306c0aed98bf5bc4d5351689f064c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:03:19 +0100 Subject: [PATCH 2/2] chore: use option to defined sdk directory --- scripts/replace.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/replace.sh b/scripts/replace.sh index 50947612f..0c37f4b85 100755 --- a/scripts/replace.sh +++ b/scripts/replace.sh @@ -2,10 +2,19 @@ # Add replace directives to local files to go.work set -eo pipefail -if [ -d $1 ]; then - SDK_DIR=$1 - shift -fi +while getopts "s:" option; do + case "${option}" in + s) + SDK_DIR=${OPTARG} + ;; + + *) + echo "call: $0 [-s sdk-dir] " + exit 0 + ;; + esac +done +shift $((OPTIND-1)) if [ -z "$SDK_DIR" ]; then SDK_DIR=../stackit-sdk-generator/sdk-repo-updated