|
| 1 | +name: Lint and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: |
| 9 | + # The release workflow calls this one, so the gate a release passes is this exact job |
| 10 | + # set rather than a copy of it that can drift. |
| 11 | + workflow_call: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + # github.workflow is the calling workflow's name under workflow_call, so a release and a |
| 18 | + # push to main land in their own groups and do not cancel each other. |
| 19 | + group: ci-${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +env: |
| 23 | + GITLEAKS_VERSION: 8.30.1 |
| 24 | + # From the release's checksums file. Dependabot cannot update a pinned download, so bump |
| 25 | + # both together when moving to a new gitleaks release. |
| 26 | + GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb |
| 27 | + PIP_AUDIT_VERSION: 2.10.1 |
| 28 | + |
| 29 | +jobs: |
| 30 | + secrets: |
| 31 | + name: Secret scan (gitleaks) |
| 32 | + runs-on: ubuntu-latest |
| 33 | + timeout-minutes: 10 |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout (full history) |
| 37 | + uses: actions/checkout@v7 |
| 38 | + with: |
| 39 | + # Every commit, so a secret added and later removed is still found. |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Install gitleaks |
| 43 | + run: | |
| 44 | + archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" |
| 45 | + curl -sSfL -o "$RUNNER_TEMP/$archive" \ |
| 46 | + "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/$archive" |
| 47 | + echo "${GITLEAKS_SHA256} $RUNNER_TEMP/$archive" | sha256sum -c - |
| 48 | + tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" gitleaks |
| 49 | +
|
| 50 | + - name: Scan every commit |
| 51 | + run: '"$RUNNER_TEMP/gitleaks" git --config .gitleaks.toml --redact --verbose .' |
| 52 | + |
| 53 | + lint: |
| 54 | + name: Lint and format check |
| 55 | + runs-on: ubuntu-latest |
| 56 | + timeout-minutes: 10 |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout |
| 60 | + uses: actions/checkout@v7 |
| 61 | + |
| 62 | + - name: Set up uv |
| 63 | + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 |
| 64 | + with: |
| 65 | + enable-cache: true |
| 66 | + |
| 67 | + # --locked fails the job when uv.lock is out of step with pyproject.toml. |
| 68 | + - name: Install |
| 69 | + run: uv sync --locked |
| 70 | + |
| 71 | + - name: Lint |
| 72 | + run: uv run ruff check --output-format=github src tests scripts |
| 73 | + |
| 74 | + # Check only: formatting is fixed locally with 'just fmt', never in CI. |
| 75 | + - name: Format check |
| 76 | + run: uv run ruff format --check src tests scripts |
| 77 | + |
| 78 | + audit: |
| 79 | + name: Dependency audit (pip-audit) |
| 80 | + runs-on: ubuntu-latest |
| 81 | + timeout-minutes: 10 |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Checkout |
| 85 | + uses: actions/checkout@v7 |
| 86 | + |
| 87 | + - name: Set up uv |
| 88 | + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 |
| 89 | + |
| 90 | + # The locked, hashed dependency tree, runtime and dev, exactly as CI installs it. |
| 91 | + - name: Audit the locked dependencies for known vulnerabilities |
| 92 | + run: | |
| 93 | + uv export --frozen --format requirements-txt --no-emit-project \ |
| 94 | + --output-file "$RUNNER_TEMP/requirements.txt" |
| 95 | + uvx "pip-audit==${PIP_AUDIT_VERSION}" --strict --disable-pip --require-hashes \ |
| 96 | + --requirement "$RUNNER_TEMP/requirements.txt" |
| 97 | +
|
| 98 | + test: |
| 99 | + name: Test (Python ${{ matrix.python-version }}, ${{ matrix.os }}) |
| 100 | + runs-on: ${{ matrix.os }} |
| 101 | + timeout-minutes: 15 |
| 102 | + |
| 103 | + strategy: |
| 104 | + fail-fast: false |
| 105 | + matrix: |
| 106 | + os: [ubuntu-latest] |
| 107 | + python-version: ["3.11", "3.12", "3.13", "3.14"] |
| 108 | + # The config path and file permission handling differ on Windows and macOS, |
| 109 | + # so run the suite there too, on one Python version. |
| 110 | + include: |
| 111 | + - os: windows-latest |
| 112 | + python-version: "3.13" |
| 113 | + - os: macos-latest |
| 114 | + python-version: "3.13" |
| 115 | + |
| 116 | + env: |
| 117 | + UV_PYTHON: ${{ matrix.python-version }} |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@v7 |
| 122 | + |
| 123 | + - name: Set up uv |
| 124 | + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 |
| 125 | + with: |
| 126 | + enable-cache: true |
| 127 | + |
| 128 | + - name: Install |
| 129 | + run: uv sync --locked |
| 130 | + |
| 131 | + # Includes the rebrand test, which renames a copy of the repository and runs its |
| 132 | + # whole suite, so 'just rebrand' is proven on every platform. |
| 133 | + - name: Test |
| 134 | + run: uv run pytest |
| 135 | + |
| 136 | + build: |
| 137 | + name: Build |
| 138 | + runs-on: ubuntu-latest |
| 139 | + timeout-minutes: 10 |
| 140 | + needs: [secrets, lint, audit, test] |
| 141 | + |
| 142 | + steps: |
| 143 | + - name: Checkout |
| 144 | + uses: actions/checkout@v7 |
| 145 | + |
| 146 | + - name: Set up uv |
| 147 | + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 |
| 148 | + |
| 149 | + - name: Build the sdist and wheel |
| 150 | + run: uv build |
| 151 | + |
| 152 | + # Proves the wheel installs cleanly and the entry point resolves outside the source tree. |
| 153 | + - name: Smoke test the wheel |
| 154 | + shell: bash |
| 155 | + run: | |
| 156 | + uv venv "$RUNNER_TEMP/smoke" |
| 157 | + uv pip install --python "$RUNNER_TEMP/smoke" dist/*.whl |
| 158 | + "$RUNNER_TEMP/smoke/bin/ldo" --version |
| 159 | + "$RUNNER_TEMP/smoke/bin/ldo" --help > /dev/null |
| 160 | +
|
| 161 | + # Built once here; a release publishes these exact files rather than rebuilding. |
| 162 | + - name: Keep the build |
| 163 | + uses: actions/upload-artifact@v7 |
| 164 | + with: |
| 165 | + name: dist |
| 166 | + path: dist/ |
| 167 | + if-no-files-found: error |
| 168 | + retention-days: 14 |
0 commit comments