Harden CI: Artifactory OIDC, uv, PyPI Trusted Publishing #2
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: CI | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| id-token: write | |
| contents: read | |
| env: | |
| ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }} | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }} | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| - name: Authenticate with Artifactory | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| uses: ./.github/actions/artifactory-oidc | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | |
| with: | |
| python-version: "3.11" | |
| - run: pip install uv==0.9.26 | |
| - run: uv sync --frozen --all-extras | |
| - run: uv run ruff check . | |
| - run: uv run ruff format --check . | |
| test: | |
| name: Test - Python ${{ matrix.python-version }} | |
| runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| - name: Authenticate with Artifactory | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| uses: ./.github/actions/artifactory-oidc | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - run: pip install uv==0.9.26 | |
| - run: uv sync --frozen --all-extras | |
| - run: uv run pytest | |
| build: | |
| name: Build Package | |
| runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }} | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| - name: Authenticate with Artifactory | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| uses: ./.github/actions/artifactory-oidc | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | |
| with: | |
| python-version: "3.11" | |
| - run: pip install uv==0.9.26 | |
| - name: Build package | |
| run: uv build | |
| - name: Verify installable | |
| run: | | |
| python -m venv test-env | |
| . test-env/bin/activate | |
| pip install dist/*.whl | |
| python -c "import segment.analytics; print(f'OK: {segment.analytics.__version__}')" | |
| all-checks: | |
| name: All Checks Passed | |
| needs: [lint, test, build] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Check all job statuses | |
| run: | | |
| if [ "${{ needs.lint.result }}" != "success" ] || \ | |
| [ "${{ needs.test.result }}" != "success" ] || \ | |
| [ "${{ needs.build.result }}" != "success" ]; then | |
| echo "One or more checks failed" | |
| exit 1 | |
| fi |