Skip to content

Commit

Permalink
Refactor/pypi (#62)
Browse files Browse the repository at this point in the history
* 更改pypi的action信息获取方式
  • Loading branch information
Feudalman authored Sep 19, 2024
1 parent 961da4c commit 64b2003
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
with:
python-version: "3.10"

- name: Checkout Version
run: |
echo "VERSION=$(echo $GITHUB_REF | sed -n 's/refs\/tags\/v//p')" >> $GITHUB_ENV
- name: Set Nodejs
uses: actions/setup-node@v4
with:
Expand All @@ -37,5 +41,15 @@ jobs:

run: |
npm run build.release
python -m build
python build_pypi.py
python -m twine upload dist/*
- run: cp dist/*.whl .

- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body: ${{ github.event.head_commit.message }}
files: |
*.whl
13 changes: 13 additions & 0 deletions build_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess
import shutil
import os
import json

# 如果node_modules文件夹存在则不运行npm install
if not os.path.exists("node_modules"):
Expand All @@ -20,5 +21,17 @@
# 如果dist文件夹存在则删除
if os.path.exists("dist"):
shutil.rmtree("dist")

# 设置版本号
version = os.getenv("VERSION")
if not version:
raise ValueError("尚未指定构建版本号,请设置VERSION环境变量,如`export VERSION=0.6.0`")
with open("swanboard/package.json", "r+") as f:
p = json.load(f)
p["version"] = version
f.seek(0)
json.dump(p, f, indent=4)
f.truncate()

# 构建python项目
subprocess.run("python -m build", shell=True)

0 comments on commit 64b2003

Please # to comment.