Skip to content

Commit 0a0e07d

Browse files
authored
chore: add script to replace dependencies in a dummy go.work file (#576)
* chore: add script to replace dependencies in a dummy go.work file * chore: use option to defined sdk directory
1 parent 6a42ca3 commit 0a0e07d

File tree

2 files changed

+61
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)