|
| 1 | +name: Test and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | + pull_request: |
| 7 | + branches: [ 'develop' ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + is-duplicate: |
| 11 | + name: Is Duplicate |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + should_skip: ${{ steps.skip-check.outputs.should_skip }} |
| 15 | + permissions: |
| 16 | + actions: write |
| 17 | + contents: read |
| 18 | + |
| 19 | + steps: |
| 20 | + - id: skip-check |
| 21 | + name: Skip Check |
| 22 | + uses: fkirc/skip-duplicate-actions@master |
| 23 | + with: |
| 24 | + paths_ignore: '["**.rst", "**.md", "**.txt"]' |
| 25 | + |
| 26 | + test-code: |
| 27 | + name: Test code |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + needs: is-duplicate |
| 30 | + if: ${{ needs.is-duplicate.outputs.should_skip != 'true' }} |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 34 | + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Check out code |
| 38 | + uses: actions/checkout@v3 |
| 39 | + with: |
| 40 | + submodules: recursive |
| 41 | + |
| 42 | + - name: Set up Python ${{ matrix.python-version }} |
| 43 | + uses: actions/setup-python@v4.5.0 |
| 44 | + with: |
| 45 | + python-version: ${{ matrix.python-version }} |
| 46 | + |
| 47 | + - name: Install dependencies |
| 48 | + run: | |
| 49 | + python -m pip install --upgrade pip |
| 50 | + pip install tox |
| 51 | +
|
| 52 | + - name: Test with Tox |
| 53 | + run: tox |
| 54 | + |
| 55 | + publish-to-test-pypi: |
| 56 | + name: Publish to TestPyPI |
| 57 | + environment: staging |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: |
| 60 | + - is-duplicate |
| 61 | + - test-code |
| 62 | + if: | |
| 63 | + needs.is-duplicate.outputs.should_skip != 'true' && |
| 64 | + github.ref == 'refs/heads/main' && |
| 65 | + github.event_name == 'push' |
| 66 | +
|
| 67 | + steps: |
| 68 | + - name: Check out code |
| 69 | + uses: actions/checkout@v3 |
| 70 | + |
| 71 | + - name: Set up Python |
| 72 | + uses: actions/setup-python@v4.5.0 |
| 73 | + with: |
| 74 | + python-version: '3.x' |
| 75 | + |
| 76 | + - name: Install dependencies |
| 77 | + run: | |
| 78 | + python -m pip install --upgrade pip |
| 79 | + pip install setuptools wheel twine |
| 80 | +
|
| 81 | + - name: Build and publish |
| 82 | + env: |
| 83 | + TWINE_USERNAME: '__token__' |
| 84 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 85 | + run: | |
| 86 | + python setup.py sdist bdist_wheel |
| 87 | + twine upload --repository testpypi dist/* |
| 88 | +
|
| 89 | + publish-to-pypi: |
| 90 | + name: Publish to PyPI |
| 91 | + environment: production |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: |
| 94 | + - is-duplicate |
| 95 | + - publish-to-test-pypi |
| 96 | + if: | |
| 97 | + needs.is-duplicate.outputs.should_skip != 'true' && |
| 98 | + github.ref == 'refs/heads/main' && |
| 99 | + github.event_name == 'push' |
| 100 | +
|
| 101 | + steps: |
| 102 | + - name: Check out code |
| 103 | + uses: actions/checkout@v3 |
| 104 | + |
| 105 | + - name: Set up Python |
| 106 | + uses: actions/setup-python@v4.5.0 |
| 107 | + with: |
| 108 | + python-version: '3.x' |
| 109 | + |
| 110 | + - name: Install dependencies |
| 111 | + run: | |
| 112 | + python -m pip install --upgrade pip |
| 113 | + pip install setuptools wheel twine |
| 114 | +
|
| 115 | + - name: Build and publish |
| 116 | + env: |
| 117 | + TWINE_USERNAME: '__token__' |
| 118 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 119 | + run: | |
| 120 | + python setup.py sdist bdist_wheel |
| 121 | + twine upload dist/* |
0 commit comments