Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PULP-215] Core version dependence #104

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 45 additions & 14 deletions gen-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,58 @@ then
exit 1
fi

normalize_version ()
{
python3 -c '
import sys
from packaging.version import Version

print(Version(sys.stdin.read()))
'
}

generator_version ()
{
python3 -c '
import sys
from packaging.version import Version

language = sys.argv[1]
core_version = Version(sys.stdin.read())

if language.lower() == "python":
print("v4.3.1")
elif language.lower() == "ruby":
print("v4.3.1")
elif language.lower() == "typescript":
print("v5.2.1")
else:
exit(1)
' "$@"
}

API_SPEC="$1"
COMPONENT="$2"
LANGUAGE="${3:-python}"
PACKAGE="${4:-pulp_${COMPONENT//-/_}}"

DOMAIN_ENABLED="$(jq -r '.info."x-pulp-domain-enabled" // false' < "${API_SPEC}")"
VERSION="$(jq -r --arg component "$COMPONENT" '.info."x-pulp-app-versions"[$component] // error("No version found.")' < "${API_SPEC}")"
echo "Unnormalized Version: ${VERSION}"
VERSION="$(python3 -c "from packaging.version import Version; print(Version('${VERSION}'))")"
echo "Version: ${VERSION}"
VERSION="$(jq -r --arg component "${COMPONENT}" '.info."x-pulp-app-versions"[$component] // error("No version found.")' < "${API_SPEC}" | normalize_version)"
CORE_VERSION="$(jq -r '.info."x-pulp-app-versions".core // "0.0.0"' < "${API_SPEC}" | normalize_version)"
GENERATOR_VERSION="$(generator_version "${LANGUAGE}" <<<"${CORE_VERSION}")"
IMAGE_OVERRIDE_VAR="OPENAPI_${LANGUAGE^^}_IMAGE"
OPENAPI_IMAGE="${!IMAGE_OVERRIDE_VAR:-docker.io/openapitools/openapi-generator-cli:${GENERATOR_VERSION}}"
IMAGE_TAG="${OPENAPI_IMAGE#*:}"

OPENAPI_PYTHON_IMAGE="${OPENAPI_PYTHON_IMAGE:-docker.io/openapitools/openapi-generator-cli:v4.3.1}"
OPENAPI_RUBY_IMAGE="${OPENAPI_RUBY_IMAGE:-docker.io/openapitools/openapi-generator-cli:v4.3.1}"
OPENAPI_TYPESCRIPT_IMAGE="${OPENAPI_TYPESCRIPT_IMAGE:-docker.io/openapitools/openapi-generator-cli:v5.2.1}"
echo "${COMPONENT}: ${VERSION} core: ${CORE_VERSION} domains: ${DOMAIN_ENABLED} generator: ${GENERATOR_VERSION}"
echo "Using: ${OPENAPI_IMAGE}"

if command -v podman > /dev/null
then
CONTAINER_EXEC=podman
if [[ -n "${PULP_MCS_LABEL:-}" ]]
then
USER_COMMAND=("--userns=keep-id" "--security-opt" "label=level:$PULP_MCS_LABEL")
USER_COMMAND=("--userns=keep-id" "--security-opt" "label=level:${PULP_MCS_LABEL}")
else
USER_COMMAND=("--userns=keep-id")
fi
Expand All @@ -38,7 +69,7 @@ else
CONTAINER_EXEC=docker
if [[ -n "${PULP_MCS_LABEL:-}" ]]
then
USER_COMMAND=("-u" "$(id -u)" "--security-opt" "label=level:$PULP_MCS_LABEL")
USER_COMMAND=("-u" "$(id -u)" "--security-opt" "label=level:${PULP_MCS_LABEL}")
else
USER_COMMAND=("-u" "$(id -u)")
fi
Expand Down Expand Up @@ -76,12 +107,12 @@ then
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_PYTHON_IMAGE" generate \
"${OPENAPI_IMAGE}" generate \
-i "${VOLUME_DIR}/patched-api.json" \
-g python \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
"--additional-properties=packageName=pulpcore.client.${PACKAGE},projectName=${PACKAGE}-client,packageVersion=${VERSION},domainEnabled=${DOMAIN_ENABLED}" \
-t "${VOLUME_DIR}/templates/python" \
-t "${VOLUME_DIR}/templates/python/${IMAGE_TAG}" \
--skip-validate-spec \
--strict-spec=false
cp python/__init__.py "${PACKAGE}-client/pulpcore/"
Expand All @@ -101,13 +132,13 @@ then
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_RUBY_IMAGE" generate \
"${OPENAPI_IMAGE}" generate \
-i "${VOLUME_DIR}/patched-api.json" \
-g ruby \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
"--additional-properties=gemName=${PACKAGE}_client,gemLicense="GPLv2+",gemVersion=${VERSION},gemHomepage=https://github.com/pulp/${PACKAGE}" \
--library=faraday \
-t "${VOLUME_DIR}/templates/ruby" \
-t "${VOLUME_DIR}/templates/ruby/${IMAGE_TAG}" \
--skip-validate-spec \
--strict-spec=false
fi
Expand All @@ -121,7 +152,7 @@ then
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_TYPESCRIPT_IMAGE" generate \
"${OPENAPI_TYPESCRIPT_IMAGE}" generate \
-i "${VOLUME_DIR}/patched-api.json" \
-g typescript-axios \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading