diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index a5cdd1b..a053bb7 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -3,33 +3,61 @@ # This workflow follow documentation from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ +# Example of cibuildwheel from https://github.com/pypa/cibuildwheel/blob/main/examples/github-deploy.yml + name: Publish +# TODO revert before merge on: - push: - branches: ['master'] - tags: ['*'] + push permissions: contents: read jobs: - build: + build_wheels: + name: Build wheel on ${{ matrix.os }} for python ${{ matrix.python }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + python: 39 + platform_id: manylinux_x86_64 + manylinux_image: manylinux2014 + - os: windows-latest + python: 39 + platform_id: win_amd64 + - os: macos-13 + python: 39 + platform_id: macosx_x86_64 + steps: + - uses: actions/checkout@v4 + - name: Build wheels + env: + CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} + CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} + CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }} + run: | + python -m pip install cibuildwheel pipenv + python -m cibuildwheel --output-dir wheelhouse + - name: Upload wheel for ${{ matrix.os }} ${{ strategy.job-index }} + uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl + build_dist: name: Prepare distribution packages runs-on: ubuntu-latest environment: name: build - strategy: - matrix: - python-version: ['3.9'] steps: - uses: actions/checkout@v4 - - name: Unshallow repo clone - run: git fetch --prune --unshallow --tags - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 cache: 'pipenv' - name: Install pipenv run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python @@ -38,15 +66,17 @@ jobs: - name: Build package run: pipenv run python ./setup.py build_ext -i -j2 bdist_wheel - name: Store the distribution packages - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: python-package-distributions - path: dist/ + name: cibw-dist + path: dist/*.tar.gz + # TODO add twine check dist/*.tar.gz publish-to-pypi: name: Publish to PyPI if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - - build + - build_wheels + - build_dist runs-on: ubuntu-latest environment: name: pypi @@ -55,16 +85,18 @@ jobs: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - name: python-package-distributions - path: dist/ + pattern: cibw-* + path: dist + merge-multiple: true - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 publish-to-testpypi: name: Publish to TestPyPI needs: - - build + - build_wheels + - build_dist runs-on: ubuntu-latest environment: @@ -76,10 +108,11 @@ jobs: steps: - name: Download all the dists - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - name: python-package-distributions - path: dist/ + pattern: cibw-* + path: dist + merge-multiple: true - name: Publish to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c659984..efbd49c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -6,8 +6,9 @@ name: Dev on: push: branches: ['master'] - pull_request: - branches: ['master'] +# TODO revert before merge +# pull_request: +# branches: ['master'] jobs: tests: @@ -17,8 +18,6 @@ jobs: name: build steps: - uses: actions/checkout@v4 - - name: Unshallow repo clone - run: git fetch --prune --unshallow --tags - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/MANIFEST.in b/MANIFEST.in index d31c031..88f68ed 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include MANIFEST.in +include pyproject.toml include *.txt recursive-include cyperf/tools *.pyx.in *.pxd.in recursive-include cyperf *.pyx *.pxd *.py *.pxi *.cc *.h diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cce2080 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools", "wheel", "pipenv", "numpy>=1.19.5", "cython>=0.29.5,<3.0.0", "scipy>=1.2.0"] diff --git a/version.py b/version.py index c3323c3..b1a1041 100644 --- a/version.py +++ b/version.py @@ -31,6 +31,8 @@ def get_version(): version_returned = 'unknown' print(f"version=={version_returned}") return version_returned + # unshallow repo clone to make `git describe` work in CI + _run(['git', 'fetch', '--prune', '--unshallow', '--tags']) describe_cmd = ['git', 'describe', '--tags', '--always'] last_tag = _run(describe_cmd + ['--abbrev=0']) # '1.0.14' describe = _run(describe_cmd) # '1.0.14-2-gfaa2442' {tag}-{nb_commit_since_tag}-{hash}' @@ -48,6 +50,7 @@ def get_version(): version_returned = f"{last_tag.replace('v', '', 1)}.dev0+{short_hash[1:]}" LOGGER.info("version==%s", version_returned) print(f"version=={version_returned}") + print(_run(['pip', 'freeze'])) return version_returned