Skip to content

Commit 95c2db2

Browse files
committed
feat: Lint and test service SDK before pushing
1 parent b67c0d0 commit 95c2db2

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

scripts/sdk-create-pr.sh

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ BRANCH_PREFIX=$1
1111
COMMIT_INFO=$2
1212

1313
if [ $# -lt 2 ]; then
14-
echo "Not enough arguments supplied. Required: 'branch-prefix' 'commit-info'"
14+
echo "! Not enough arguments supplied. Required: 'branch-prefix' 'commit-info'"
1515
exit 1
1616
fi
1717

1818
if type -p go >/dev/null; then
1919
:
2020
else
21-
echo "Go not installed, unable to proceed."
21+
echo "! Go not installed, unable to proceed."
2222
exit 1
2323
fi
2424

2525
if [ ! -d ${SDK_REPO_LOCAL_PATH} ]; then
26-
echo "sdk to commit not found in root. Please run make generate-sdk"
26+
echo "! SDK to commit not found in root. Please run make generate-sdk"
2727
exit 1
2828
fi
2929

@@ -41,7 +41,8 @@ else
4141
fi
4242

4343
# Create temp directory to work on
44-
work_dir=$(mktemp -d)
44+
work_dir="$ROOT_DIR/temp"
45+
mkdir -p ${work_dir}
4546
if [[ ! ${work_dir} || -d {work_dir} ]]; then
4647
echo "Unable to create temporary directory"
4748
exit 1
@@ -51,7 +52,7 @@ fi
5152
trap "rm -rf ${work_dir}" EXIT
5253

5354
mkdir ${work_dir}/git_repo # Where the git repo will be created
54-
mkdir ${work_dir}/sdk_backup # Backup of the SDK to check for new modules
55+
mkdir ${work_dir}/sdk_backup # Backup of the SDK to check for new modules
5556
mkdir ${work_dir}/sdk_to_push # Copy of SDK to push
5657

5758
# Prepare SDK to push
@@ -60,7 +61,7 @@ rm -rf ${work_dir}/sdk_to_push/.git
6061

6162
# Initialize git repo
6263
cd ${work_dir}/git_repo
63-
git clone ${REPO_URL_SSH} ./
64+
git clone ${REPO_URL_SSH} ./ --quiet
6465
git config user.name "${COMMIT_NAME}"
6566
git config user.email "${COMMIT_EMAIL}"
6667

@@ -74,37 +75,50 @@ for service_path in ${work_dir}/sdk_to_push/services/*; do
7475
# Removal of pulled data is necessary because the old version may have files
7576
# that were deleted in the new version
7677
rm -rf ./services/$service/*
77-
cp -a ${work_dir}/sdk_to_push/services/$service/. ./services/$service
78+
cp -a ${work_dir}/sdk_to_push/services/$service/. ./services/$service
7879

7980
# Check for changes in the specific folder compared to main
8081
service_changes=$(git status --porcelain "services/$service")
8182

8283
if [[ -n "$service_changes" ]]; then
83-
echo "Committing changes for $service"
84+
echo -e "\n>> Detected changes in $service service"
85+
86+
# If lint or test fails for a service, we skip it and continue to the next one
87+
make lint skip-non-generated-files=true service=$service || {
88+
echo "! Linting failed for $service. THE UPDATE OF THIS SERVICE WILL BE SKIPPED."
89+
continue
90+
}
91+
make test skip-non-generated-files=true service=$service || {
92+
echo "! Testing failed for $service. THE UPDATE OF THIS SERVICE WILL BE SKIPPED."
93+
continue
94+
}
95+
8496
if [[ "$BRANCH_PREFIX" != "main" ]]; then
8597
git switch main # This is needed to create a new branch for the service without including the previously committed files
8698
branch="$BRANCH_PREFIX/$service"
8799
git switch -c "$branch"
88100
else
89101
branch=$BRANCH_PREFIX
90-
fi
91-
102+
fi
103+
92104
git add services/${service}/
93105
if [ "${LANGUAGE}" == "go" ] && [ ! -d "${work_dir}/sdk_backup/services/${service}/" ]; then # Check if it is a newly added SDK module
94106
# go work use -r adds a use directive to the go.work file for dir, if it exists, and removes the use directory if the argument directory doesn’t exist
95107
# the -r flag examines subdirectories of dir recursively
96108
# this prevents errors if there is more than one new module in the SDK generation
97-
go work use -r .
109+
go work use -r .
98110
git add go.work
99111
fi
100-
112+
101113
if [[ "$branch" != "main" ]]; then
114+
echo ">> Creating PR for $service"
102115
git commit -m "Generate $service"
103116
git push origin "$branch"
104117
gh pr create --title "Generator: Update SDK /services/$service" --body "$COMMIT_INFO" --head "$branch" --base "main"
105118
else
119+
echo ">> Pushing changes for $service service..."
106120
git commit -m "Generate $service: $COMMIT_INFO"
107121
git push origin "$branch"
108-
fi
122+
fi
109123
fi
110-
done
124+
done

0 commit comments

Comments
 (0)