From f465fe76d587a0616e61325aabb580218f20543d Mon Sep 17 00:00:00 2001 From: KAAANG <79990647+SAKURA-CAT@users.noreply.github.com> Date: Sun, 18 Aug 2024 13:08:04 +0800 Subject: [PATCH] change action --- .github/workflows/publish-to-pypi.yml | 29 +++++++++++++++++---------- build_pypi.py | 11 ++++++++++ swanlab/package.json | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 79f9bbae4..55d1305e6 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -18,6 +18,10 @@ jobs: with: python-version: "3.10" + - name: Checkout Version + run: | + export VERSION=$(echo $GITHUB_REF | sed -n 's/refs\/tags\/v//p') + - name: Install Dependencies run: | pip install -r requirements.txt @@ -30,14 +34,17 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} run: | - python -m build - python -m twine upload dist/* - - # - run: cp dist/*.whl . - # - name: Release - # uses: softprops/action-gh-release@v1 - # if: startsWith(github.ref, 'refs/tags/') - # with: - # body: ${{ github.event.head_commit.message }} - # files: | - # *.whl + python -m build_pypi.py + # python -m twine upload dist/* + + - run: cp dist/*.whl . + + - run: cat swanlab/package.json + + - name: Release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + body: ${{ github.event.head_commit.message }} + files: | + *.whl diff --git a/build_pypi.py b/build_pypi.py index 107d6af6d..c07ac04d5 100644 --- a/build_pypi.py +++ b/build_pypi.py @@ -9,10 +9,21 @@ """ import subprocess import shutil +import json import os # 如果dist文件夹存在则删除 if os.path.exists("dist"): shutil.rmtree("dist") + +# 设置版本号 +version = os.getenv("VERSION") +if not version: + raise ValueError("尚未指定构建版本号") +with open("swanlab/package.json", 'r+') as f: + p = json.load(f) + p["version"] = version + json.dump(p, f, indent=4) + # 构建python项目 subprocess.run("python -m build", shell=True) diff --git a/swanlab/package.json b/swanlab/package.json index da7a952d1..814c1fd62 100644 --- a/swanlab/package.json +++ b/swanlab/package.json @@ -1,6 +1,6 @@ { "name": "swanlab", - "version": "0.3.16", + "version": "development", "description": "", "python": "true" }