|
| 1 | +name: Publish Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" # Trigger on tags that start with 'v', such as v0.1.0 |
| 7 | + |
| 8 | +jobs: |
| 9 | + verify-version: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: '3.11' |
| 19 | + cache: 'pip' |
| 20 | + |
| 21 | + - name: Install Poetry |
| 22 | + run: | |
| 23 | + curl -sSL https://install.python-poetry.org | python3 - |
| 24 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 25 | +
|
| 26 | + - name: Get tag version |
| 27 | + id: get_version |
| 28 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV |
| 29 | + |
| 30 | + - name: Extract version from pyproject.toml |
| 31 | + id: get_toml_version |
| 32 | + run: | |
| 33 | + TOML_VERSION=$(grep -m 1 "version" pyproject.toml | cut -d '"' -f2) |
| 34 | + echo "TOML_VERSION=${TOML_VERSION}" >> $GITHUB_ENV |
| 35 | + echo "Version from pyproject.toml: ${TOML_VERSION}" |
| 36 | + echo "Version from tag: ${{ env.VERSION }}" |
| 37 | +
|
| 38 | + - name: Verify versions match |
| 39 | + run: | |
| 40 | + if [ "${{ env.VERSION }}" != "${{ env.TOML_VERSION }}" ]; then |
| 41 | + echo "Error: Version in pyproject.toml (${{ env.TOML_VERSION }}) does not match tag version (${{ env.VERSION }})" |
| 42 | + exit 1 |
| 43 | + else |
| 44 | + echo "Versions match!" |
| 45 | + fi |
| 46 | +
|
| 47 | + build: |
| 48 | + needs: verify-version |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Checkout repository |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Set up Python |
| 55 | + uses: actions/setup-python@v5 |
| 56 | + with: |
| 57 | + python-version: '3.11' |
| 58 | + cache: 'pip' |
| 59 | + |
| 60 | + - name: Install Poetry |
| 61 | + run: | |
| 62 | + curl -sSL https://install.python-poetry.org | python3 - |
| 63 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 64 | +
|
| 65 | + - name: Install dependencies |
| 66 | + run: | |
| 67 | + poetry install --with dev,docs |
| 68 | +
|
| 69 | + - name: Run tests |
| 70 | + run: | |
| 71 | + poetry run pytest tests/ |
| 72 | +
|
| 73 | + - name: Build package |
| 74 | + run: | |
| 75 | + poetry build |
| 76 | +
|
| 77 | + - name: Upload distribution artifacts |
| 78 | + uses: actions/upload-artifact@v3 |
| 79 | + with: |
| 80 | + name: dist |
| 81 | + path: dist/ |
| 82 | + retention-days: 7 |
| 83 | + |
| 84 | + publish-docs: |
| 85 | + needs: build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + permissions: |
| 88 | + contents: read |
| 89 | + pages: write |
| 90 | + id-token: write |
| 91 | + |
| 92 | + environment: |
| 93 | + name: github-pages |
| 94 | + url: ${{ steps.deployment.outputs.page_url }} |
| 95 | + |
| 96 | + steps: |
| 97 | + - name: Checkout repository |
| 98 | + uses: actions/checkout@v4 |
| 99 | + |
| 100 | + - name: Set up Python |
| 101 | + uses: actions/setup-python@v5 |
| 102 | + with: |
| 103 | + python-version: '3.11' |
| 104 | + cache: 'pip' |
| 105 | + |
| 106 | + - name: Install Poetry |
| 107 | + run: | |
| 108 | + curl -sSL https://install.python-poetry.org | python3 - |
| 109 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 110 | +
|
| 111 | + - name: Install dependencies |
| 112 | + run: | |
| 113 | + poetry install --with docs |
| 114 | +
|
| 115 | + - name: Generate RST files |
| 116 | + run: | |
| 117 | + cd ${{ github.workspace }} |
| 118 | + poetry run python docs/generate_docs.py |
| 119 | +
|
| 120 | + - name: Build documentation |
| 121 | + run: | |
| 122 | + cd ${{ github.workspace }}/docs |
| 123 | + poetry run sphinx-build -b html source build/html |
| 124 | +
|
| 125 | + - name: Setup Pages |
| 126 | + uses: actions/configure-pages@v4 |
| 127 | + |
| 128 | + - name: Upload artifact |
| 129 | + uses: actions/upload-pages-artifact@v3 |
| 130 | + with: |
| 131 | + path: ${{ github.workspace }}/docs/build/html |
| 132 | + |
| 133 | + - name: Deploy to GitHub Pages |
| 134 | + id: deployment |
| 135 | + uses: actions/deploy-pages@v4 |
| 136 | + |
| 137 | + publish-pypi: |
| 138 | + needs: publish-docs |
| 139 | + runs-on: ubuntu-latest |
| 140 | + environment: |
| 141 | + name: pypi |
| 142 | + permissions: |
| 143 | + id-token: write # For trusted publishing to PyPI |
| 144 | + |
| 145 | + steps: |
| 146 | + - name: Download distribution artifacts |
| 147 | + uses: actions/download-artifact@v3 |
| 148 | + with: |
| 149 | + name: dist |
| 150 | + path: dist/ |
| 151 | + |
| 152 | + - name: Publish to PyPI |
| 153 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments