Skip to content

Commit

Permalink
feat: Improve echos in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopalet committed Nov 27, 2024
1 parent 1533607 commit 45fcbf1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
6 changes: 3 additions & 3 deletions scripts/download-oas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi
# Create temp directory to clone OAS repo
work_dir=$(mktemp -d)
if [[ ! ${work_dir} || -d {work_dir} ]]; then
echo "Unable to create temporary directory"
echo "! Unable to create temporary directory"
exit 1
fi
trap "rm -rf ${work_dir}" EXIT # Delete temp directory on exit
Expand Down Expand Up @@ -55,8 +55,8 @@ for service_dir in ${work_dir}/${OAS_REPO_NAME}/services/*; do
if [[ ${version} == *alpha* ]]; then
# To support initial integrations of the IaaS API in an Alpha state, we will temporarily use it to generate an IaaS Alpha SDK module
# This check can be removed once the IaaS API moves all endpoints to Beta
if [[ ${service} == "iaas" ]]; then
mv -f ${dir}/*.json ${ROOT_DIR}/oas/iaasalpha.json
if [[ ${service} == "iaas" ]]; then
mv -f ${dir}/*.json ${ROOT_DIR}/oas/iaasalpha.json
fi
if [[ ${ALLOW_ALPHA} != "true" ]]; then
continue
Expand Down
6 changes: 3 additions & 3 deletions scripts/generate-sdk/languages/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ generate_go_sdk() {
if type -p go >/dev/null; then
:
else
echo "Go not installed, unable to proceed."
echo "! Go not installed, unable to proceed."
exit 1
fi

Expand All @@ -80,7 +80,7 @@ generate_go_sdk() {
# Backup of the current state of the SDK services dir (services/)
sdk_services_backup_dir=$(mktemp -d)
if [[ ! ${sdk_services_backup_dir} || -d {sdk_services_backup_dir} ]]; then
echo "Unable to create temporary directory"
echo "! Unable to create temporary directory"
exit 1
fi
cleanup() {
Expand Down Expand Up @@ -128,7 +128,7 @@ generate_go_sdk() {
exit 1
fi

echo -e "\nGenerating \"${service}\" service..."
echo -e "\n>> Generating \"${service}\" service..."
cd ${ROOT_DIR}

GO_POST_PROCESS_FILE="gofmt -w" \
Expand Down
18 changes: 9 additions & 9 deletions scripts/generate-sdk/languages/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ generate_python_sdk() {

# Check required parameters
if [[ -z ${GIT_HOST} ]]; then
echo "GIT_HOST not specified."
echo "! GIT_HOST not specified."
exit 1
fi

if [[ -z ${GIT_USER_ID} ]]; then
echo "GIT_USER_ID id not specified."
echo "! GIT_USER_ID id not specified."
exit 1
fi

Expand All @@ -46,7 +46,7 @@ generate_python_sdk() {

# Prepare folders
if [[ ! -d $SERVICES_FOLDER ]]; then
mkdir -p "$SERVICES_FOLDER"
mkdir -p "$SERVICES_FOLDER"
fi

# Clone SDK repo
Expand All @@ -63,7 +63,7 @@ generate_python_sdk() {
# Backup of the current state of the SDK services dir (services/)
sdk_services_backup_dir=$(mktemp -d)
if [[ ! ${sdk_services_backup_dir} || -d {sdk_services_backup_dir} ]]; then
echo "Unable to create temporary directory"
echo "! Unable to create temporary directory"
exit 1
fi
cleanup() {
Expand All @@ -75,7 +75,7 @@ generate_python_sdk() {
trap cleanup EXIT

# Remove old contents of services dir (services/)
rm -rf ${SERVICES_FOLDER}
rm -rf ${SERVICES_FOLDER}

# Generate SDK for each service
for service_json in ${ROOT_DIR}/oas/*.json; do
Expand All @@ -89,7 +89,7 @@ generate_python_sdk() {
service=$(echo "${service}" | tr '[:upper:]' '[:lower:]') # convert upper case letters to lower case
service=$(echo "${service}" | tr -d -c '[:alnum:]') # remove non-alphanumeric characters

echo "Generating \"${service}\" service..."
echo ">> Generating \"${service}\" service..."
cd ${ROOT_DIR}

mkdir -p "${SERVICES_FOLDER}/${service}/"
Expand All @@ -113,11 +113,11 @@ generate_python_sdk() {
rm -r "${SERVICES_FOLDER}/${service}/.openapi-generator/"
rm "${SERVICES_FOLDER}/${service}/stackit/__init__.py"
rm "${SERVICES_FOLDER}/${service}/.github/workflows/python.yml"

# Create source layout
mkdir "${SERVICES_FOLDER}/${service}/src"
mv "${SERVICES_FOLDER}/${service}/stackit/" "${SERVICES_FOLDER}/${service}/src/"

# If the service has a wait package files, move them inside the service folder
if [ -d ${sdk_services_backup_dir}/${service}/src/wait ]; then
echo "Found ${service} \"wait\" package"
Expand Down Expand Up @@ -165,6 +165,6 @@ generate_python_sdk() {
isort .
autoimport --ignore-init-modules .
black .

done
}
4 changes: 2 additions & 2 deletions scripts/project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ elif [ "$action" = "tools" ]; then
elif [ "${LANGUAGE}" == "python" ]; then
pip install black==24.8.0 isort~=5.13.2 autoimport~=1.6.1
else
echo "Invalid language: `$LANGUAGE`, please use $0 help for help"
echo "! Invalid language: $($LANGUAGE), please use $0 help for help"
fi
else
echo "Invalid action: '$action', please use $0 help for help"
echo "! Invalid action: '$action', please use $0 help for help"
fi
9 changes: 6 additions & 3 deletions scripts/sdk-create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ for service_path in ${work_dir}/sdk_to_push/services/*; do
service_changes=$(git status --porcelain "services/$service")

if [[ -n "$service_changes" ]]; then
echo "Committing changes for $service"
if [[ "$BRANCH_PREFIX" != "main" ]]; then
git switch main # This is needed to create a new branch for the service without including the previously committed files
branch="$BRANCH_PREFIX/$service"
Expand All @@ -99,17 +98,21 @@ for service_path in ${work_dir}/sdk_to_push/services/*; do
fi

if [[ "$branch" != "main" ]]; then
echo ">> Creating PR for $service"

git commit -m "Generate $service"
git push origin "$branch"
gh pr create --title "Generator: Update SDK /services/$service" --body "$COMMIT_INFO" --head "$branch" --base "main"
else
echo ">> Pushing changes for $service service..."

# If lint or test fails for a service, we skip it and continue to the next one
make lint skip-non-generated-files=true service=$service || {
echo "Linting failed for service: $service"
echo "! Linting failed for $service"
continue
}
make test skip-non-generated-files=true service=$service || {
echo "Testing failed for service: $service"
echo "! Testing failed for $service"
continue
}

Expand Down

0 comments on commit 45fcbf1

Please sign in to comment.