diff --git a/.github/reusable-build/action.yml b/.github/reusable-build/action.yml new file mode 100644 index 0000000..1727c44 --- /dev/null +++ b/.github/reusable-build/action.yml @@ -0,0 +1,38 @@ +name: Resusable steps to build tfx-bsl + +inputs: + python-version: + description: 'Python version' + required: true +runs: + using: 'composite' + steps: + + - name: Set up Python ${{ inputs.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Upgrade pip + shell: bash + run: | + python -m pip install --upgrade pip pytest + + - name: Build the package for Python ${{ inputs.python-version }} + shell: bash + run: | + version="${{ inputs.python-version }}" + docker compose run -e PYTHON_VERSION=$(echo "$version" | sed 's/\.//') manylinux2010 + + - name: Upload wheel artifact for Python ${{ inputs.python-version }} + uses: actions/upload-artifact@v4.4.0 + with: + name: tfx-bsl-wheel-py${{ inputs.python-version }} + path: dist/*.whl + + - name: Install built wheel + shell: bash + run: | + pip install twine + twine check dist/* + pip install dist/*.whl diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98ef62b..7176327 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,28 +33,34 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - name: Build tfx-bsl + id: build-tfx-bsl + uses: ./.github/reusable-build with: python-version: ${{ matrix.python-version }} - - name: Upgrade pip - run: | - python -m pip install --upgrade pip - - name: Build the manylinux2010 image - run: docker compose build manylinux2010 - - - name: Build the package for Python ${{ matrix.python-version }} - run: | - version="${{ matrix.python-version }}" - docker compose run -e PYTHON_VERSION=$(echo "$version" | sed 's/\.//') manylinux2010 - - - name: Upload wheel artifact for Python ${{ matrix.python-version }} - uses: actions/upload-artifact@v3 - with: - name: tfx-bsl-wheel-py${{ matrix.python-version }} - path: dist/*.whl + upload_to_pypi: + name: Upload to PyPI + runs-on: ubuntu-latest + if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags')) || (github.event_name == 'workflow_dispatch') + needs: [build] + environment: + name: pypi + url: https://pypi.org/p/struct2tensor/ + permissions: + id-token: write + steps: + - name: Retrieve wheels + uses: actions/download-artifact@v4.1.8 + with: + merge-multiple: true + path: wheels - - name: Install built wheel - run: pip install dist/*.whl \ No newline at end of file + - name: List the build artifacts + run: | + ls -lAs wheels/ + - name: Upload to PyPI + uses: pypa/gh-action-pypi-publish@release/v1.9 + with: + packages_dir: wheels/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17606eb..cc53121 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,32 +33,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - name: Build tfx-bsl + id: build-tfx-bsl + uses: ./.github/reusable-build with: python-version: ${{ matrix.python-version }} - - name: Upgrade pip - run: | - python -m pip install --upgrade pip - - - name: Build the manylinux2010 image - run: docker compose build manylinux2010 - - - name: Build the package for Python ${{ matrix.python-version }} - run: | - version="${{ matrix.python-version }}" - docker compose run -e PYTHON_VERSION=$(echo "$version" | sed 's/\.//') manylinux2010 - - - name: Upload wheel artifact for Python ${{ matrix.python-version }} - uses: actions/upload-artifact@v3 - with: - name: tfx-bsl-wheel-py${{ matrix.python-version }} - path: dist/*.whl - - - name: Install built wheel - run: pip install dist/*.whl - - name: Test run: | pip install pytest