Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,77 @@
name: Publish Python 🐍 distributions 📦 to PyPI
name: Publish to PyPI

on:
push:
tags:
- '*'
- '[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+'

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
build:
name: Build and test release distributions
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.12'
- name: Check that the release tag matches the package version
run: |
python - <<'PY'
import os
import tomllib

with open('pyproject.toml', 'rb') as config:
version = tomllib.load(config)['project']['version']
tag = os.environ['GITHUB_REF_NAME']
if tag.removeprefix('v') != version:
raise SystemExit(f'Release tag {tag!r} does not match package version {version!r}.')
PY
- name: Build wheel and source distribution
run: |
python -m pip install build twine
python -m build
python -m twine check --strict dist/*
- name: Test the installed wheel
run: |
python -m pip install dist/*.whl
python -I test.py
- name: Upload checked distributions
id: upload
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python-distributions
path: dist/
if-no-files-found: error

publish:
name: Publish with Trusted Publishing and attestations
if: github.repository == 'Infinitode/ValX'
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write # Request the short-lived PyPI credential and sign the attestations.
# The PyPI Trusted Publisher is registered with its Environment field blank.
steps:
- uses: actions/checkout@master
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install pypa/setuptools
run: >-
python -m
pip install setuptools wheel
- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Update version in setup.py
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
- name: Build a binary wheel
run: >-
python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Download the checked distributions from this run
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ needs.build.outputs.artifact-id }}
path: dist/
digest-mismatch: error
- name: Upload wheel and sdist with PEP 740 publish attestations
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
attestations: true
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test ValX

on:
push:
branches: [main]
pull_request:

permissions:
contents: read # Check out the code to test.

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install ValX
run: python -m pip install .
- name: Test the installed package
run: python -I test.py
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__pycache__
__pycache__/
*.pyc
dist/
build/
*.egg-info/
env/
.venv/
.venv/
42 changes: 34 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ Thank you for considering contributing to **ValX**! Contributions, whether they
Create a fork of this repository to your GitHub account and clone it locally.

2. **Set Up the Environment**
Ensure you have Python 3.6+ installed. You should also install compatible versions of the necessary dependencies for the project.
Use Python 3.10 or newer. In a virtual environment, install ValX for development and run its tests:

3. **Run Tests**
Before making changes, run tests to confirm that everything works.

> [!TIP]
> We sometimes include testing scripts in our projects for easy testing.
```bash
python -m pip install -r requirements.txt
python -m unittest discover -v
```

## How to Contribute

Expand All @@ -25,14 +24,41 @@ Thank you for considering contributing to **ValX**! Contributions, whether they

2. **Make Changes**
- Use clear and descriptive commit messages.
- (Optional) Write tests to show new functionality.
- Add regression tests for bug fixes and tests for new behavior.
- Ensure the code is **readable**. You can learn more about Python code readability here: https://peps.python.org/pep-0008/.

3. **Submit a Pull Request**
- Push your changes to a feature branch in your fork.
- Submit a pull request with a detailed explanation of what you've changed or added.
- Ensure your PR passes all automated tests and adheres to the contribution guidelines.

## Releasing to PyPI

Register a GitHub Actions Trusted Publisher under **Publishing** in [ValX's PyPI project settings](https://pypi.org/manage/projects/):

| PyPI field | Value |
| --- | --- |
| Owner | `Infinitode` |
| Repository name | `ValX` |
| Workflow name | `build_and_publish.yml` |
| Environment name | **Leave blank** (do not enter `None` or `pypi`) |

The publish job deliberately has no GitHub environment and uses OIDC rather than a `PYPI_API_TOKEN`. Limit who can create or change release tags with a GitHub tag ruleset, since there is no environment approval gate.

1. Set the version in `pyproject.toml`, update the README change notes, and merge the reviewed changes.
2. Tag the merged commit and push the tag, for example `git tag v0.2.7` followed by `git push origin v0.2.7`. Use a final `X.Y.Z` or `vX.Y.Z` tag matching the package version.
3. Once the workflow succeeds, open the release's **Security** tab on PyPI. Confirm there is a publish attestation for both the wheel and the source distribution from `Infinitode/ValX` and `build_and_publish.yml`. Avoid separate manual uploads, which would not inherit those attestations.

To verify the signatures against this repository, use `pypi-attestations` after the release is live (substitute the actual version):

```bash
python -m pip install pypi-attestations
pypi-attestations verify pypi --repository https://github.com/Infinitode/ValX pypi:valx-0.2.7-py3-none-any.whl
pypi-attestations verify pypi --repository https://github.com/Infinitode/ValX pypi:valx-0.2.7.tar.gz
```

After the first verified OIDC release, remove the unused `PYPI_API_TOKEN` secret from GitHub and revoke the old token on PyPI if nothing else uses it.

## Community Guidelines

To maintain a positive and collaborative community, we ask that all contributors adhere to the following principles:
Expand All @@ -46,4 +72,4 @@ To maintain a positive and collaborative community, we ask that all contributors
3. **Follow Licensing Requirements**
Ensure that any derivative works comply with the [license](https://github.com/infinitode/ValX/blob/main/LICENSE).

By contributing, you agree to abide by these guidelines and this project's [license](https://github.com/infinitode/ValX/blob/main/LICENSE). Thank you for helping make **ValX** better!
By contributing, you agree to abide by these guidelines and this project's [license](https://github.com/infinitode/ValX/blob/main/LICENSE). Thank you for helping make **ValX** better!
Loading
Loading