diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 583b1de9..015602a3 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -2,6 +2,8 @@ name: Wheels on: [ push, pull_request ] +if: ${{ startsWith(github.ref, 'refs/tags/') || contains(github.event.commits.*.message, '[pypi]') }} + jobs: build_wheels: name: Build wheels on ${{ matrix.os }} @@ -39,8 +41,6 @@ jobs: MACOSX_DEPLOYMENT_TARGET: 13 CIBW_BUILD: cp311-* CIBW_SKIP: pp* - #CIBW_TEST_REQUIRES: scipy sympy - #CIBW_TEST_COMMAND: python -m unittest camb.tests.camb_test CIBW_BUILD_VERBOSITY: 1 run: python -m cibuildwheel --output-dir wheelhouse @@ -109,13 +109,25 @@ jobs: twine check --strict dist/* twine check --strict dist-wheels/* - - name: Publish wheels to PyPI + - name: Publish wheels to PyPI Test + if: ${{ !startsWith(github.ref, 'refs/tags/') }} uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ packages-dir: dist-wheels/ - - name: Publish sdist to PyPI + - name: Publish sdist to PyPI Test + if: ${{ !startsWith(github.ref, 'refs/tags/') }} uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ + + - name: Publish wheels to PyPI + if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist-wheels/ + + - name: Publish sdist to PyPI + if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/setup.py b/setup.py index 3d38d11d..9059b221 100644 --- a/setup.py +++ b/setup.py @@ -181,7 +181,7 @@ def make_library(cluster=False): get_forutils() print("Compiling source...") subprocess.call("make python PYCAMB_OUTPUT_DIR=%s/camb/ CLUSTER_SAFE=%d" % - (pycamb_path, int(cluster)), shell=True) + (pycamb_path, int(cluster if not os.getenv("GITHUB_ACTIONS") else 1)), shell=True) subprocess.call("chmod 755 %s" % lib_file, shell=True) if not os.path.isfile(os.path.join(pycamb_path, 'camb', DLLNAME)): @@ -276,7 +276,14 @@ def run(self): def find_version(): version_file = open(os.path.join(file_dir, 'camb', '__init__.py')).read() - return re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M).group(1) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + if version_match: + version = version_match.group(1) + commit = os.getenv('GITHUB_RUN_NUMBER') + if commit and not os.getenv('TRAVIS_TAG'): + version += '.' + commit + return version + raise RuntimeError("Unable to find version string.") if __name__ == "__main__":