|
| 1 | +name: Build Wheels & Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + workflow_dispatch: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +env: |
| 10 | + USE_BAZEL_VERSION: "7.2.1" |
| 11 | + |
| 12 | +jobs: |
| 13 | + build_sdist: |
| 14 | + name: Build sdist |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Check out the repo |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.11' |
| 24 | + |
| 25 | + - name: install python dependencies |
| 26 | + run: pip install build twine |
| 27 | + |
| 28 | + - uses: bazel-contrib/setup-bazel@0.14.0 |
| 29 | + name: Set up Bazel |
| 30 | + with: |
| 31 | + # Avoid downloading Bazel every time. |
| 32 | + bazelisk-cache: true |
| 33 | + # Store build cache per workflow. |
| 34 | + disk-cache: ${{ github.workflow }}-${{ hashFiles('.github/workflows/wheels.yml') }} |
| 35 | + # Share repository cache between workflows. |
| 36 | + repository-cache: true |
| 37 | + |
| 38 | + - name: Verify bazel installation |
| 39 | + run: | |
| 40 | + which bazel |
| 41 | + bazel info |
| 42 | + bazel version |
| 43 | +
|
| 44 | + - name: build sdist |
| 45 | + run: | |
| 46 | + python -m build --sdist -o wheelhouse |
| 47 | +
|
| 48 | + - name: List and check sdist |
| 49 | + run: | |
| 50 | + ls -lh wheelhouse/ |
| 51 | + twine check wheelhouse/* |
| 52 | +
|
| 53 | + - name: Upload sdist |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: sdist |
| 57 | + path: ./wheelhouse/*.tar.gz |
| 58 | + |
| 59 | + build_wheels: |
| 60 | + name: > |
| 61 | + build ${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }} |
| 62 | + ${{ (matrix.arch) || '' }} |
| 63 | + strategy: |
| 64 | + fail-fast: false |
| 65 | + matrix: |
| 66 | + os: [ubuntu] |
| 67 | + python-version: ['cp311'] |
| 68 | + |
| 69 | + runs-on: ${{ format('{0}-latest', matrix.os) }} |
| 70 | + steps: |
| 71 | + - name: Check out the repo |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Set up python |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.11' |
| 78 | + |
| 79 | + - name: Install python build dependencies |
| 80 | + run: | |
| 81 | +
|
| 82 | + pip install wheel |
| 83 | + |
| 84 | +
|
| 85 | + - uses: bazel-contrib/setup-bazel@0.14.0 |
| 86 | + name: Set up Bazel |
| 87 | + with: |
| 88 | + # Avoid downloading Bazel every time. |
| 89 | + bazelisk-cache: true |
| 90 | + # Store build cache per workflow. |
| 91 | + disk-cache: ${{ github.workflow }}-${{ hashFiles('.github/workflows/wheels.yml') }} |
| 92 | + # Share repository cache between workflows. |
| 93 | + repository-cache: true |
| 94 | + |
| 95 | + - name: Verify bazel installation |
| 96 | + run: | |
| 97 | + which bazel |
| 98 | + bazel info |
| 99 | + bazel version |
| 100 | +
|
| 101 | + - name: Install build |
| 102 | + run: python -m pip install --upgrade pip build |
| 103 | + |
| 104 | + - name: Build wheels |
| 105 | + run: | |
| 106 | + python -m build --wheel |
| 107 | + mkdir wheelhouse |
| 108 | + mv dist/*.whl wheelhouse/ |
| 109 | +
|
| 110 | + - name: List and check wheels |
| 111 | + run: | |
| 112 | + pip install twine pkginfo>=1.11.0 |
| 113 | + ${{ matrix.ls || 'ls -lh' }} wheelhouse/ |
| 114 | + twine check wheelhouse/* |
| 115 | +
|
| 116 | + - name: Upload wheels |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: wheels-${{ matrix.python-version }}-${{ matrix.os }} |
| 120 | + path: ./wheelhouse/*.whl |
| 121 | + |
| 122 | + upload_to_pypi: |
| 123 | + name: Upload to PyPI |
| 124 | + runs-on: ubuntu-latest |
| 125 | + if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags')) || (github.event_name == 'workflow_dispatch') |
| 126 | + needs: [build_wheels, build_sdist] |
| 127 | + environment: |
| 128 | + name: pypi |
| 129 | + url: https://pypi.org/p/tensorflow-metadata |
| 130 | + permissions: |
| 131 | + id-token: write |
| 132 | + steps: |
| 133 | + - name: Retrieve wheels and sdist |
| 134 | + uses: actions/download-artifact@v4 |
| 135 | + with: |
| 136 | + merge-multiple: true |
| 137 | + path: wheels/ |
| 138 | + |
| 139 | + - name: List the build artifacts |
| 140 | + run: | |
| 141 | + ls -lAs wheels/ |
| 142 | +
|
| 143 | + - name: Upload to PyPI |
| 144 | + uses: pypa/gh-action-pypi-publish@release/v1.12 |
| 145 | + with: |
| 146 | + packages-dir: wheels/ |
| 147 | + repository-url: https://pypi.org/legacy/ |
| 148 | + # already checked, and the pkginfo/twine versions on this runner causes check to fail |
| 149 | + verify-metadata: false |
| 150 | + verbose: true |
0 commit comments