From df86885867e14660d56ffd8ea25dd613c00e2a9d Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Sun, 24 Nov 2024 20:37:18 +0900 Subject: [PATCH] feat: ci. --- .github/workflows/release_python.yml | 10 ++++++++++ python/set_version.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 python/set_version.py diff --git a/.github/workflows/release_python.yml b/.github/workflows/release_python.yml index 449b775f..faa13bbe 100644 --- a/.github/workflows/release_python.yml +++ b/.github/workflows/release_python.yml @@ -35,6 +35,8 @@ jobs: target: ppc64le steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: python python/set_version.py - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -63,6 +65,8 @@ jobs: target: armv7 steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: python python/set_version.py - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -87,6 +91,8 @@ jobs: target: x86 steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: python python/set_version.py - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -110,6 +116,8 @@ jobs: target: aarch64 steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: python python/set_version.py - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -126,6 +134,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: python python/set_version.py - name: Build sdist uses: PyO3/maturin-action@v1 with: diff --git a/python/set_version.py b/python/set_version.py new file mode 100644 index 00000000..86934139 --- /dev/null +++ b/python/set_version.py @@ -0,0 +1,16 @@ +import os +from pathlib import Path + +project_root = Path(__file__).parents[1].absolute() + +pyproject_toml_path = project_root / "pyproject.toml" + +with open(pyproject_toml_path, "r") as f: + contents = f.read() + +with open(pyproject_toml_path, "w") as f: + if (github_ref := os.getenv("GITHUB_REF")) and github_ref.startswith("refs/tags/"): + version = github_ref.replace("refs/tags/v", "") + contents = contents.replace('version = "0.0.0"', f'version = "{version}"') + + f.write(contents)