|
1 | | -@echo off |
2 | | -echo Cel-expr-python release build on Windows |
3 | | -echo TODO(b/507567432): implement release build for windows. |
| 1 | +:: Copyright 2026 Google LLC |
| 2 | +:: |
| 3 | +:: Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +:: you may not use this file except in compliance with the License. |
| 5 | +:: You may obtain a copy of the License at |
| 6 | +:: |
| 7 | +:: http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +:: |
| 9 | +:: Unless required by applicable law or agreed to in writing, software |
| 10 | +:: distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +:: See the License for the specific language governing permissions and |
| 13 | +:: limitations under the License. |
| 14 | +:: |
| 15 | +setlocal enabledelayedexpansion |
| 16 | +:: release_windows.bat |
| 17 | +:: Kokoro entrypoint for Windows Release builds. |
4 | 18 |
|
5 | | -exit /b 0 |
| 19 | +echo === Loading Environment Configuration === |
| 20 | +call "%~dp0set_env_windows.bat" |
| 21 | +if !ERRORLEVEL! NEQ 0 ( |
| 22 | + echo Failed to configure build environment! |
| 23 | + exit /b 1 |
| 24 | +) |
| 25 | + |
| 26 | +set "RELEASE_STATUS=0" |
| 27 | + |
| 28 | +:: If running locally (not on Kokoro), authenticate with gcloud. |
| 29 | +if "%KOKORO_BUILD_ID%" == "" ( |
| 30 | + gcloud auth application-default print-access-token --quiet >nul 2>&1 |
| 31 | + if !ERRORLEVEL! NEQ 0 ( |
| 32 | + gcloud auth application-default login |
| 33 | + ) |
| 34 | +) |
| 35 | + |
| 36 | +echo --- Installing Release Dependencies --- |
| 37 | +!PYTHON_EXE! -m pip install -U keyring keyrings.google-artifactregistry-auth twine cibuildwheel |
| 38 | +if !ERRORLEVEL! NEQ 0 ( |
| 39 | + echo Failed to install dependencies! |
| 40 | + exit /b 1 |
| 41 | +) |
| 42 | + |
| 43 | +:: Use sibling directories for temporary build folders to avoid issues on Windows. |
| 44 | +set "REPO_DIR=..\cel-python-repo-%RANDOM%" |
| 45 | +set "TMP_DIR=..\cel-python-build-%RANDOM%" |
| 46 | +echo Created temporary directories: %REPO_DIR%, %TMP_DIR% |
| 47 | + |
| 48 | +mkdir "%REPO_DIR%" |
| 49 | +mkdir "%TMP_DIR%" |
| 50 | + |
| 51 | +echo --- Cloning Repository --- |
| 52 | +pushd "%REPO_DIR%" |
| 53 | +git clone https://github.com/cel-expr/cel-python.git |
| 54 | +if !ERRORLEVEL! NEQ 0 ( |
| 55 | + echo Failed to clone repository! |
| 56 | + set "RELEASE_STATUS=1" |
| 57 | + popd |
| 58 | + goto cleanup |
| 59 | +) |
| 60 | +cd cel-python |
| 61 | + |
| 62 | +:: Get the latest version tag |
| 63 | +for /f "tokens=*" %%i in ('git tag --sort=-v:refname') do ( |
| 64 | + set "VERSION=%%i" |
| 65 | + goto :got_tag |
| 66 | +) |
| 67 | +:got_tag |
| 68 | +if "%VERSION%" == "" ( |
| 69 | + echo Failed to get version tag! |
| 70 | + set "RELEASE_STATUS=1" |
| 71 | + popd |
| 72 | + goto cleanup |
| 73 | +) |
| 74 | +if "%VERSION:~0,1%" == "v" ( |
| 75 | + set "VERSION=%VERSION:~1%" |
| 76 | +) |
| 77 | +echo Building release for version: %VERSION% |
| 78 | +popd |
| 79 | + |
| 80 | +echo --- Preparing Release in Temp Directory --- |
| 81 | +pushd "%TMP_DIR%" |
| 82 | + |
| 83 | +xcopy /E /I /Y "%REPO_DIR%\cel-python\*.*" . |
| 84 | +if !ERRORLEVEL! NEQ 0 ( |
| 85 | + echo Failed to copy repo contents! |
| 86 | + set "RELEASE_STATUS=1" |
| 87 | + popd |
| 88 | + goto cleanup |
| 89 | +) |
| 90 | + |
| 91 | +xcopy /Y "%REPO_DIR%\cel-python\release\*.*" . |
| 92 | +if !ERRORLEVEL! NEQ 0 ( |
| 93 | + echo Failed to copy release configs! |
| 94 | + set "RELEASE_STATUS=1" |
| 95 | + popd |
| 96 | + goto cleanup |
| 97 | +) |
| 98 | + |
| 99 | +if exist "cel_expr_python\*_test.py" ( |
| 100 | + del /Q "cel_expr_python\*_test.py" |
| 101 | +) |
| 102 | + |
| 103 | +:: Substitute $VERSION in pyproject.toml with the value of VERSION. |
| 104 | +!PYTHON_EXE! -c "import sys; content = open('pyproject.toml').read(); open('pyproject.toml', 'w').write(content.replace('$VERSION', sys.argv[1]))" "%VERSION%" |
| 105 | +if !ERRORLEVEL! NEQ 0 ( |
| 106 | + echo Failed to substitute version in pyproject.toml! |
| 107 | + set "RELEASE_STATUS=1" |
| 108 | + popd |
| 109 | + goto cleanup |
| 110 | +) |
| 111 | + |
| 112 | +echo --- Creating .bazelrc --- |
| 113 | +echo startup --output_user_root=C:/tmp > .bazelrc |
| 114 | +echo startup --host_jvm_args=-Dhttp.nonProxyHosts=bcr.bazel.build^^^|*.bazel.build^^^|storage.googleapis.com^^^|*.googleapis.com^^^|metadata.google.internal^^^|169.254.169.254 >> .bazelrc |
| 115 | +echo startup --host_jvm_args=-Djava.net.preferIPv4Stack=true >> .bazelrc |
| 116 | + |
| 117 | +echo --- Pre-fetching Dependencies for Workarounds --- |
| 118 | +bazel fetch //... |
| 119 | +if !ERRORLEVEL! NEQ 0 ( |
| 120 | + echo Pre-fetch failed, but continuing... |
| 121 | +) |
| 122 | + |
| 123 | +echo --- Applying ANTLR VERSION Collision Fix --- |
| 124 | +for /f "tokens=*" %%i in ('bazel info output_base') do set "OUTPUT_BASE=%%i" |
| 125 | +set "OUTPUT_BASE=!OUTPUT_BASE:/=\!" |
| 126 | +echo Output Base: !OUTPUT_BASE! |
| 127 | + |
| 128 | +set "ANTLR_DIR=!OUTPUT_BASE!\external\antlr4-cpp-runtime+" |
| 129 | +if exist "!ANTLR_DIR!\VERSION" ( |
| 130 | + if not exist "!ANTLR_DIR!\VERSION.txt" ( |
| 131 | + echo Renaming !ANTLR_DIR!\VERSION to VERSION.txt |
| 132 | + ren "!ANTLR_DIR!\VERSION" VERSION.txt |
| 133 | + ) |
| 134 | +) |
| 135 | +if exist "!ANTLR_DIR!\version" ( |
| 136 | + if not exist "!ANTLR_DIR!\version.txt" ( |
| 137 | + echo Renaming !ANTLR_DIR!\version to version.txt |
| 138 | + ren "!ANTLR_DIR!\version" version.txt |
| 139 | + ) |
| 140 | +) |
| 141 | + |
| 142 | +echo --- Running cibuildwheel --- |
| 143 | +if "%CIBWHEEL_BIN%" == "" ( |
| 144 | + set "CIBWHEEL_BIN=!PYTHON_EXE! -m cibuildwheel" |
| 145 | +) |
| 146 | +echo Running cibuildwheel: %CIBWHEEL_BIN% |
| 147 | +%CIBWHEEL_BIN% --platform windows --output-dir dist |
| 148 | +if !ERRORLEVEL! NEQ 0 ( |
| 149 | + echo cibuildwheel failed! |
| 150 | + set "RELEASE_STATUS=1" |
| 151 | + popd |
| 152 | + goto cleanup |
| 153 | +) |
| 154 | + |
| 155 | +echo --- Uploading to OSS Exit Gate --- |
| 156 | +if "%DRY_RUN%" == "true" ( |
| 157 | + echo [DRY RUN] Skipping upload to PyPI exit gate. |
| 158 | +) else ( |
| 159 | + !PYTHON_EXE! -m twine upload --repository-url https://us-python.pkg.dev/oss-exit-gate-prod/cel-expr-python--pypi dist/* |
| 160 | + if !ERRORLEVEL! NEQ 0 ( |
| 161 | + echo Twine upload failed! |
| 162 | + set "RELEASE_STATUS=1" |
| 163 | + popd |
| 164 | + goto cleanup |
| 165 | + ) |
| 166 | +) |
| 167 | + |
| 168 | +popd |
| 169 | +echo cel-expr-python %VERSION% built and uploaded for release by OSS Exit Gate. |
| 170 | + |
| 171 | +:cleanup |
| 172 | +echo Cleaning up directories... |
| 173 | +if exist "%REPO_DIR%" rd /S /Q "%REPO_DIR%" |
| 174 | +if exist "%TMP_DIR%" rd /S /Q "%TMP_DIR%" |
| 175 | + |
| 176 | +if "%RELEASE_STATUS%" NEQ "0" ( |
| 177 | + exit /b %RELEASE_STATUS% |
| 178 | +) |
0 commit comments