Merge pull request #33 from LucasDooms/develop #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Build the package and publish it to PyPI | |
| name: Publish to PyPI | |
| # Only for version tags | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| jobs: | |
| build: | |
| name: Build distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Check if tag version matches pyproject.toml and sphinx conf.py | |
| run: | | |
| TAG_VERSION="${GITHUB_REF#refs/tags/v}" | |
| PYPROJECT_VERSION=$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])') || exit | |
| SPHINX_VERSION=$(python -c 'import docs.source.conf as conf; print(conf.release)') || exit | |
| echo "Tag version: $TAG_VERSION" | |
| echo "pyproject.toml version: $PYPROJECT_VERSION" | |
| echo "sphinx version: $SPHINX_VERSION" | |
| if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then | |
| echo "Error: tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)" | |
| exit 1 | |
| fi | |
| if [ "$TAG_VERSION" != "$SPHINX_VERSION" ]; then | |
| echo "Error: tag version ($TAG_VERSION) does not match sphinx conf.py version ($SPHINX_VERSION)" | |
| exit 1 | |
| fi | |
| - name: Check if tag version matches sphinx conf.py | |
| run: | | |
| TAG_VERSION="${GITHUB_REF#refs/tags/v}" | |
| PYPROJECT_VERSION=$(python -c 'import docs.source.conf as conf; print(conf.release)') | |
| echo "Tag version: $TAG_VERSION" | |
| echo "conf.py version: $PYPROJECT_VERSION" | |
| if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then | |
| echo "Error: tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)" | |
| exit 1 | |
| fi | |
| - name: Build a binary wheel and a source tarball | |
| run: uv build --out-dir dist | |
| - name: Store the distribution packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| publish-to-pypi: | |
| name: Publish to PyPI | |
| if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes | |
| needs: | |
| - build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/smc-lammps | |
| permissions: | |
| id-token: write # IMPORTANT: mandatory for trusted publishing | |
| steps: | |
| - name: Download all the dists | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |