Skip to content

Commit

Permalink
Add reusable bump version action
Browse files Browse the repository at this point in the history
  • Loading branch information
torymur committed Feb 14, 2025
1 parent 9c11667 commit dda7b55
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/actions/bump_version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Bump Versions'
description: 'This action bumps versions of Cargo.toml and _version.py file, matching release tag'

runs:
using: 'composite'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Bump Cargo version
# python ./cargo_version_bumper.py --target Cargo.toml "${{ github.ref_name }}"
run: |
python ./actions/bump_version/cargo_version_bumper.py --target Cargo.toml "0.0.1"
shell: bash

# - 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
40 changes: 40 additions & 0 deletions .github/actions/bump_version/cargo_version_bumper.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 25 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release_pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dda7b55

Please sign in to comment.