|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: |
| 7 | + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 |
| 8 | + pull_request: |
| 9 | + branches: [ main ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v3 |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: '3.12' |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + pip install poetry |
| 23 | + poetry install |
| 24 | + - name: Run tests |
| 25 | + run: poetry run pytest |
| 26 | + - name: Upload test results |
| 27 | + uses: actions/upload-artifact@v3 |
| 28 | + with: |
| 29 | + name: test-results |
| 30 | + path: test-results |
| 31 | + |
| 32 | + build-docs: |
| 33 | + needs: build-and-test |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v3 |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v4 |
| 39 | + with: |
| 40 | + python-version: '3.12' |
| 41 | + - name: Install dependencies |
| 42 | + run: | |
| 43 | + pip install poetry |
| 44 | + poetry install |
| 45 | + poetry add mkdocs mkdocs-material mkdocstrings[python] |
| 46 | + - name: Build documentation |
| 47 | + run: poetry run mkdocs build |
| 48 | + - name: Upload documentation |
| 49 | + uses: actions/upload-artifact@v3 |
| 50 | + with: |
| 51 | + name: site |
| 52 | + path: site |
| 53 | + |
| 54 | + deploy-docs: |
| 55 | + needs: build-docs |
| 56 | + runs-on: ubuntu-latest |
| 57 | + if: startsWith(github.ref, 'refs/tags/') |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v3 |
| 60 | + - name: Download built site |
| 61 | + uses: actions/download-artifact@v3 |
| 62 | + with: |
| 63 | + name: site |
| 64 | + path: site |
| 65 | + - name: Deploy to GitHub Pages |
| 66 | + uses: peaceiris/actions-gh-pages@v3 |
| 67 | + with: |
| 68 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + publish_dir: ./site |
| 70 | + |
| 71 | + create-release: |
| 72 | + needs: [build-and-test, deploy-docs] |
| 73 | + runs-on: ubuntu-latest |
| 74 | + if: startsWith(github.ref, 'refs/tags/') |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v3 |
| 77 | + - name: Create Release |
| 78 | + id: create_release |
| 79 | + uses: actions/create-release@v1 |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + with: |
| 83 | + tag_name: ${{ github.ref }} |
| 84 | + release_name: Release ${{ github.ref }} |
| 85 | + draft: false |
| 86 | + prerelease: false |
| 87 | + |
| 88 | + release: |
| 89 | + needs: create-release |
| 90 | + runs-on: ubuntu-latest |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v3 |
| 93 | + - name: Set up Python |
| 94 | + uses: actions/setup-python@v4 |
| 95 | + with: |
| 96 | + python-version: '3.12' |
| 97 | + - name: Install dependencies |
| 98 | + run: | |
| 99 | + pip install poetry |
| 100 | + poetry install |
| 101 | + - name: Build package |
| 102 | + run: poetry build |
| 103 | + - name: Publish to PyPI |
| 104 | + env: |
| 105 | + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} |
| 106 | + run: | |
| 107 | + poetry config pypi-token.pypi $PYPI_TOKEN |
| 108 | + poetry publish |
0 commit comments