|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + PYTHON_VERSION: '3.11' |
| 10 | + |
| 11 | +jobs: |
| 12 | + dependencies: |
| 13 | + name: Install Dependencies |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + name: Checkout |
| 18 | + |
| 19 | + - uses: actions/setup-python@v5 |
| 20 | + name: Setup Python |
| 21 | + with: |
| 22 | + python-version: ${{ env.PYTHON_VERSION }} |
| 23 | + architecture: x64 |
| 24 | + |
| 25 | + - name: Install Poetry |
| 26 | + uses: snok/install-poetry@v1 |
| 27 | + with: |
| 28 | + virtualenvs-create: true |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: poetry install --with dev |
| 32 | + |
| 33 | + - name: Save Cached Poetry |
| 34 | + id: cached-poetry |
| 35 | + uses: actions/cache/save@v4 |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.cache |
| 39 | + ~/.local |
| 40 | + key: poetry-0 |
| 41 | + |
| 42 | + type-check: |
| 43 | + name: Type Check |
| 44 | + needs: |
| 45 | + - dependencies |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + name: Checkout |
| 50 | + |
| 51 | + - uses: actions/setup-python@v5 |
| 52 | + name: Setup Python |
| 53 | + with: |
| 54 | + python-version: ${{ env.PYTHON_VERSION }} |
| 55 | + architecture: x64 |
| 56 | + |
| 57 | + - name: Load Cached Poetry |
| 58 | + id: cached-poetry |
| 59 | + uses: actions/cache/restore@v4 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + ~/.cache |
| 63 | + ~/.local |
| 64 | + key: poetry-0 |
| 65 | + |
| 66 | + - name: Type Check |
| 67 | + run: poetry run poe typecheck |
| 68 | + |
| 69 | + lint: |
| 70 | + name: Lint |
| 71 | + needs: |
| 72 | + - dependencies |
| 73 | + runs-on: ubuntu-latest |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v4 |
| 76 | + name: Checkout |
| 77 | + |
| 78 | + - uses: actions/setup-python@v5 |
| 79 | + name: Setup Python |
| 80 | + with: |
| 81 | + python-version: ${{ env.PYTHON_VERSION }} |
| 82 | + architecture: x64 |
| 83 | + |
| 84 | + - name: Load Cached Poetry |
| 85 | + id: cached-poetry |
| 86 | + uses: actions/cache/restore@v4 |
| 87 | + with: |
| 88 | + path: | |
| 89 | + ~/.cache |
| 90 | + ~/.local |
| 91 | + key: poetry-0 |
| 92 | + |
| 93 | + - name: Lint |
| 94 | + run: poetry run poe lint |
| 95 | + |
| 96 | + build: |
| 97 | + name: Build |
| 98 | + needs: |
| 99 | + - dependencies |
| 100 | + runs-on: ubuntu-latest |
| 101 | + outputs: |
| 102 | + version: ${{ steps.extract_version.outputs.version }} |
| 103 | + name: ${{ steps.extract_version.outputs.name }} |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v4 |
| 106 | + name: Checkout |
| 107 | + with: |
| 108 | + lfs: true |
| 109 | + |
| 110 | + - uses: actions/setup-python@v5 |
| 111 | + name: Setup Python |
| 112 | + with: |
| 113 | + python-version: ${{ env.PYTHON_VERSION }} |
| 114 | + architecture: x64 |
| 115 | + |
| 116 | + - name: Load Cached Poetry |
| 117 | + id: cached-poetry |
| 118 | + uses: actions/cache/restore@v4 |
| 119 | + with: |
| 120 | + path: | |
| 121 | + ~/.cache |
| 122 | + ~/.local |
| 123 | + key: poetry-0 |
| 124 | + |
| 125 | + - name: Build |
| 126 | + run: poetry build |
| 127 | + |
| 128 | + - name: Extract Version |
| 129 | + id: extract_version |
| 130 | + run: | |
| 131 | + echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT" |
| 132 | + echo "name=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" |
| 133 | +
|
| 134 | + - name: Upload wheel |
| 135 | + uses: actions/upload-artifact@v4 |
| 136 | + with: |
| 137 | + name: wheel |
| 138 | + path: dist/*.whl |
| 139 | + if-no-files-found: error |
| 140 | + |
| 141 | + - name: Upload binary |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: binary |
| 145 | + path: dist/*.tar.gz |
| 146 | + if-no-files-found: error |
| 147 | + |
| 148 | + pypi-publish: |
| 149 | + name: Publish to PyPI |
| 150 | + if: >- |
| 151 | + github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 152 | + needs: |
| 153 | + - type-check |
| 154 | + - lint |
| 155 | + - build |
| 156 | + runs-on: ubuntu-latest |
| 157 | + environment: |
| 158 | + name: release |
| 159 | + url: https://pypi.org/p/${{ needs.build.outputs.name }} |
| 160 | + permissions: |
| 161 | + id-token: write |
| 162 | + steps: |
| 163 | + - uses: actions/download-artifact@v4 |
| 164 | + with: |
| 165 | + name: wheel |
| 166 | + path: dist |
| 167 | + |
| 168 | + - uses: actions/download-artifact@v4 |
| 169 | + with: |
| 170 | + name: binary |
| 171 | + path: dist |
| 172 | + |
| 173 | + - name: Publish package distributions to PyPI |
| 174 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 175 | + with: |
| 176 | + packages-dir: dist |
| 177 | + verbose: true |
| 178 | + |
| 179 | + release: |
| 180 | + name: Release |
| 181 | + needs: |
| 182 | + - type-check |
| 183 | + - lint |
| 184 | + - build |
| 185 | + - pypi-publish |
| 186 | + environment: |
| 187 | + name: release |
| 188 | + url: https://pypi.org/p/${{ needs.build.outputs.name }} |
| 189 | + runs-on: ubuntu-latest |
| 190 | + permissions: |
| 191 | + contents: write |
| 192 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 193 | + steps: |
| 194 | + - name: Procure Wheel |
| 195 | + uses: actions/download-artifact@v4 |
| 196 | + with: |
| 197 | + name: wheel |
| 198 | + path: artifacts |
| 199 | + |
| 200 | + - name: Procure Binary |
| 201 | + uses: actions/download-artifact@v4 |
| 202 | + with: |
| 203 | + name: binary |
| 204 | + path: artifacts |
| 205 | + |
| 206 | + - name: Release |
| 207 | + uses: softprops/action-gh-release@v1 |
| 208 | + with: |
| 209 | + files: artifacts/* |
| 210 | + tag_name: v${{ needs.build.outputs.version }} |
| 211 | + body: | |
| 212 | + Release of version ${{ needs.build.outputs.version }} |
| 213 | + PyPI package: https://pypi.org/project/${{ needs.build.outputs.name }}/${{ needs.build.outputs.version }} |
| 214 | + prerelease: false |
| 215 | + draft: false |
0 commit comments