|
| 1 | +name: Main |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + tags: |
| 14 | + - 'v*.*.*' |
| 15 | + |
| 16 | +env: |
| 17 | + # Change this to invalidate existing cache. |
| 18 | + CACHE_PREFIX: v0 |
| 19 | + PYTHONPATH: ./ |
| 20 | + |
| 21 | +jobs: |
| 22 | + checks: |
| 23 | + name: Python ${{ matrix.python }} - ${{ matrix.task.name }} |
| 24 | + runs-on: [ubuntu-latest] |
| 25 | + timeout-minutes: 15 |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + python: ['3.8', '3.10'] |
| 30 | + task: |
| 31 | + - name: Lint |
| 32 | + run: | |
| 33 | + flake8 . |
| 34 | +
|
| 35 | + include: |
| 36 | + - python: '3.10' |
| 37 | + task: |
| 38 | + name: Test |
| 39 | + run: pytest -v --color=yes --durations=5 tests/ |
| 40 | + |
| 41 | + - python: '3.10' |
| 42 | + task: |
| 43 | + name: Lint |
| 44 | + run: flake8 . |
| 45 | + |
| 46 | + - python: '3.10' |
| 47 | + task: |
| 48 | + name: Type check |
| 49 | + run: mypy . |
| 50 | + |
| 51 | + - python: '3.10' |
| 52 | + task: |
| 53 | + name: Build |
| 54 | + run: | |
| 55 | + python setup.py check |
| 56 | + python setup.py bdist_wheel sdist |
| 57 | +
|
| 58 | + - python: '3.10' |
| 59 | + task: |
| 60 | + name: Style |
| 61 | + run: | |
| 62 | + isort --check . |
| 63 | + black --check . |
| 64 | +
|
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v3 |
| 67 | + |
| 68 | + - name: Setup Python environment |
| 69 | + uses: ./.github/actions/setup-venv |
| 70 | + with: |
| 71 | + python-version: ${{ matrix.python }} |
| 72 | + cache-prefix: ${{ env.CACHE_PREFIX }} |
| 73 | + |
| 74 | + - name: Restore mypy cache |
| 75 | + if: matrix.task.name == 'Type check' |
| 76 | + uses: actions/cache@v3 |
| 77 | + with: |
| 78 | + path: .mypy_cache |
| 79 | + key: mypy-${{ env.CACHE_PREFIX }}-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('*requirements.txt') }}-${{ github.ref }}-${{ github.sha }} |
| 80 | + restore-keys: | |
| 81 | + mypy-${{ env.CACHE_PREFIX }}-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('*requirements.txt') }}-${{ github.ref }} |
| 82 | + mypy-${{ env.CACHE_PREFIX }}-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('*requirements.txt') }} |
| 83 | +
|
| 84 | + - name: ${{ matrix.task.name }} |
| 85 | + run: | |
| 86 | + . .venv/bin/activate |
| 87 | + ${{ matrix.task.run }} |
| 88 | +
|
| 89 | + - name: Upload package distribution files |
| 90 | + if: matrix.task.name == 'Build' |
| 91 | + uses: actions/upload-artifact@v3 |
| 92 | + with: |
| 93 | + name: package |
| 94 | + path: dist |
| 95 | + |
| 96 | + - name: Clean up |
| 97 | + if: always() |
| 98 | + run: | |
| 99 | + . .venv/bin/activate |
| 100 | + pip uninstall -y damia |
| 101 | +
|
| 102 | + release: |
| 103 | + name: Release |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: [checks] |
| 106 | + if: startsWith(github.ref, 'refs/tags/') |
| 107 | + steps: |
| 108 | + - uses: actions/checkout@v3 |
| 109 | + with: |
| 110 | + fetch-depth: 0 |
| 111 | + |
| 112 | + - name: Setup Python |
| 113 | + uses: actions/setup-python@v4 |
| 114 | + with: |
| 115 | + python-version: '3.10' |
| 116 | + |
| 117 | + - name: Install requirements |
| 118 | + run: | |
| 119 | + pip install --upgrade pip setuptools wheel |
| 120 | + pip install -r dev-requirements.txt |
| 121 | +
|
| 122 | + - name: Prepare environment |
| 123 | + run: | |
| 124 | + echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV |
| 125 | + echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 126 | +
|
| 127 | + - name: Download package distribution files |
| 128 | + uses: actions/download-artifact@v3 |
| 129 | + with: |
| 130 | + name: package |
| 131 | + path: dist |
| 132 | + |
| 133 | + - name: Generate release notes |
| 134 | + run: | |
| 135 | + python scripts/release_notes.py > ${{ github.workspace }}-RELEASE_NOTES.md |
| 136 | +
|
| 137 | + - name: Publish package to PyPI |
| 138 | + run: | |
| 139 | + twine upload -u '${{ secrets.PYPI_USERNAME }}' -p '${{ secrets.PYPI_PASSWORD }}' dist/* |
| 140 | +
|
| 141 | + - name: Publish GitHub release |
| 142 | + uses: softprops/action-gh-release@v1 |
| 143 | + env: |
| 144 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + with: |
| 146 | + body_path: ${{ github.workspace }}-RELEASE_NOTES.md |
| 147 | + prerelease: ${{ contains(env.TAG, 'rc') }} |
| 148 | + files: | |
| 149 | + dist/* |
0 commit comments