|  | 
|  | 1 | +name: Build and upload to PyPI | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  workflow_dispatch: # run on request (no need for PR) | 
|  | 5 | +  release: | 
|  | 6 | +    types: [published] | 
|  | 7 | + | 
|  | 8 | +# Declare default permissions as read only. | 
|  | 9 | +permissions: read-all | 
|  | 10 | + | 
|  | 11 | +jobs: | 
|  | 12 | +  build: | 
|  | 13 | +    name: Build | 
|  | 14 | +    runs-on: ubuntu-latest | 
|  | 15 | +    steps: | 
|  | 16 | +      - name: Checkout | 
|  | 17 | +        uses: actions/checkout@v4 | 
|  | 18 | +      - name: Set up Python 3.10 | 
|  | 19 | +        uses: actions/setup-python@v5 | 
|  | 20 | +        with: | 
|  | 21 | +          python-version: "3.10" | 
|  | 22 | +      - name: Install pypa/build | 
|  | 23 | +        run: | | 
|  | 24 | +          python -m pip install --upgrade build | 
|  | 25 | +      - name: Build sdist | 
|  | 26 | +        run: | | 
|  | 27 | +          sed -i '/omz_tools/d' model_api/python/pyproject.toml | 
|  | 28 | +          python -m build --sdist model_api/python/ | 
|  | 29 | +      - uses: actions/upload-artifact@v4 | 
|  | 30 | +        with: | 
|  | 31 | +          name: artifact-sdist | 
|  | 32 | +          path: model_api/python/dist/*.tar.gz | 
|  | 33 | +      - name: Build wheel | 
|  | 34 | +        run: | | 
|  | 35 | +          sed -i '/omz_tools/d' model_api/python/pyproject.toml | 
|  | 36 | +          python -m build --wheel model_api/python/ | 
|  | 37 | +      - uses: actions/upload-artifact@v4 | 
|  | 38 | +        with: | 
|  | 39 | +          name: artifact-wheel | 
|  | 40 | +          path: model_api/python/dist/*.whl | 
|  | 41 | + | 
|  | 42 | +  publish_package: | 
|  | 43 | +    name: Publish package | 
|  | 44 | +    needs: [build] | 
|  | 45 | +    environment: pypi | 
|  | 46 | +    runs-on: ubuntu-latest | 
|  | 47 | +    permissions: | 
|  | 48 | +      packages: write | 
|  | 49 | +      contents: write | 
|  | 50 | +      id-token: write | 
|  | 51 | +    steps: | 
|  | 52 | +      - name: Download artifacts | 
|  | 53 | +        uses: actions/download-artifact@v4 | 
|  | 54 | +        with: | 
|  | 55 | +          path: model_api/python/dist | 
|  | 56 | +          pattern: artifact-* | 
|  | 57 | +          merge-multiple: true | 
|  | 58 | +      # to determine where to publish the package distribution to PyPI or TestPyPI | 
|  | 59 | +      - name: Check tag | 
|  | 60 | +        id: check-tag | 
|  | 61 | +        uses: actions-ecosystem/action-regex-match@v2 | 
|  | 62 | +        with: | 
|  | 63 | +          text: ${{ github.ref }} | 
|  | 64 | +          regex: '^refs/tags/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+rc[0-9]+|rc[0-9]+)?$' | 
|  | 65 | +      - name: Upload package distributions to github | 
|  | 66 | +        if: ${{ steps.check-tag.outputs.match != '' }} | 
|  | 67 | +        uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # v2 | 
|  | 68 | +        with: | 
|  | 69 | +          repo_token: ${{ secrets.GITHUB_TOKEN }} | 
|  | 70 | +          file: model_api/python/dist/* | 
|  | 71 | +          tag: ${{ github.ref }} | 
|  | 72 | +          overwrite: true | 
|  | 73 | +          file_glob: true | 
|  | 74 | +      - name: Publish package distributions to PyPI | 
|  | 75 | +        if: ${{ steps.check-tag.outputs.match != '' }} | 
|  | 76 | +        uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 | 
|  | 77 | +      - name: Publish package distributions to TestPyPI | 
|  | 78 | +        if: ${{ steps.check-tag.outputs.match == '' }} | 
|  | 79 | +        uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 | 
|  | 80 | +        with: | 
|  | 81 | +          repository-url: https://test.pypi.org/legacy/ | 
|  | 82 | +          verbose: true | 
0 commit comments