|
| 1 | +name: Build and upload to internal PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # run on request (no need for PR) |
| 5 | + |
| 6 | +jobs: |
| 7 | + build_wheels: |
| 8 | + name: Build wheels |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout |
| 12 | + uses: actions/checkout@v3 |
| 13 | + - name: Build wheels |
| 14 | + |
| 15 | + - uses: actions/upload-artifact@v3 |
| 16 | + with: |
| 17 | + path: ./wheelhouse/*.whl |
| 18 | + |
| 19 | + build_sdist: |
| 20 | + name: Build source distribution |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + - name: Set up Python 3.10 |
| 26 | + uses: actions/setup-python@v3 |
| 27 | + with: |
| 28 | + python-version: "3.10" |
| 29 | + - name: Install pypa/build |
| 30 | + run: python -m pip install build |
| 31 | + - name: Build sdist |
| 32 | + run: python -m build --sdist |
| 33 | + - uses: actions/upload-artifact@v3 |
| 34 | + with: |
| 35 | + path: dist/*.tar.gz |
| 36 | + |
| 37 | + publish_package: |
| 38 | + name: Publish package |
| 39 | + needs: [build_wheels, build_sdist] |
| 40 | + environment: pypi |
| 41 | + runs-on: [self-hosted, linux, x64, dev] |
| 42 | + permissions: write-all |
| 43 | + steps: |
| 44 | + - name: Set up Python |
| 45 | + uses: actions/setup-python@v4 |
| 46 | + with: |
| 47 | + python-version: "3.10" |
| 48 | + - name: Install dependencies |
| 49 | + run: python -m pip install twine |
| 50 | + - name: Download artifacts |
| 51 | + uses: actions/download-artifact@v3 |
| 52 | + with: |
| 53 | + # unpacks default artifact into dist/ |
| 54 | + # if `name: artifact` is omitted, the action will create extra parent dir |
| 55 | + name: artifact |
| 56 | + path: dist |
| 57 | + - name: Check tag |
| 58 | + id: check-tag |
| 59 | + uses: actions-ecosystem/action-regex-match@v2 |
| 60 | + with: |
| 61 | + text: ${{ github.ref }} |
| 62 | + regex: '^refs/heads/releases/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+rc[0-9]+|rc[0-9]+)?$' |
| 63 | + - name: Upload package distributions to github |
| 64 | + if: ${{ steps.check-tag.outputs.match != '' }} |
| 65 | + uses: svenstaro/upload-release-action@v2 |
| 66 | + with: |
| 67 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + file: dist/* |
| 69 | + tag: ${{ github.ref }} |
| 70 | + overwrite: true |
| 71 | + file_glob: true |
| 72 | + - name: Check dist contents |
| 73 | + run: twine check dist/* |
| 74 | + - name: Publish package dist to internal PyPI |
| 75 | + if: ${{ steps.check-tag.outputs.match != '' }} |
| 76 | + run: | |
| 77 | + export no_proxy=${{ secrets.PYPI_HOST }} |
| 78 | + export REPOSITORY_URL=http://${{ secrets.PYPI_HOST }}:${{ secrets.PYPI_PORT }} |
| 79 | + twine upload --verbose --repository-url $REPOSITORY_URL dist/* -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} |
| 80 | + - name: Publish package distributions to TestPyPI |
| 81 | + if: ${{ steps.check-tag.outputs.match == '' }} |
| 82 | + run: | |
| 83 | + export REPOSITORY_URL=https://test.pypi.org/legacy/ |
| 84 | + twine upload --verbose --repository-url $REPOSITORY_URL dist/* -u __token__ -p ${{ secrets.TESTPYPI_API_TOKEN }} |
| 85 | + - name: Clean up dist |
| 86 | + if: ${{ always() }} |
| 87 | + run: | |
| 88 | + if OUTPUT=$(ls | grep -c dist) |
| 89 | + then |
| 90 | + echo "Cleaning up dist directory" |
| 91 | + rm -r dist |
| 92 | + fi |
0 commit comments