diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..d9422e9 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,74 @@ +name: Publish Python Package to PyPI +on: + workflow_dispatch: +# push: +# branches: +# - main + +jobs: + build: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get-version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@v7 + + - name: Setup uv + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d + + - name: Get version from pyproject.toml + id: get-version + run: | + VERSION=$(python setup.py --version) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Found version: $VERSION" + + - name: Build package + run: uv build + + - name: Upload build artifacts + uses: actions/upload-artifact@v7 + with: + name: python-package-distributions + path: dist/ + + create-release: + runs-on: ubuntu-latest + needs: build + permissions: + contents: write + steps: + - name: Checkout repo + uses: actions/checkout@v7 + + - name: Download build artifacts + uses: actions/download-artifact@v8 + with: + name: python-package-distributions + path: dist/ + + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "v${{ needs.build.outputs.version }}" \ + --title "Release v${{ needs.build.outputs.version }}" \ + --draft=false \ + --prerelease=false + + publish: + runs-on: ubuntu-latest + needs: [build, create-release] + permissions: + # IMPORTANT: this permission is mandatory for Trusted Publishing + id-token: write + steps: + - name: Download build artifacts + uses: actions/download-artifact@v8 + with: + name: python-package-distributions + path: dist/ + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..df462be --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,18 @@ +name: Run Tests + +on: + pull_request: + workflow_dispatch: + +jobs: + check_test_all: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v7 + + - name: Setup uv + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d + + - name: Run tests + run: uv run python -m unittest discover --start-directory tests diff --git a/README.md b/README.md index f7923d4..9c30356 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ solemn Run via: `$ python setup.py test` (or `$ python tests/tests.py`) ## Build +A GitHub Action exists for this at: [.github/workflows/publish.yaml](.github/workflows/publish.yaml) + +Alternatively build and publish manually with: + - `$ python setup.py sdist bdist_wheel` - `$ twine upload dist/* -r testpypi --skip-existing` assuming twine is installed and *~/.pypirc* exists with something like: ``` diff --git a/setup.py b/setup.py index be7ee7c..5d62bb5 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def test_suite(): setup( name='Vose-Alias-Method', - version='1.2.1', + version='1.2.2', description=('Python implementation of Vose\'s alias method, an efficient algorithm for sampling from a discrete probability distribution.'), long_description=long_description, long_description_content_type='text/markdown',