|
| 1 | +# This is a basic workflow to help you get started with uploading to pypi automatically |
| 2 | +# https://packaging.python.org/tutorials/packaging-projects/ |
| 3 | +# |
| 4 | +# Before running this workflow in your repository, you will need to set up Secrets in your repository settings: |
| 5 | +# - Log in to your (test)PyPI account, go to your account -> your_project -> Publishing |
| 6 | +# - Fill in the required fields (environment: release) |
| 7 | +# - Create an API token for the repository and this workflow |
| 8 | + |
| 9 | +# - Go to your repository on GitHub, click on the "Settings" tab. |
| 10 | +# - Create an environment 'release' and set the security rules |
| 11 | +# - Go to the "Secrets" tab, click on "New environment secret" |
| 12 | +# - Add a new secret with the name PYPI_TOKEN and the value is your pypi token |
| 13 | +# - Add a new secret with the name PYPI_TEST_TOKEN and the value is your test pypi token |
| 14 | +# Then, define the name of your package and the python version you want to use in the env block below. |
| 15 | + |
| 16 | +# This workflow will then automatically test, build and upload your package to PyPI/TestPypi: |
| 17 | +# - When a new commit is pushed to main, it will build and upload to TestPyPI to catch errors early |
| 18 | +# - When a new release is created, it will build and upload to the real PyPI |
| 19 | +--- |
| 20 | +env: |
| 21 | + PACKAGE_NAME: "cht_tiling" # the name of your package on PyPI |
| 22 | + PYTHON_VERSION: "3.10" # the version of python used to build & publish the package. Tests will be run for all versions in the matrix |
| 23 | + |
| 24 | +name: Build and Upload to PyPI |
| 25 | +on: |
| 26 | + push: |
| 27 | + branches: |
| 28 | + - main |
| 29 | + tags: |
| 30 | + - v* |
| 31 | + pull_request: |
| 32 | + branches: |
| 33 | + - main |
| 34 | + release: |
| 35 | + types: |
| 36 | + - published |
| 37 | + workflow_dispatch: |
| 38 | + |
| 39 | + |
| 40 | +jobs: |
| 41 | + build-artifacts: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v3 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: ${{ env.PYTHON_VERSION }} |
| 52 | + |
| 53 | + - name: Install dependencies and build tools |
| 54 | + shell: bash -l {0} |
| 55 | + run: | |
| 56 | + python -m pip install --upgrade pip |
| 57 | + python -m pip install . |
| 58 | + python -m pip install build |
| 59 | +
|
| 60 | + - name: Build package |
| 61 | + shell: bash -l {0} |
| 62 | + run: python -m build |
| 63 | + |
| 64 | + - uses: actions/upload-artifact@v3 |
| 65 | + with: |
| 66 | + name: releases |
| 67 | + path: dist |
| 68 | + |
| 69 | + test-built-dist: # Install the built package and test it has been built correctly |
| 70 | + needs: [build-artifacts] |
| 71 | + runs-on: ubuntu-latest |
| 72 | + defaults: |
| 73 | + run: |
| 74 | + shell: bash -l {0} |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v3 |
| 77 | + |
| 78 | + - uses: actions/download-artifact@v3 |
| 79 | + with: |
| 80 | + name: releases |
| 81 | + path: dist |
| 82 | + - name: List contents of built dist |
| 83 | + run: | |
| 84 | + ls -ltrh |
| 85 | + ls -ltrh dist |
| 86 | + |
| 87 | + - uses: actions/setup-python@v5 |
| 88 | + with: |
| 89 | + python-version: ${{ env.PYTHON_VERSION }} |
| 90 | + |
| 91 | + - name: Verify the built dist/wheel is valid |
| 92 | + run: | |
| 93 | + python -m pip install dist/*.whl |
| 94 | + python -c "import ${{ env.PACKAGE_NAME }}; print(${{ env.PACKAGE_NAME }}.__version__)" |
| 95 | +
|
| 96 | + upload-to-test-pypi: |
| 97 | + environment: release |
| 98 | + permissions: |
| 99 | + id-token: write |
| 100 | + needs: [test-built-dist] |
| 101 | + if: ${{ github.event_name == 'release' && !github.event.act }} |
| 102 | + |
| 103 | + runs-on: ubuntu-latest |
| 104 | + steps: |
| 105 | + - uses: actions/download-artifact@v3 |
| 106 | + with: |
| 107 | + name: releases |
| 108 | + path: dist |
| 109 | + - name: Publish package to TestPyPI |
| 110 | + |
| 111 | + with: |
| 112 | + user: __token__ |
| 113 | + password: ${{ secrets.TEST_PYPI_TOKEN }} |
| 114 | + repository_url: https://test.pypi.org/legacy/ |
| 115 | + verbose: true |
| 116 | + skip_existing: true |
| 117 | + |
| 118 | + upload-to-pypi: |
| 119 | + needs: [upload-to-test-pypi] |
| 120 | + environment: release |
| 121 | + permissions: |
| 122 | + id-token: write |
| 123 | + |
| 124 | + if: ${{ github.event_name == 'release' && !github.event.act }} |
| 125 | + runs-on: ubuntu-latest |
| 126 | + steps: |
| 127 | + - uses: actions/download-artifact@v3 |
| 128 | + with: |
| 129 | + name: releases |
| 130 | + path: dist |
| 131 | + - name: Publish package to PyPI |
| 132 | + |
| 133 | + with: |
| 134 | + user: __token__ |
| 135 | + password: ${{ secrets.PYPI_TOKEN }} |
| 136 | + verbose: true |
0 commit comments