Skip to content

Commit 8754268

Browse files
committed
Add reusable bump version action
1 parent f337191 commit 8754268

File tree

6 files changed

+96
-7
lines changed

6 files changed

+96
-7
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Bump Versions'
2+
description: 'This action bumps versions of Cargo.toml and _version.py file, matching release tag'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- uses: actions/checkout@v4
8+
9+
- name: Bump Cargo version
10+
# python ./cargo_version_bumper.py --target Cargo.toml "${{ github.ref_name }}"
11+
run: |
12+
python .github/actions/bump_version/cargo_version_bumper.py --target Cargo.toml "0.0.1"
13+
shell: bash
14+
15+
# - name: Check Cargo.toml version matches Release tag
16+
# run: |
17+
# CARGO_VERSION=$(grep '^version =' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
18+
# if [ "${GITHUB_REF#refs/tags/}" != "$CARGO_VERSION" ]; then
19+
# echo "Version mismatch: Cargo.toml ($CARGO_VERSION) doesn't match Release tag (${GITHUB_REF#refs/tags/})"
20+
# exit 1
21+
# fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# From https://github.com/Intreecom/scyllapy/blob/05fdab32dd7468c26533de5fdfe9627fa3e38445/scripts/version_bumper.py
2+
3+
import argparse
4+
import re
5+
from pathlib import Path
6+
7+
8+
def parse_args() -> argparse.Namespace:
9+
"""Parse command line arguments."""
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument(
12+
"--target",
13+
"-t",
14+
dest="target",
15+
type=Path,
16+
default="Cargo.toml",
17+
)
18+
parser.add_argument("version", type=str)
19+
return parser.parse_args()
20+
21+
22+
def main() -> None:
23+
"""Main function."""
24+
args = parse_args()
25+
with args.target.open("r") as f:
26+
contents = f.read()
27+
28+
contents = re.sub(
29+
r"version\s*=\s*\"(.*)\"",
30+
f'version = "{args.version}"',
31+
contents,
32+
count=1,
33+
)
34+
35+
with args.target.open("w") as f:
36+
f.write(contents)
37+
38+
39+
if __name__ == "__main__":
40+
main()

.github/workflows/build_wheels.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Build Wheels
22

33
on:
44
workflow_call:
5+
inputs:
6+
auto_bump:
7+
description: 'Bump version automatically'
8+
type: boolean
9+
required: false
10+
default: false
511

612
jobs:
713
linux:
@@ -35,6 +41,10 @@ jobs:
3541
sudo apt update
3642
sudo apt install pkg-config gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -qy
3743
44+
- name: Bump Cargo version
45+
if: ${{ inputs.auto_bump }}
46+
uses: ./.github/actions/bump_version
47+
3848
- uses: dtolnay/rust-toolchain@master
3949
with:
4050
toolchain: stable
@@ -95,6 +105,10 @@ jobs:
95105
run: |
96106
choco install nasm
97107
108+
- name: Bump Cargo version
109+
if: ${{ inputs.auto_bump }}
110+
uses: ./.github/actions/bump_version
111+
98112
- uses: dtolnay/rust-toolchain@master
99113
with:
100114
toolchain: stable
@@ -158,6 +172,10 @@ jobs:
158172
- name: Set macOS version
159173
run: echo "MACOSX_DEPLOYMENT_TARGET=${{ matrix.platform.macos_version }}" >> $GITHUB_ENV
160174

175+
- name: Bump Cargo version
176+
if: ${{ inputs.auto_bump }}
177+
uses: ./.github/actions/bump_version
178+
161179
- uses: dtolnay/rust-toolchain@master
162180
with:
163181
toolchain: stable
@@ -192,15 +210,22 @@ jobs:
192210
runs-on: ubuntu-latest
193211
steps:
194212
- uses: actions/checkout@v3
213+
195214
- name: Set up Python
196215
uses: actions/setup-python@v4
197216
with:
198217
python-version: '3.10'
218+
219+
- name: Bump Cargo version
220+
if: ${{ inputs.auto_bump }}
221+
uses: ./.github/actions/bump_version
222+
199223
- name: Build sdist with Maturin
200224
uses: PyO3/maturin-action@v1
201225
with:
202226
command: sdist
203227
args: --out dist
228+
204229
- uses: actions/upload-artifact@v4
205230
with:
206231
path: dist/*.tar.gz

.github/workflows/release_pypi.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ on:
99
branches: [main]
1010

1111
jobs:
12-
build_wheels:
12+
build_wheels:
13+
# TODO: switch to main
1314
uses: dottxt-ai/outlines-core/.github/workflows/build_wheels.yml@maturin
14-
15+
with:
16+
auto_bump: true
17+
1518
release:
1619
needs: build_wheels
1720
name: Release to PyPI

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ repos:
3030
- id: mypy
3131
exclude: |
3232
(?x)^(
33-
^examples/|
34-
^tests/|
35-
^benchmarks/
36-
)$
33+
tests/|
34+
benchmarks/|
35+
\.github/
36+
)
3737
- repo: local
3838
hooks:
3939
- id: cargo-fmt

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ addopts = [
6464
]
6565

6666
[tool.mypy]
67-
exclude=["examples", "tests", "benchmarks"]
67+
exclude=["tests", "benchmarks", ".github"]
6868
namespace_packages = true
6969
explicit_package_bases = true
7070

0 commit comments

Comments
 (0)