|
| 1 | +name: Test |
| 2 | +on: |
| 3 | + push: |
| 4 | + paths-ignore: |
| 5 | + - 'doc/**' |
| 6 | + pull_request: |
| 7 | + paths-ignore: |
| 8 | + - 'doc/**' |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + tests: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + max-parallel: 5 |
| 22 | + matrix: |
| 23 | + python-version: [3.9, '3.10', '3.11', '3.12', '3.13'] |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Print github context |
| 27 | + env: |
| 28 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 29 | + run: echo $GITHUB_CONTEXT |
| 30 | + |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 1 |
| 35 | + |
| 36 | + - name: Set up Python ${{ matrix.python-version }} |
| 37 | + uses: astral-sh/setup-uv@v3 |
| 38 | + with: |
| 39 | + enable-cache: true |
| 40 | + cache-dependency-glob: "pyproject.toml" |
| 41 | + cache-suffix: ${{ matrix.python-version }} |
| 42 | + |
| 43 | + - name: Install Python |
| 44 | + run: uv python install ${{ matrix.python-version }} |
| 45 | + env: |
| 46 | + UV_PYTHON_PREFERENCE: only-managed |
| 47 | + |
| 48 | + - name: Install Transifex CLI |
| 49 | + run: | |
| 50 | + curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash |
| 51 | + mv tx /usr/local/bin/tx |
| 52 | +
|
| 53 | + - name: Tox tests |
| 54 | + run: uv run --only-dev tox -- -v --durations=25 |
| 55 | + |
| 56 | + build: |
| 57 | + name: build distribution |
| 58 | + if: github.repository_owner == 'sphinx-doc' && github.ref == 'refs/heads/master' |
| 59 | + needs: |
| 60 | + - tests |
| 61 | + runs-on: ubuntu-latest |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Checkout code |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + fetch-depth: 1 |
| 68 | + |
| 69 | + - name: Set up Python |
| 70 | + uses: astral-sh/setup-uv@v3 |
| 71 | + |
| 72 | + - name: build package |
| 73 | + run: uv build |
| 74 | + |
| 75 | + - name: upload artifact |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: distributions |
| 79 | + path: dist/ |
| 80 | + |
| 81 | + pypi-publish: |
| 82 | + name: Upload release to PyPI |
| 83 | + if: github.repository_owner == 'sphinx-doc' && startsWith(github.ref, 'refs/tags/') |
| 84 | + needs: |
| 85 | + - build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + environment: |
| 88 | + name: pypi |
| 89 | + url: https://pypi.org/p/sphinx-intl |
| 90 | + permissions: |
| 91 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Download all the dists |
| 95 | + uses: actions/download-artifact@v4 |
| 96 | + with: |
| 97 | + name: distributions |
| 98 | + path: dist/ |
| 99 | + |
| 100 | + - name: Publish package distributions to PyPI |
| 101 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 102 | + with: |
| 103 | + verbose: true |
| 104 | + |
| 105 | + # for test |
| 106 | + password: ${{ secrets.TESTPYPI_TOKEN }} |
| 107 | + repository_url: https://test.pypi.org/legacy/ |
| 108 | + |
| 109 | + # for production |
| 110 | + # password: ${{ secrets.PYPI_TOKEN }} |
| 111 | + |
| 112 | + github-release: |
| 113 | + name: GitHub release |
| 114 | + if: github.repository_owner == 'sphinx-doc' |
| 115 | + runs-on: ubuntu-latest |
| 116 | + needs: |
| 117 | + - pypi-publish |
| 118 | + environment: release |
| 119 | + permissions: |
| 120 | + contents: write # for softprops/action-gh-release to create GitHub release |
| 121 | + |
| 122 | + steps: |
| 123 | + - uses: actions/checkout@v4 |
| 124 | + with: |
| 125 | + persist-credentials: false |
| 126 | + - name: Get release version |
| 127 | + id: get_version |
| 128 | + uses: actions/github-script@v7 |
| 129 | + with: |
| 130 | + script: core.setOutput('version', context.ref.replace("refs/tags/", "")) |
| 131 | + |
| 132 | + - name: Create GitHub release |
| 133 | + uses: softprops/action-gh-release@v2 |
| 134 | + if: startsWith(github.ref, 'refs/tags/') |
| 135 | + with: |
| 136 | + name: "sphinx-intl ${{ steps.get_version.outputs.version }}" |
| 137 | + body: "Changelog: https://sphinx-intl.readthedocs.io/en/master/changes.html" |
0 commit comments