diff --git a/.github/actions/bump_version/action.yml b/.github/actions/bump_version/action.yml new file mode 100644 index 00000000..e851aa86 --- /dev/null +++ b/.github/actions/bump_version/action.yml @@ -0,0 +1,22 @@ +name: 'Bump Versions' +description: 'This action bumps versions of Cargo.toml and _version.py file, matching release tag' + +runs: + using: 'composite' + steps: + - name: Check out the code + uses: actions/checkout@v4 + + - name: Bump Cargo version + # python ./cargo_version_bumper.py --target Cargo.toml "${{ github.ref_name }}" + run: | + python ./cargo_version_bumper.py --target Cargo.toml "0.0.1" + shell: python3 + +# - name: Check Cargo.toml version matches Release tag +# run: | +# CARGO_VERSION=$(grep '^version =' Cargo.toml | sed 's/.*"\(.*\)".*/\1/') +# if [ "${GITHUB_REF#refs/tags/}" != "$CARGO_VERSION" ]; then +# echo "Version mismatch: Cargo.toml ($CARGO_VERSION) doesn't match Release tag (${GITHUB_REF#refs/tags/})" +# exit 1 +# fi \ No newline at end of file diff --git a/.github/actions/bump_version/cargo_version_bumper.py b/.github/actions/bump_version/cargo_version_bumper.py new file mode 100644 index 00000000..d10d763c --- /dev/null +++ b/.github/actions/bump_version/cargo_version_bumper.py @@ -0,0 +1,40 @@ +# From https://github.com/Intreecom/scyllapy/blob/05fdab32dd7468c26533de5fdfe9627fa3e38445/scripts/version_bumper.py + +import argparse +import re +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/build_wheels.yml b/.github/workflows/build_wheels.yml index 5a79e7d3..37715aa0 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -2,6 +2,12 @@ name: Build Wheels on: workflow_call: + inputs: + auto_bump: + description: 'Bump version automatically' + type: boolean + required: false + default: false jobs: linux: @@ -35,6 +41,10 @@ jobs: sudo apt update sudo apt install pkg-config gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -qy + - name: Bump Cargo version + if: ${{ inputs.auto_bump }} + uses: ./.github/actions/bump_version + - uses: dtolnay/rust-toolchain@master with: toolchain: stable @@ -95,6 +105,10 @@ jobs: run: | choco install nasm + - name: Bump Cargo version + if: ${{ inputs.auto_bump }} + uses: ./.github/actions/bump_version + - uses: dtolnay/rust-toolchain@master with: toolchain: stable @@ -158,6 +172,10 @@ jobs: - name: Set macOS version run: echo "MACOSX_DEPLOYMENT_TARGET=${{ matrix.platform.macos_version }}" >> $GITHUB_ENV + - name: Bump Cargo version + if: ${{ inputs.auto_bump }} + uses: ./.github/actions/bump_version + - uses: dtolnay/rust-toolchain@master with: toolchain: stable @@ -192,15 +210,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' + + - name: Bump Cargo version + if: ${{ inputs.auto_bump }} + uses: ./.github/actions/bump_version + - name: Build sdist with Maturin uses: PyO3/maturin-action@v1 with: command: sdist args: --out dist + - uses: actions/upload-artifact@v4 with: path: dist/*.tar.gz diff --git a/.github/workflows/release_pypi.yaml b/.github/workflows/release_pypi.yaml index 14fbd413..7550d5e9 100644 --- a/.github/workflows/release_pypi.yaml +++ b/.github/workflows/release_pypi.yaml @@ -9,9 +9,12 @@ on: branches: [main] jobs: - build_wheels: + build_wheels: + # TODO: switch to main uses: dottxt-ai/outlines-core/.github/workflows/build_wheels.yml@maturin - + with: + auto_bump: true + release: needs: build_wheels name: Release to PyPI