diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..b6c7ea9 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,81 @@ +on: + push: + tags: + - 'v[0-9]+' + - 'test-v[0-9]*' # Uploads to https://test.pypi.org/project/tree-sitter/ + +jobs: + build-sdist: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: python setup.py sdist + - uses: actions/upload-artifact@v2 + with: + name: dist + path: ./dist/* + + build-wheels: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04, macos-11, windows-2022] + + steps: + - uses: actions/checkout@v3 + with: + submodules: true + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - if: ${{ startsWith(matrix.os, 'windows') }} + run: script\fetch-fixtures.cmd + - if: ${{ !startsWith(matrix.os, 'windows') }} + run: script/fetch-fixtures + + # Build wheels + - run: pip install cibuildwheel==2.9.0 + - run: python -m cibuildwheel --output-dir dist + env: + CIBW_TEST_COMMAND: python -m unittest discover -s {package}/tests + CIBW_ARCHS_MACOS: x86_64 arm64 + + # Make wheels downloadable from GitHub UI and from the pypi step + - uses: actions/upload-artifact@v2 + with: + name: dist + path: ./dist/*.whl + + release: + runs-on: ubuntu-latest + needs: [build-sdist, build-wheels] + steps: + - uses: actions/download-artifact@v3 + with: + name: dist + path: dist + - run: ls -la + - run: ls -la dist + + # https://stackoverflow.com/a/58478262 + - if: ${{ startsWith(github.ref, 'refs/tags/test-v') }} + name: 'Upload to test.pypi.org' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + + - if: ${{ startsWith(github.ref, 'refs/tags/v') }} + name: 'Upload to pypi.org' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/script/publish b/script/publish deleted file mode 100755 index 441d2ca..0000000 --- a/script/publish +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if which python3 > /dev/null; then - py=python3 -else - py=python -fi - -$py setup.py sdist bdist_wheel -for file in dist/*; do - twine upload $file -done diff --git a/tests/test_tree_sitter.py b/tests/test_tree_sitter.py index e4841c2..c022eff 100644 --- a/tests/test_tree_sitter.py +++ b/tests/test_tree_sitter.py @@ -6,13 +6,21 @@ from tree_sitter import Language, Parser LIB_PATH = path.join("build", "languages.so") + +# cibuildwheel uses a funny working directory when running tests. +# This is by design, this way tests import whatever is installed and not from the project. +# +# The languages binary is still relative to current working directory to prevent reusing +# a 32-bit languages binary in a 64-bit build. The working directory is clean every time. +project_root = path.dirname(path.dirname(path.abspath(__file__))) Language.build_library( LIB_PATH, [ - path.join("tests", "fixtures", "tree-sitter-python"), - path.join("tests", "fixtures", "tree-sitter-javascript"), + path.join(project_root, "tests", "fixtures", "tree-sitter-python"), + path.join(project_root, "tests", "fixtures", "tree-sitter-javascript"), ], ) + PYTHON = Language(LIB_PATH, "python") JAVASCRIPT = Language(LIB_PATH, "javascript")