Skip to content

Commit 8f14ed0

Browse files
committed
chore: add script to replace dependencies in a dummy go.work file
1 parent 7f18fd6 commit 8f14ed0

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ dist/
88

99
# OS generated files
1010
.DS_Store
11+
12+
# Go workspace file
13+
go.work
14+
go.work.sum

scripts/replace.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# Add replace directives to local files to go.work
3+
set -eo pipefail
4+
5+
if [ -d $1 ]; then
6+
SDK_DIR=$1
7+
shift
8+
fi
9+
10+
if [ -z "$SDK_DIR" ]; then
11+
SDK_DIR=../stackit-sdk-generator/sdk-repo-updated
12+
echo "No SDK_DIR set, using $SDK_DIR"
13+
fi
14+
15+
16+
if [ ! -f go.work ]; then
17+
go work init
18+
go work use .
19+
else
20+
echo "go.work already exists"
21+
fi
22+
23+
if [ $# -gt 0 ];then
24+
# modules passed via commandline
25+
for service in $*; do
26+
if [ ! -d $SDK_DIR/services/$service ]; then
27+
echo "service directory $SDK_DIR/services/$service does not exist"
28+
exit 1
29+
fi
30+
echo "replacing selected service $service"
31+
if [ "$service" = "core" ]; then
32+
go work edit -replace github.com/stackitcloud/stackit-sdk-go/core=$SDK_DIR/core
33+
else
34+
go work edit -replace github.com/stackitcloud/stackit-sdk-go/services/$service=$SDK_DIR/services/$service
35+
fi
36+
done
37+
else
38+
# replace all modules
39+
echo "replacing all services"
40+
go work edit -replace github.com/stackitcloud/stackit-sdk-go/core=$SDK_DIR/core
41+
for n in $(find ${SDK_DIR}/services -name go.mod);do
42+
service=$(dirname $n)
43+
service=${service#${SDK_DIR}/services/}
44+
go work edit -replace github.com/stackitcloud/stackit-sdk-go/services/$service=$(dirname $n)
45+
done
46+
fi
47+
go work edit -fmt
48+
go work sync

0 commit comments

Comments
 (0)