From 1e9850ee27d91624b9652f10cfc36a553a208b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Fri, 6 Dec 2024 17:11:05 +0100 Subject: [PATCH] Use a script to automatically set the version in `Cargo.toml` --- .github/scripts/cargo_version_bumper.py | 40 +++++++++++++++++++++++++ .github/workflows/release_pypi.yaml | 5 +++- .github/workflows/release_rust.yaml | 4 +++ Cargo.toml | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .github/scripts/cargo_version_bumper.py diff --git a/.github/scripts/cargo_version_bumper.py b/.github/scripts/cargo_version_bumper.py new file mode 100644 index 00000000..33b86d81 --- /dev/null +++ b/.github/scripts/cargo_version_bumper.py @@ -0,0 +1,40 @@ +# From https://github.com/Intreecom/scyllapy/blob/05fdab32dd7468c26533de5fdfe9627fa3e38445/scripts/version_bumper.py + +import re +import argparse +from pathlib import Path + + +def parse_args() -> argparse.Namespace: + """Parse command line arguments.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--target", + "-t", + dest="target", + type=Path, + default="Cargo.toml", + ) + parser.add_argument("version", type=str) + return parser.parse_args() + + +def main() -> None: + """Main function.""" + args = parse_args() + with args.target.open("r") as f: + contents = f.read() + + contents = re.sub( + r"version\s*=\s*\"(.*)\"", + f'version = "{args.version}"', + contents, + count=1, + ) + + with args.target.open("w") as f: + f.write(contents) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/release_pypi.yaml b/.github/workflows/release_pypi.yaml index 5e29d886..cb04e148 100644 --- a/.github/workflows/release_pypi.yaml +++ b/.github/workflows/release_pypi.yaml @@ -23,6 +23,10 @@ jobs: with: python-version: '3.10' + - name: Bump Cargo version + run: | + python ../.github/scripts/cargo_version_bumper.py --target Cargo.toml "${{ github.ref_name }}" + - name: Set up QEMU if: runner.os == 'Linux' uses: docker/setup-qemu-action@v3 @@ -71,7 +75,6 @@ jobs: CIBW_TEST_COMMAND: python -c "import outlines_core; print(outlines_core.__version__)" CMAKE_PREFIX_PATH: ./dist - - uses: actions/upload-artifact@v3 with: path: ./wheelhouse/*.whl diff --git a/.github/workflows/release_rust.yaml b/.github/workflows/release_rust.yaml index 5aa81ba5..39a59a87 100644 --- a/.github/workflows/release_rust.yaml +++ b/.github/workflows/release_rust.yaml @@ -15,6 +15,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Bump Cargo version + run: | + python ./.github/scripts/cargo_version_bumper.py --target Cargo.toml "${{ github.ref_name }}" + - name: Install Rust uses: actions-rs/toolchain@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 399118a4..5eec7a08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "outlines-core" -version = "0.1.21" +version = "0.0.0" edition = "2021" description = "Structured Generation" license = "Apache-2.0"