From 1f82c224840993d4831f079db438f30cdeb2f9f2 Mon Sep 17 00:00:00 2001 From: asmith26 Date: Fri, 14 Aug 2026 20:48:49 +0100 Subject: [PATCH 1/3] Add GitHub Actions --- .github/workflows/publish.yaml | 74 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 18 +++++++++ README.md | 4 ++ setup.py | 2 +- 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..843c671 --- /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 + + - 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..2197fd5 --- /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 + + - 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', From 58edb206f8f21f10e4af4dddefa83cd0ff4dcc2b Mon Sep 17 00:00:00 2001 From: asmith26 Date: Fri, 14 Aug 2026 20:56:08 +0100 Subject: [PATCH 2/3] Fix astral-sh/setup-uv version --- .github/workflows/publish.yaml | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 843c671..29b9f50 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v7 - name: Setup uv - uses: astral-sh/setup-uv + uses: astral-sh/setup-uv@v10 - name: Get version from pyproject.toml id: get-version diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2197fd5..0684373 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v7 - name: Setup uv - uses: astral-sh/setup-uv + uses: astral-sh/setup-uv@v10 - name: Run tests run: uv run python -m unittest discover --start-directory tests From 34518fe75af1836c6bc67c7c61b9c247e11862a7 Mon Sep 17 00:00:00 2001 From: asmith26 Date: Fri, 14 Aug 2026 20:57:37 +0100 Subject: [PATCH 3/3] Fix astral-sh/setup-uv version --- .github/workflows/publish.yaml | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 29b9f50..d9422e9 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v7 - name: Setup uv - uses: astral-sh/setup-uv@v10 + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d - name: Get version from pyproject.toml id: get-version diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0684373..df462be 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v7 - name: Setup uv - uses: astral-sh/setup-uv@v10 + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d - name: Run tests run: uv run python -m unittest discover --start-directory tests