diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..a75cff8 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +exclude = abi +ignore = W, E, F \ No newline at end of file diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 0000000..18d0807 --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -0,0 +1,109 @@ +name: publish package to PyPi + +on: + workflow_dispatch: + inputs: + version_type: + type: choice + description: version to be published + options: + - major + - minor + - patch + +jobs: + Timestamp: + uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main + + lint: + needs: Timestamp + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 + + - name: Run flake8 + run: | + flake8 . + + build: + needs: [Timestamp, lint] + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["pypy3.9", "pypy3.10", "3.9", "3.10", "3.11", "3.12"] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install -r requirements.txt + python -m pip install --upgrade pip + pip install setuptools wheel + + - name: Build package + run: python setup.py sdist bdist_wheel + + publish: + needs: [Timestamp, build, lint] + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + pip install -r requirements.txt + python -m pip install --upgrade pip + pip install setuptools wheel + + - name: Change version number + env: + VERSION_TYPE: ${{ github.event.inputs.version_type }} + run: python update_version.py + + - name: Commit version change + run: | + git add setup.py + git config --global user.name 'GitHub Actions Bot' + git config --global user.email 'actions@github.com' + git commit -m "Update version" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: main + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@v1.8.14 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/setup.py b/setup.py index 44c04b6..10575e2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='story_protocol_python_sdk', - version='0.2.1', + version='0.1.7', packages=find_packages(where='src', exclude=["tests"]), package_dir={'': 'src'}, install_requires=[ diff --git a/update_version.py b/update_version.py new file mode 100644 index 0000000..c4a4b27 --- /dev/null +++ b/update_version.py @@ -0,0 +1,26 @@ +import re, os +from setuptools import setup + +version_type = os.getenv('VERSION_TYPE') + +with open('setup.py', 'r') as f: + setup_py = f.read() + +version = re.search(r"version='(\d+\.\d+\.\d+)'", setup_py).group(1) +major, minor, patch = map(int, version.split('.')) + +if version_type == 'major': + major += 1 + minor = 0 + patch = 0 +elif version_type == 'minor': + minor += 1 + patch = 0 +elif version_type == 'patch': + patch += 1 + +new_version = f"{major}.{minor}.{patch}" + +with open('setup.py', 'w') as f: + f.write(re.sub(r"version='(\d+\.\d+\.\d+)'", f"version='{new_version}'", setup_py)) +