|
| 1 | +name: Check & Release |
| 2 | + |
| 3 | +on: |
| 4 | + # Push to master will publish a beta version |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + # A release via GitHub releases will publish a stable version |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint_and_test: |
| 14 | + name: Lint and run unit tests |
| 15 | + runs-on: ubuntu-20.04 |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + python-version: [3.7, 3.8, 3.9] |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Set up Python ${{ matrix.python-version }} |
| 25 | + uses: actions/setup-python@v2 |
| 26 | + with: |
| 27 | + python-version: ${{ matrix.python-version }} |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install -e .[dev] |
| 33 | +
|
| 34 | + - name: Lint |
| 35 | + run: ./lint_and_test.sh lint |
| 36 | + |
| 37 | + - name: Type check |
| 38 | + run: ./lint_and_test.sh types |
| 39 | + |
| 40 | + - name: Unit tests |
| 41 | + run: ./lint_and_test.sh tests |
| 42 | + |
| 43 | + check_docs: |
| 44 | + name: Check whether the documentation is up to date |
| 45 | + runs-on: ubuntu-20.04 |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@v2 |
| 50 | + |
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@v2 |
| 53 | + with: |
| 54 | + python-version: 3.7 |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + run: | |
| 58 | + python -m pip install --upgrade pip |
| 59 | + pip install -e .[dev] |
| 60 | +
|
| 61 | + - name: Check whether docs are built from the latest code |
| 62 | + run: ./docs/res/check.sh |
| 63 | + |
| 64 | + deploy: |
| 65 | + name: Publish to PyPI |
| 66 | + needs: [lint_and_test, check_docs] |
| 67 | + runs-on: ubuntu-20.04 |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout repository |
| 71 | + uses: actions/checkout@v2 |
| 72 | + |
| 73 | + - name: Set up Python |
| 74 | + uses: actions/setup-python@v2 |
| 75 | + with: |
| 76 | + python-version: 3.7 |
| 77 | + |
| 78 | + - name: Install dependencies |
| 79 | + run: | |
| 80 | + python -m pip install --upgrade pip |
| 81 | + pip install --upgrade setuptools twine wheel |
| 82 | +
|
| 83 | + - # Determine if this is a beta or latest release |
| 84 | + name: Determine release type |
| 85 | + run: echo "RELEASE_TYPE=$(if [ ${{ github.event_name }} = release ]; then echo stable; else echo beta; fi)" >> $GITHUB_ENV |
| 86 | + |
| 87 | + - # Check whether the released version is listed in CHANGELOG.md |
| 88 | + name: Check whether the released version is listed in the changelog |
| 89 | + run: python ./.github/scripts/check_version_in_changelog.py |
| 90 | + |
| 91 | + - # Check version consistency and increment pre-release version number for beta releases (must be the last step before build) |
| 92 | + name: Bump pre-release version |
| 93 | + if: env.RELEASE_TYPE == 'beta' |
| 94 | + run: python ./.github/scripts/update_version_for_beta_release.py |
| 95 | + |
| 96 | + - # Build a source distribution and a python3-only wheel |
| 97 | + name: Build distribution files |
| 98 | + run: python setup.py sdist bdist_wheel |
| 99 | + |
| 100 | + - # Check whether the package description will render correctly on PyPI |
| 101 | + name: Check package rendering on PyPI |
| 102 | + run: python -m twine check dist/* |
| 103 | + |
| 104 | + - # Publish package to PyPI using their official GitHub action |
| 105 | + name: Publish package to PyPI |
| 106 | + run: python -m twine upload --non-interactive --disable-progress-bar dist/* |
| 107 | + env: |
| 108 | + TWINE_USERNAME: __token__ |
| 109 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 110 | + |
| 111 | + - # Tag the current commit with the version tag if this is a beta release (stable releases are tagged with the release process) |
| 112 | + name: Tag Version |
| 113 | + if: env.RELEASE_TYPE == 'beta' |
| 114 | + run: | |
| 115 | + git_tag=v`python ./.github/scripts/print_current_package_version.py` |
| 116 | + git tag $git_tag |
| 117 | + git push origin $git_tag |
| 118 | +
|
| 119 | + - # Upload the build artifacts to the release |
| 120 | + name: Upload the build artifacts to release |
| 121 | + uses: svenstaro/upload-release-action@v2 |
| 122 | + if: env.RELEASE_TYPE == 'stable' |
| 123 | + with: |
| 124 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + file: dist/* |
| 126 | + file_glob: true |
| 127 | + tag: ${{ github.ref }} |
0 commit comments