From 3b44f3fe33eea4cc8c97e331723a6ba44a25a389 Mon Sep 17 00:00:00 2001 From: Henrique Musseli Cezar Date: Mon, 25 Sep 2023 15:50:07 +0200 Subject: [PATCH] Add github action for release and fix importlib.util import --- .github/workflows/black.yml | 4 +- .github/workflows/ci.yml | 2 +- .github/workflows/documentation.yml | 2 +- .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++ clusttraj/__init__.py | 2 +- clusttraj/io.py | 2 +- 6 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 0a8b8e9..f5d13b9 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,4 +1,4 @@ -name: Lint +name: Lint with black on: [push, pull_request] @@ -6,5 +6,5 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: psf/black@stable \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e67427d..c9ee199 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index c01357f..9cab35b 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -14,7 +14,7 @@ jobs: docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: "3.10" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7e7fd55 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +name: Upload clusttraj to PyPI when tag is pushed + +on: push + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install pypa/build + run: | + python3 -m pip install --upgrade pip + python3 -m pip install build + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + testpypi-publish: + name: upload release to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: release + url: https://test.pypi.org/p/clusttraj + + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution packages to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + pypi-publish: + name: upload release to PyPI + needs: + - build + runs-on: ubuntu-latest + + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + environment: + name: release + url: https://pypi.org/p/clusttraj + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution packages to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: Sign and upload them to GitHub Release + needs: + - pypi-publish + runs-on: ubuntu-latest + + if: startsWith(github.ref, 'refs/tags/') # only upload to GitHub Release on tag pushes + permissions: + contents: write + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.0.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/clusttraj/__init__.py b/clusttraj/__init__.py index 174707d..9ef4758 100644 --- a/clusttraj/__init__.py +++ b/clusttraj/__init__.py @@ -1,6 +1,6 @@ from .main import main -__version__ = "0.1.0" +__version__ = "0.1.1" __all__ = [ "main", diff --git a/clusttraj/io.py b/clusttraj/io.py index 3c87b71..947d06f 100644 --- a/clusttraj/io.py +++ b/clusttraj/io.py @@ -10,7 +10,7 @@ import numpy as np import rmsd import logging -import importlib +import importlib.util from typing import Callable, List, Union from dataclasses import dataclass from .utils import get_mol_info