|
| 1 | +name: test |
| 2 | + |
| 3 | +on: [push, pull_request, workflow_dispatch] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build-and-inspect: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + permissions: |
| 9 | + id-token: write |
| 10 | + attestations: write |
| 11 | + contents: read |
| 12 | + outputs: |
| 13 | + python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }} |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Build and inspect package |
| 21 | + id: baipp |
| 22 | + uses: hynek/build-and-inspect-python-package@v2 |
| 23 | + with: |
| 24 | + attest-build-provenance-github: true |
| 25 | + env: |
| 26 | + SETUPTOOLS_SCM_OVERRIDES_FOR_INICONFIG: ${{ github.ref == 'refs/heads/main' && 'local_scheme="no-local-version"' || '' }} |
| 27 | + |
| 28 | + test: |
| 29 | + needs: build-and-inspect |
| 30 | + runs-on: ${{ matrix.os }} |
| 31 | + defaults: |
| 32 | + run: |
| 33 | + shell: bash |
| 34 | + |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + python: ${{ fromJSON(needs.build-and-inspect.outputs.python-versions) }} |
| 39 | + os: [ubuntu-latest, windows-latest] |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout test files |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + sparse-checkout: | |
| 46 | + testing |
| 47 | + uv.lock |
| 48 | + sparse-checkout-cone-mode: false |
| 49 | + |
| 50 | + - name: Download built packages |
| 51 | + uses: actions/download-artifact@v4 |
| 52 | + with: |
| 53 | + name: Packages |
| 54 | + path: dist |
| 55 | + |
| 56 | + - name: Verify artifacts exist |
| 57 | + run: | |
| 58 | + ls -la dist/ |
| 59 | + test -f dist/*.whl || (echo "No wheel found!" && exit 1) |
| 60 | + test -f dist/*.tar.gz || (echo "No sdist found!" && exit 1) |
| 61 | +
|
| 62 | + - name: Install uv |
| 63 | + uses: astral-sh/setup-uv@v7 |
| 64 | + with: |
| 65 | + enable-cache: true |
| 66 | + |
| 67 | + - name: Set up Python ${{ matrix.python }} |
| 68 | + run: uv python install ${{ matrix.python }} |
| 69 | + |
| 70 | + - name: Run tests with built wheel |
| 71 | + run: uv run --with dist/*.whl --with pytest pytest testing --color=yes |
| 72 | + |
| 73 | + create-release: |
| 74 | + name: Create GitHub Release |
| 75 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 76 | + needs: [test, build-and-inspect] |
| 77 | + runs-on: ubuntu-latest |
| 78 | + permissions: |
| 79 | + contents: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Download built packages |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + name: Packages |
| 86 | + path: dist |
| 87 | + |
| 88 | + - name: Extract version from tag |
| 89 | + id: version |
| 90 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 91 | + |
| 92 | + - name: Create GitHub Release |
| 93 | + uses: softprops/action-gh-release@v2 |
| 94 | + with: |
| 95 | + files: dist/* |
| 96 | + fail_on_unmatched_files: true |
| 97 | + generate_release_notes: true |
| 98 | + name: Version ${{ steps.version.outputs.VERSION }} |
| 99 | + |
| 100 | + publish-to-pypi: |
| 101 | + name: Publish to PyPI |
| 102 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 103 | + needs: [test, build-and-inspect, create-release] |
| 104 | + runs-on: ubuntu-latest |
| 105 | + environment: pypi-upload |
| 106 | + permissions: |
| 107 | + id-token: write |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Download built packages |
| 111 | + uses: actions/download-artifact@v4 |
| 112 | + with: |
| 113 | + name: Packages |
| 114 | + path: dist |
| 115 | + |
| 116 | + - name: Publish package to PyPI |
| 117 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 118 | + |
| 119 | + publish-to-test-pypi: |
| 120 | + name: Publish to TestPyPI |
| 121 | + if: | |
| 122 | + github.repository == 'pytest-dev/iniconfig' && |
| 123 | + (github.event_name == 'push' && ( |
| 124 | + github.ref == 'refs/heads/main' || |
| 125 | + contains(github.ref, 'deploy') |
| 126 | + )) |
| 127 | + needs: [test, build-and-inspect] |
| 128 | + runs-on: ubuntu-latest |
| 129 | + environment: test-pypi-upload |
| 130 | + permissions: |
| 131 | + id-token: write |
| 132 | + attestations: write |
| 133 | + |
| 134 | + steps: |
| 135 | + - name: Download built packages |
| 136 | + uses: actions/download-artifact@v4 |
| 137 | + with: |
| 138 | + name: Packages |
| 139 | + path: dist |
| 140 | + |
| 141 | + - name: Publish package to TestPyPI |
| 142 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 143 | + with: |
| 144 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments