diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES deleted file mode 100644 index 89f65b2..0000000 --- a/.openapi-generator/FILES +++ /dev/null @@ -1,187 +0,0 @@ -.gitignore -.gitlab-ci.yml -.openapi-generator-ignore -.travis.yml -README.md -docs/AccountRecovery.md -docs/AccountRegistration.md -docs/AccountReset.md -docs/AdminProjectManagementApi.md -docs/AdminUserManagementApi.md -docs/Artifact.md -docs/ArtifactApi.md -docs/ArtifactList.md -docs/CreateToken.md -docs/Credentials.md -docs/Dashboard.md -docs/DashboardApi.md -docs/DashboardList.md -docs/GetReportTypes200ResponseInner.md -docs/Group.md -docs/GroupApi.md -docs/GroupList.md -docs/Health.md -docs/HealthApi.md -docs/HealthInfo.md -docs/ImportApi.md -docs/LoginApi.md -docs/LoginConfig.md -docs/LoginError.md -docs/LoginSupport.md -docs/LoginToken.md -docs/ModelImport.md -docs/Pagination.md -docs/Project.md -docs/ProjectApi.md -docs/ProjectList.md -docs/Report.md -docs/ReportApi.md -docs/ReportList.md -docs/ReportParameters.md -docs/Result.md -docs/ResultApi.md -docs/ResultList.md -docs/Run.md -docs/RunApi.md -docs/RunList.md -docs/TaskApi.md -docs/Token.md -docs/TokenList.md -docs/UpdateRun.md -docs/User.md -docs/UserApi.md -docs/UserList.md -docs/WidgetApi.md -docs/WidgetConfig.md -docs/WidgetConfigApi.md -docs/WidgetConfigList.md -docs/WidgetParam.md -docs/WidgetType.md -docs/WidgetTypeList.md -git_push.sh -ibutsu_client/__init__.py -ibutsu_client/api/__init__.py -ibutsu_client/api/admin_project_management_api.py -ibutsu_client/api/admin_user_management_api.py -ibutsu_client/api/artifact_api.py -ibutsu_client/api/dashboard_api.py -ibutsu_client/api/group_api.py -ibutsu_client/api/health_api.py -ibutsu_client/api/import_api.py -ibutsu_client/api/login_api.py -ibutsu_client/api/project_api.py -ibutsu_client/api/report_api.py -ibutsu_client/api/result_api.py -ibutsu_client/api/run_api.py -ibutsu_client/api/task_api.py -ibutsu_client/api/user_api.py -ibutsu_client/api/widget_api.py -ibutsu_client/api/widget_config_api.py -ibutsu_client/api_client.py -ibutsu_client/apis/__init__.py -ibutsu_client/configuration.py -ibutsu_client/exceptions.py -ibutsu_client/model/__init__.py -ibutsu_client/model/account_recovery.py -ibutsu_client/model/account_registration.py -ibutsu_client/model/account_reset.py -ibutsu_client/model/artifact.py -ibutsu_client/model/artifact_list.py -ibutsu_client/model/create_token.py -ibutsu_client/model/credentials.py -ibutsu_client/model/dashboard.py -ibutsu_client/model/dashboard_list.py -ibutsu_client/model/get_report_types200_response_inner.py -ibutsu_client/model/group.py -ibutsu_client/model/group_list.py -ibutsu_client/model/health.py -ibutsu_client/model/health_info.py -ibutsu_client/model/login_config.py -ibutsu_client/model/login_error.py -ibutsu_client/model/login_support.py -ibutsu_client/model/login_token.py -ibutsu_client/model/model_import.py -ibutsu_client/model/pagination.py -ibutsu_client/model/project.py -ibutsu_client/model/project_list.py -ibutsu_client/model/report.py -ibutsu_client/model/report_list.py -ibutsu_client/model/report_parameters.py -ibutsu_client/model/result.py -ibutsu_client/model/result_list.py -ibutsu_client/model/run.py -ibutsu_client/model/run_list.py -ibutsu_client/model/token.py -ibutsu_client/model/token_list.py -ibutsu_client/model/update_run.py -ibutsu_client/model/user.py -ibutsu_client/model/user_list.py -ibutsu_client/model/widget_config.py -ibutsu_client/model/widget_config_list.py -ibutsu_client/model/widget_param.py -ibutsu_client/model/widget_type.py -ibutsu_client/model/widget_type_list.py -ibutsu_client/model_utils.py -ibutsu_client/models/__init__.py -ibutsu_client/rest.py -requirements.txt -setup.cfg -setup.py -test-requirements.txt -test/__init__.py -test/test_account_recovery.py -test/test_account_registration.py -test/test_account_reset.py -test/test_admin_project_management_api.py -test/test_admin_user_management_api.py -test/test_artifact.py -test/test_artifact_api.py -test/test_artifact_list.py -test/test_create_token.py -test/test_credentials.py -test/test_dashboard.py -test/test_dashboard_api.py -test/test_dashboard_list.py -test/test_get_report_types200_response_inner.py -test/test_group.py -test/test_group_api.py -test/test_group_list.py -test/test_health.py -test/test_health_api.py -test/test_health_info.py -test/test_import_api.py -test/test_login_api.py -test/test_login_config.py -test/test_login_error.py -test/test_login_support.py -test/test_login_token.py -test/test_model_import.py -test/test_pagination.py -test/test_project.py -test/test_project_api.py -test/test_project_list.py -test/test_report.py -test/test_report_api.py -test/test_report_list.py -test/test_report_parameters.py -test/test_result.py -test/test_result_api.py -test/test_result_list.py -test/test_run.py -test/test_run_api.py -test/test_run_list.py -test/test_task_api.py -test/test_token.py -test/test_token_list.py -test/test_update_run.py -test/test_user.py -test/test_user_api.py -test/test_user_list.py -test/test_widget_api.py -test/test_widget_config.py -test/test_widget_config_api.py -test/test_widget_config_list.py -test/test_widget_param.py -test/test_widget_type.py -test/test_widget_type_list.py -tox.ini diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION deleted file mode 100644 index 5fe6072..0000000 --- a/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -6.0.1 diff --git a/regenerate-client.sh b/regenerate-client.sh index 48fdebc..9114a95 100755 --- a/regenerate-client.sh +++ b/regenerate-client.sh @@ -1,28 +1,68 @@ #!/usr/bin/env bash +set -euo pipefail #### # Re-generate the client based on the spec +# Configuration +OPENAPI_GENERATOR_VERSION="7.15.0" CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +TEMP_DIR="${CLIENT_DIR}/tmp/client" OPENAPI_FILE="" -CAN_COMMIT=false -CAN_PUSH=false -CAN_DELETE=false -CURRENT_VERSION=`cat setup.py | grep 'VERSION =' | cut -d\" -f2` -if [[ "$NEW_VERSION" == "" ]]; then - # If there's no new version defined externally, generate a new version - NEW_VERSION="${CURRENT_VERSION%.*}.$((${CURRENT_VERSION##*.}+1))" -fi + +# Version extraction function +get_versions() { + # Use hatch to get the current version - fail if hatch is not available or can't read version + if ! command -v hatch >/dev/null 2>&1; then + echo "Error: hatch is required to read the project version" + echo "Please install hatch: pip install hatch" + exit 1 + fi + + CURRENT_VERSION=$(hatch version 2>/dev/null) + if [[ $? -ne 0 ]] || [[ -z "$CURRENT_VERSION" ]]; then + echo "Error: Failed to read version using 'hatch version'" + echo "Make sure you're in the project root and hatch is properly configured" + exit 1 + fi + + if [[ "${NEW_VERSION:-}" == "" ]]; then + # If there's no new version defined externally, generate a new version + # Handle version formats like "2.3.0" or "2.3.0.d20250918" + if [[ "$CURRENT_VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+) ]]; then + BASE_VERSION="${BASH_REMATCH[1]}" + PATCH_VERSION="${BASE_VERSION##*.}" + NEW_PATCH=$((PATCH_VERSION + 1)) + NEW_VERSION="${BASE_VERSION%.*}.$NEW_PATCH" + else + echo "Error: Unexpected version format: $CURRENT_VERSION" + exit 1 + fi + fi +} + +# Check dependencies +function check_dependencies() { + if ! command -v podman >/dev/null 2>&1; then + echo "Error: Podman is required for consistent OpenAPI generation" + echo "Please install Podman from https://podman.io/getting-started/installation" + exit 1 + fi + # Note: hatch requirement is checked in get_versions() function +} function print_usage() { - echo "Usage: regenerate-client.sh [-h|--help] [-c|--commit] [-p|--push] [-d|--delete] OPENAPI_FILE" + echo "Usage: regenerate-client.sh [-h|--help] [-v|--version] OPENAPI_FILE" echo "" echo "optional arguments:" echo " -h, --help show this help message" echo " -v, --version show the prospective new version number" - echo " -c, --commit create a new branch and commit all the changes" - echo " -p, --push push the branch up to origin after commit" - echo " -d, --delete delete the branch after pushing" echo "" + echo "This script regenerates the client on the current branch and leaves" + echo "uncommitted changes in the working tree after running pre-commit." + echo "" + echo "Requirements:" + echo " - Podman (for consistent OpenAPI generation)" + echo " - hatch (required for version management)" } # Check if there were no arguments @@ -40,21 +80,11 @@ while (( "$#" )); do exit 0 ;; -v|--version) + get_versions + echo "Current version: $CURRENT_VERSION" echo "Prospective version number: $NEW_VERSION" exit 0 ;; - -c|--commit) - CAN_COMMIT=true - shift - ;; - -p|--push) - CAN_PUSH=true - shift - ;; - -d|--delete) - CAN_PUSH=true - shift - ;; -*|--*) echo "Error: unsupported option $1" >&2 exit 1 @@ -66,65 +96,91 @@ while (( "$#" )); do esac done -# Check if the files exist +# Initialize versions +get_versions + +# Check dependencies +check_dependencies + +# Check if the OpenAPI file exists if [[ ! $OPENAPI_FILE == http* ]] && [[ ! -f "$OPENAPI_FILE" ]]; then echo "Error: No OpenAPI file or incorrect path to file" exit 1 fi -if [[ ! -x "$(command -v openapi-generator-cli)" ]]; then - echo "Error: openapi-generator-cli is not installed. Please see https://openapi-generator.tech/" - exit 2 -fi -# Generate the client -echo -n "Generating client..." -openapi-generator-cli generate -o /tmp/client -g python --package-name ibutsu_client \ - --git-repo-id ibutsu-client-python --git-user-id ibutsu \ - --global-property skipFormModel=true -p packageVersion=$NEW_VERSION \ +# Generate the client using Podman +echo "Generating client with OpenAPI Generator v${OPENAPI_GENERATOR_VERSION}..." +mkdir -p "$(dirname "${TEMP_DIR}")" + +podman run --rm \ + -v "${CLIENT_DIR}:/local" \ + "openapitools/openapi-generator-cli:v${OPENAPI_GENERATOR_VERSION}" \ + generate \ + -i "/local/${OPENAPI_FILE}" \ + -g python \ + -o "/local/tmp/client" \ + --package-name ibutsu_client \ + --git-repo-id ibutsu-client-python \ + --git-user-id ibutsu \ + --global-property skipFormModel=true \ + -p packageVersion="${NEW_VERSION}" \ -p packageUrl=https://github.com/ibutsu/ibutsu-client-python \ - -i $OPENAPI_FILE > $CLIENT_DIR/generate.log 2>&1 + -p pythonVersion=3.8 \ + -p generateSourceCodeOnly=false \ + -p library=urllib3 \ + > "${CLIENT_DIR}/generate.log" 2>&1 + if [ $? -ne 0 ]; then - echo "error" - echo "Error: Generating client failed. Please see $CLIENT_DIR/generate.log for errors" + echo "Error: Client generation failed. Please see ${CLIENT_DIR}/generate.log for details" exit 3 fi -echo "done" +echo "Client generation completed successfully" + +# Clean up and modify generated files +echo "Processing generated files..." -# Modify various files -cat <> /tmp/client/.gitignore +# Remove unwanted generated files +rm -f "${TEMP_DIR}/git_push.sh" +rm -f "${TEMP_DIR}/.travis.yml" + +# Add custom .gitignore entries +cat >> "${TEMP_DIR}/.gitignore" << 'EOF' # Virtual environment .ibutsu-env EOF -rm /tmp/client/git_push.sh -rm .travis.yml - -# Copy all the files -find $CLIENT_DIR -not -path $CLIENT_DIR -not -path "$CLIENT_DIR/.git/*" -not -name '.git' \ - -not -path "$CLIENT_DIR/.github/*" -not -name '.github' \ - -not -path "$CLIENT_DIR/.ibutsu-env/*" -not -name '.ibutsu-env' \ - -not -name 'regenerate-client.sh' -not -name 'LICENSE' \ - -exec rm -fr {} + -cp -r /tmp/client/. $CLIENT_DIR - -# Clean up afterward -rm -fr /tmp/client - -# Commit everything -if [[ "$CAN_COMMIT" = true ]]; then - echo -n "Committing code..." - BRANCH_NAME="regenerate-$NEW_VERSION" - git checkout -b $BRANCH_NAME > /dev/null 2>&1 - git add . > /dev/null 2>&1 - git commit -q -m "Regenerated client" - echo "done, new branch created: $BRANCH_NAME" - if [[ "$CAN_PUSH" = true ]]; then - echo -n "Pushing up to origin/$BRANCH_NAME..." - git push -q origin $BRANCH_NAME - git checkout master - if [[ "$CAN_DELETE" = true ]]; then - git branch -D $BRANCH_NAME - echo "Deleted branch $BRANCH_NAME" - fi - fi + +# Copy generated files while preserving important directories +echo "Copying generated files..." +# Remove old generated content but preserve important directories and files +find "${CLIENT_DIR}" -mindepth 1 -maxdepth 1 \ + ! -name '.git' \ + ! -name '.github' \ + ! -name '.ibutsu-env' \ + ! -name 'regenerate-client.sh' \ + ! -name 'LICENSE' \ + ! -name 'tmp' \ + -exec rm -rf {} + + +# Copy new generated content +cp -r "${TEMP_DIR}"/. "${CLIENT_DIR}/" + +# Clean up temporary directory +rm -rf "${CLIENT_DIR}/tmp" +echo "File processing completed" + +# Post-processing: run formatting and linting if available +echo "Running post-processing..." +if command -v hatch >/dev/null 2>&1; then + echo "Running code formatting and linting..." + cd "${CLIENT_DIR}" + hatch run pre-commit run --all-files || echo "Pre-commit hooks completed with some issues (normal for generated code)" +else + echo "Hatch not available, skipping code formatting" fi + +echo "" +echo "🎉 Client regeneration completed successfully!" +echo " Version: $NEW_VERSION" +echo " OpenAPI Generator: v$OPENAPI_GENERATOR_VERSION" +echo " Working tree contains uncommitted changes for review"