|
| 1 | +# .github/workflows/publish_testpypi.yml |
| 2 | +--- |
| 3 | +name: test-n-build |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - v* |
| 9 | +jobs: |
| 10 | + super-test: |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 15 | + python_v: ["3.11", "3.12", "3.13", "3.14"] |
| 16 | + name: Build and Test |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + env: |
| 19 | + UV_PYTHON: ${{ matrix.python_v }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 1 |
| 24 | + - uses: astral-sh/setup-uv@v5 |
| 25 | + - name: Install Dependencies |
| 26 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 27 | + run: sudo apt-get update && sudo apt-get install xvfb |
| 28 | + timeout-minutes: 1 |
| 29 | + # must actually checkout for version determination |
| 30 | + - run: git checkout ${{ github.ref_name }} |
| 31 | + - run: uv python install ${{ matrix.python_v }} |
| 32 | + # don't modify sync file! messes up version! |
| 33 | + - run: uv sync --all-extras --locked --no-sources |
| 34 | + - run: git status |
| 35 | + - run: git diff --quiet HEAD || { echo "Working tree dirty"; exit 1; } |
| 36 | + - run: uv build |
| 37 | + - name: Reinstall from wheel |
| 38 | + run: > |
| 39 | + uv pip install dist/container_tester-$(uv |
| 40 | + run --no-sync --with setuptools-git-versioning |
| 41 | + setuptools-git-versioning)-py3-none-any.whl |
| 42 | + - run: uv run --no-sync python --version |
| 43 | + - name: Test |
| 44 | + if: ${{ ! runner.debug && matrix.os != 'ubuntu-latest' }} |
| 45 | + run: uv run pytest |
| 46 | + timeout-minutes: 8 |
| 47 | + |
| 48 | + store-build: |
| 49 | + name: build release |
| 50 | + needs: super-test |
| 51 | + if: ${{ !cancelled() && |
| 52 | + !failure() && |
| 53 | + github.event_name == 'push' && |
| 54 | + github.run_attempt == 1 }} |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v4 |
| 59 | + - uses: astral-sh/setup-uv@v4 |
| 60 | + - uses: actions/setup-python@v5 |
| 61 | + with: |
| 62 | + python-version-file: "pyproject.toml" |
| 63 | + - run: git checkout ${{ github.ref_name }} |
| 64 | + - run: uv sync --frozen --all-extras |
| 65 | + - run: uv build |
| 66 | + - name: Store the distribution packages |
| 67 | + uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: python-package-distributions |
| 70 | + path: dist/ |
| 71 | + |
| 72 | + github-release: |
| 73 | + name: >- |
| 74 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 75 | + and upload them to GitHub Release |
| 76 | + needs: |
| 77 | + - super-test |
| 78 | + - store-build |
| 79 | + if: ${{ !cancelled() && |
| 80 | + !failure() && |
| 81 | + github.event_name == 'push' && |
| 82 | + github.run_attempt == 1 }} |
| 83 | + runs-on: ubuntu-latest |
| 84 | + |
| 85 | + permissions: |
| 86 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 87 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Download all the dists |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + name: python-package-distributions |
| 94 | + path: dist/ |
| 95 | + - name: Sign the dists with Sigstore |
| 96 | + uses: sigstore/gh-action-sigstore-python@v3.0.0 |
| 97 | + with: |
| 98 | + inputs: >- |
| 99 | + ./dist/*.tar.gz |
| 100 | + ./dist/*.whl |
| 101 | + - name: Create GitHub Release |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{ github.token }} |
| 104 | + run: >- |
| 105 | + gh release create |
| 106 | + "$GITHUB_REF_NAME" |
| 107 | + --repo "$GITHUB_REPOSITORY" |
| 108 | + --notes "" |
| 109 | + - name: Upload artifact signatures to GitHub Release |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ github.token }} |
| 112 | + # Upload to GitHub Release using the `gh` CLI. |
| 113 | + # `dist/` contains the built packages, and the |
| 114 | + # sigstore-produced signatures and certificates. |
| 115 | + run: >- |
| 116 | + gh release upload |
| 117 | + "$GITHUB_REF_NAME" dist/** |
| 118 | + --repo "$GITHUB_REPOSITORY" |
| 119 | + publish-to-pypi: |
| 120 | + name: >- |
| 121 | + Publish Python 🐍 distribution 📦 to PyPI |
| 122 | + needs: |
| 123 | + - super-test |
| 124 | + - store-build |
| 125 | + - github-release |
| 126 | + if: ${{ !cancelled() && |
| 127 | + !failure() && |
| 128 | + github.event_name == 'push' && |
| 129 | + github.run_attempt == 1 }} |
| 130 | + runs-on: ubuntu-latest |
| 131 | + environment: |
| 132 | + name: pypi |
| 133 | + url: https://pypi.org/p/container-tester |
| 134 | + # Signs this workflow so pypi trusts it |
| 135 | + permissions: |
| 136 | + id-token: write |
| 137 | + steps: |
| 138 | + - name: Download the dists |
| 139 | + uses: actions/download-artifact@v4 |
| 140 | + with: |
| 141 | + name: python-package-distributions |
| 142 | + path: dist/ |
| 143 | + - name: Push to PyPi |
| 144 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments