Codestyle #40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - main | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| jobs: | |
| # Runs main tests for the package. | |
| # | |
| # Runs on all events except when closing a pull request. | |
| test: | |
| name: Test package | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| python-version: | |
| - "3.12" | |
| - "3.13" | |
| type: | |
| - test | |
| include: | |
| - os: ubuntu-latest | |
| python-version: "3.13" | |
| type: code style | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Update pip | |
| run: python -m pip install --upgrade pip | |
| # Tests | |
| - name: Install test dependencies | |
| if: ${{ matrix.type == 'test' }} | |
| run: python -m pip install . --group test | |
| - name: Check types | |
| if: ${{ matrix.type == 'test' }} | |
| run: pyright | |
| - name: Test package | |
| if: ${{ matrix.type == 'test' }} | |
| run: pytest -vv --showlocals --tb=short --color=yes --junit-xml=test-results.xml | |
| # Lint | |
| - name: Install lint dependencies | |
| if: ${{ matrix.type == 'code style' }} | |
| run: python -m pip install . --group lint | |
| - name: Check code style | |
| if: ${{ matrix.type == 'code style' }} | |
| run: pre-commit run -a | |
| # Builds and publishes python packages. | |
| # | |
| # Only runs on tag pushes. | |
| publish_to_pypi: | |
| name: Publish package to PyPi | |
| needs: | |
| - test | |
| if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }} | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/sphinx-syntax | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate release metadata | |
| id: metadata | |
| run: | | |
| ref="${{ github.ref }}"; | |
| version=${ref#refs/tags/v}; | |
| link="https://pypi.org/p/${{ github.repository }}/${version}"; | |
| echo "version=${version}" >> $GITHUB_OUTPUT | |
| echo "link=${link}" >> $GITHUB_OUTPUT | |
| - name: Parse Changelog | |
| id: changelog | |
| uses: mindsers/changelog-reader-action@v2 | |
| with: | |
| version: ${{ steps.metadata.outputs.version }} | |
| - name: Set up python 3.12 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.12 | |
| - name: Install build | |
| run: | | |
| pip install build | |
| - name: Build project | |
| run: | | |
| python3 -m build . | |
| - name: Publish to test pypi | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| attestations: false | |
| - name: Publish to pypi | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| attestations: false | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| prerelease: ${{ steps.changelog.outputs.status == 'prereleased' }} | |
| draft: ${{ steps.changelog.outputs.status == 'unreleased' }} | |
| body: | | |
| ## Changelog | |
| ${{ steps.changelog.outputs.changes }} | |
| [See release on PyPi](${{ steps.metadata.outputs.link }}) | |
| # Builds sphinx documentation. | |
| # | |
| # Runs on all events except when closing a pull request. | |
| build_docs: | |
| name: Build docs | |
| needs: | |
| - test | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up python 3.12 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.12 | |
| - name: Install package | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install . --group doc | |
| - name: Build docs | |
| env: | |
| SPHINXOPTS: "-j auto -n" | |
| run: | | |
| cd docs | |
| make html | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: html_output | |
| path: docs/build/html | |
| include-hidden-files: true | |
| # Builds and publishes production docs. | |
| # | |
| # Only runs on tag pushes. | |
| publish_docs: | |
| name: Publish docs to GitHub Pages | |
| needs: | |
| - build_docs | |
| if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && !contains(github.event.ref, '.dev') }} | |
| concurrency: | |
| group: publish-docs-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: write-all | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: html_output | |
| path: docs/build/html | |
| - name: Publish HTML | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| folder: docs/build/html | |
| target-folder: . | |
| clean-exclude: pr-preview | |
| single-commit: false |