1
+ #! /bin/bash
2
+
3
+ # Go Release Process Script
4
+ # Used for copying go files to release directory and make a commit
5
+
6
+ set -e # Exit on error
7
+
8
+ # Check if project name and version is provided
9
+ if [ $# -ne 3 ]; then
10
+ echo " Usage: $0 <function> <project-name> [version]"
11
+ echo " Example: $0 get_release_dir_name DynamoDbEncryption v0.1.0"
12
+ echo " Example: $0 run_release_script DynamoDbEncryption v0.1.0"
13
+ exit 1
14
+ fi
15
+
16
+ # Function to map project name to release directory name
17
+ get_release_dir_name () {
18
+ local project=$1
19
+ case " $project " in
20
+ " DynamoDbEncryption" ) echo " dynamodb-esdk" ;;
21
+ * ) echo " Error: Unknown project name: $project " >&2 ; return 1 ;;
22
+ esac
23
+ }
24
+
25
+ run_release_script () {
26
+ PROJECT_NAME=$1
27
+ VERSION=$2
28
+
29
+ echo " Starting Go release script for $PROJECT_NAME $VERSION "
30
+
31
+ # Pull the latest smithy-dafny and libraries git submodules
32
+ echo " Pulling latest git submodules..."
33
+ git submodule update --init --recursive
34
+
35
+ # Go to the project directory
36
+ echo " Navigating to $PROJECT_NAME ..."
37
+ cd " $PROJECT_NAME " || { echo " Error: Project directory $PROJECT_NAME not found" ; exit 1; }
38
+
39
+ # Build using make commands
40
+ echo " Building project..."
41
+ make polymorph_dafny
42
+ make polymorph_go
43
+ make transpile_go
44
+ make test_go
45
+
46
+ # Run Go tools in ImplementationFromDafny-go
47
+ echo " Running Go tools in ImplementationFromDafny-go..."
48
+ cd runtimes/go/ImplementationFromDafny-go || { echo " Error: ImplementationFromDafny-go directory not found" ; exit 1; }
49
+
50
+ find . -name " *shim.go" -type f -delete
51
+ echo " Removed all shim.go files"
52
+
53
+ echo " Running goimports..."
54
+ goimports -w .
55
+
56
+ echo " Running go get -u..."
57
+ go get -u
58
+
59
+ echo " Running go mod tidy..."
60
+ go mod tidy
61
+
62
+ echo " Running go build to check for errors..."
63
+ go build --gcflags=" -e" ./...
64
+
65
+ # Replacement directives are removed to get package from go pkg instead of local copy
66
+ echo " Removing all replace directives from go.mod..."
67
+ go mod edit -json | jq -r ' .Replace[].Old.Path' | xargs -n1 go mod edit -dropreplace
68
+
69
+ # Get the mapped release directory name
70
+ RELEASE_DIR_NAME=$( get_release_dir_name " $PROJECT_NAME " )
71
+
72
+ # Copy files to releases directory
73
+ echo " Copying files to releases/go/$RELEASE_DIR_NAME ..."
74
+
75
+ # Use rsync to copy files while excluding following ones:
76
+ # ImplementationFromDafny.go: This file is for devlopment. Users is expected use API(s) from `*/api_client.go`
77
+ # ImplementationFromDafny-go.dtr: This is the dafny translation record only needed for code generation
78
+ # go.sum: This files will be updated by go mod tidy
79
+ rsync -av --exclude=" ImplementationFromDafny.go" --exclude=" ImplementationFromDafny-go.dtr" --exclude=" go.sum" ./ " $( git rev-parse --show-toplevel) /releases/go/$RELEASE_DIR_NAME /"
80
+
81
+ # Run Go tools in releases directory
82
+ echo " Running Go tools in releases/go/$RELEASE_DIR_NAME ..."
83
+
84
+ cd " $( git rev-parse --show-toplevel) /releases/go/$RELEASE_DIR_NAME /" || { echo " Error: releases directory not found" ; exit 1; }
85
+
86
+ echo " Running goimports..."
87
+ goimports -w .
88
+ echo " Running go get -u..."
89
+ go get -u ./...
90
+
91
+ echo " Running go mod tidy..."
92
+ go mod tidy
93
+
94
+ echo " Running go build to check for errors..."
95
+ go build --gcflags=" -e" ./...
96
+
97
+ # Prepare for commit
98
+ echo " creating a branch..."
99
+
100
+ git checkout -b " golang-release-staging-branch/$RELEASE_DIR_NAME /${VERSION} "
101
+ git add *
102
+
103
+ git commit -m " Release $RELEASE_DIR_NAME Go module ${VERSION} "
104
+ git push origin " golang-release-staging-branch/$RELEASE_DIR_NAME /${VERSION} "
105
+ }
106
+
107
+ " $@ "
0 commit comments