Repository navigation
[INT-3877] Add CI quality gates, lint, and security checks #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
370b3e9
[INT-3877] Handle missing fields in Onfleet error payloads
joao-onfleet b91d542
[INT-3877] Add CI quality gates, ruff lint, and security checks
joao-onfleet 31c6a17
[INT-3877] Address review feedback on CI gates
joao-onfleet 67308ee
[INT-3877] Add API-free unit tests for the offline gate
joao-onfleet 13ffd96
[INT-3877] Address second review round
joao-onfleet 35b7260
TEMP: run live suite on same-repo PR to validate secret
joao-onfleet 900f527
[INT-3877] Fix stale assertion in test_authenticate
joao-onfleet ed3a9c1
[INT-3877] Do not assume an organization ID format in test_authenticate
joao-onfleet 117ac24
Revert "TEMP: run live suite on same-repo PR to validate secret"
joao-onfleet fc422c8
[INT-3877] Address round-1 code review findings
joao-onfleet b358fe1
[INT-3877] Address cubic review comments
joao-onfleet bcc808e
[INT-3877] Address review findings from izzyandrade
joao-onfleet 3694616
[INT-3877] Keep float error codes classifiable
joao-onfleet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # CI quality gates (INT-3877 steps 6-10). | ||
| # Offline checks (lint, audit, secret scan, tests) run on every PR. | ||
| # The live-API suite runs only on push to master: Actions secrets are not | ||
| # exposed to fork PRs, and the suite performs real writes. | ||
| name: CI | ||
|
|
||
| # No paths-ignore here: these checks become required via branch | ||
| # protection (INT-3877 step 12), and a required check that never | ||
| # triggers leaves doc-only PRs stuck in the "Expected" state. | ||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # Cancel superseded runs on PR churn only. Push runs to master include | ||
| # the live-API suite, which mutates real data; a mid-test cancellation | ||
| # would leave test resources behind. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install ruff | ||
| run: pip install ruff==0.16.8 | ||
| - name: Lint | ||
| run: ruff check . | ||
|
|
||
| audit: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install pip-audit | ||
| run: pip install pip-audit==2.10.1 | ||
| # pip-audit has no severity filter; it fails on any known | ||
| # vulnerability, which is stricter than the "high severity" gate | ||
| # the ticket asks for. | ||
| - name: Audit dependencies | ||
| run: pip-audit -r requirements.txt | ||
|
|
||
| secret-scan: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| # gitleaks-action requires a license for organization repos; | ||
| # the CLI performs the same full-history scan without one. | ||
| - name: Run gitleaks (full history) | ||
| run: | | ||
| curl -sSfLO https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz | ||
| echo "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gitleaks_8.30.1_linux_x64.tar.gz" | sha256sum -c - | ||
| tar -xzf gitleaks_8.30.1_linux_x64.tar.gz gitleaks | ||
| ./gitleaks git --redact --verbose . | ||
|
|
||
| test-offline: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| strategy: | ||
| matrix: | ||
| python-version: ['3.10', '3.11', '3.12'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| pip install -r requirements.txt | ||
| pip install build==1.6.1 | ||
| - name: Build package | ||
| run: python -m build | ||
| # Install the wheel the build step produced, not the source tree, | ||
| # so the smoke test exercises the artifact pypi-publish.yml ships. | ||
| # Import from outside the repo root: in the root, the onfleet/ | ||
| # source directory shadows the installed wheel. | ||
| - name: Import smoke test | ||
| run: | | ||
| pip install dist/*.whl | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| cd "$RUNNER_TEMP" | ||
| python -c "import onfleet; print(onfleet.Onfleet)" | ||
| # Without ONFLEET_API_KEY the live-API tests skip; the API-free | ||
| # unit tests in test_request_offline.py still run and assert. | ||
| - name: Run test suite (offline) | ||
| run: python -m unittest discover -s test -v | ||
|
|
||
| # The job stays disabled until the ONFLEET_API_KEY secret has a value: | ||
| # set the LIVE_SUITE_ENABLED repository variable to 'true' when the | ||
| # secret lands. Secrets are not readable in job-level `if` expressions; | ||
| # variables are. This avoids a red master while the secret is pending. | ||
| test-live: | ||
| if: github.event_name == 'push' && vars.LIVE_SUITE_ENABLED == 'true' | ||
| needs: [lint, test-offline] | ||
| uses: ./.github/workflows/live-suite.yml | ||
| secrets: inherit | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Reusable live-API test suite, called from ci.yml (push to master) | ||
| # and pypi-publish.yml (release gate). Single Python version: the suite | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| # mutates real data in the test organization, so concurrent matrix jobs | ||
| # would race each other. Per-version coverage runs offline in ci.yml. | ||
| name: Live suite | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| # Both callers share this group, so a master push and a release | ||
| # never mutate the test organization at the same time. Never cancel | ||
| # a running suite: a mid-test cancellation leaves test resources | ||
| # behind. | ||
| concurrency: | ||
| group: live-api-suite | ||
| cancel-in-progress: false | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install dependencies | ||
| run: pip install -r requirements.txt | ||
| # Without the secret the suite skips every test and the job would | ||
| # pass green with zero assertions. Fail loudly instead. | ||
| - name: Require ONFLEET_API_KEY | ||
| env: | ||
| ONFLEET_API_KEY: ${{ secrets.ONFLEET_API_KEY }} | ||
| run: | | ||
| if [ -z "$ONFLEET_API_KEY" ]; then | ||
| echo "::error::The live-API suite cannot run without the ONFLEET_API_KEY secret." | ||
| exit 1 | ||
| fi | ||
| - name: Run test suite (live API) | ||
| env: | ||
| ONFLEET_API_KEY: ${{ secrets.ONFLEET_API_KEY }} | ||
| run: python -m unittest discover -s test -v | ||
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| from onfleet.onfleet import Onfleet | ||
| from onfleet.endpoint import Endpoint | ||
| from onfleet.error import HttpError, PermissionError, RateLimitError, ServiceError, ValidationError | ||
| from onfleet.onfleet import Onfleet | ||
| from onfleet.request import Request | ||
| from onfleet.error import ValidationError, PermissionError, HttpError, RateLimitError, ServiceError | ||
|
|
||
| __all__ = ["Onfleet"] | ||
| # Only Onfleet is exported on star imports. The error classes stay | ||
| # importable by name, but out of `__all__`: onfleet.PermissionError is | ||
| # the API exception, and a star import must not shadow the builtin. | ||
| __all__ = ["Onfleet"] | ||
|
joao-onfleet marked this conversation as resolved.
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Minimal ruff configuration (INT-3877 step 8). | ||
| target-version = "py310" | ||
| line-length = 120 | ||
|
|
||
| [lint] | ||
| # Pinned rule set: pycodestyle errors (incl. E501 line length), | ||
| # pyflakes, import sorting. | ||
| # Pinning keeps CI deterministic across ruff versions. | ||
| select = ["E4", "E5", "E7", "E9", "F", "I"] | ||
|
|
||
| [lint.per-file-ignores] | ||
| # Re-export module: the imports exist for `onfleet.<name>` access and | ||
| # are deliberately absent from `__all__`. | ||
| "onfleet/__init__.py" = ["F401"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import ast | ||
| import pathlib | ||
|
|
||
| import setuptools | ||
|
|
||
| PROJECT_ROOT = pathlib.Path(__file__).parent | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.