diff --git a/.github/actions/reusable-build/action.yml b/.github/actions/reusable-build/action.yml new file mode 100644 index 0000000..2230ed8 --- /dev/null +++ b/.github/actions/reusable-build/action.yml @@ -0,0 +1,20 @@ +name: Reusable action which builds struct2tensor + +inputs: + python-version: + description: 'Python version' + required: true +runs: + using: 'composite' + steps: + - name: Build the package for Python ${{ inputs.python-version }} + uses: pypa/cibuildwheel@v3.1.3 + with: + output-dir: dist + + - name: Upload wheel artifact for Python ${{ inputs.python-version }} + uses: actions/upload-artifact@v4 + with: + name: struct2tensor-py${{ inputs.python-version }} + path: dist/*.whl + if-no-files-found: error diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..107f7be --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,68 @@ +name: Build struct2tensor wheels + +on: + pull_request: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Build package + id: build-package + uses: ./.github/actions/reusable-build + with: + python-version: ${{ matrix.python-version }} + + - name: List and check wheels + shell: bash + run: | + pip install twine + ls -lh dist/ + twine check dist/* + + upload_to_pypi: + name: Upload to PyPI + runs-on: ubuntu-latest + if: (github.event_name == 'release' && github.event.action == 'published') || (github.event_name == 'workflow_dispatch') + needs: [build] + environment: + name: pypi + url: https://pypi.org/p/struct2tensor/ + permissions: + id-token: write + contents: read + attestations: write + steps: + - name: Retrieve wheels + uses: actions/download-artifact@v4 + with: + merge-multiple: true + path: wheels + + - name: List the build artifacts + run: | + ls -lAs wheels/ + + - name: Generate artifact attestations for wheels + uses: actions/attest-build-provenance@v1 + with: + subject-path: "wheels/*" + + - name: Upload to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages_dir: wheels/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8f422b9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[tool.cibuildwheel] +environment = { TF_VERSION="RELEASED_TF_2" } \ No newline at end of file