Skip to content

DOC add scenario update blog (#1940) #11713

DOC add scenario update blog (#1940)

DOC add scenario update blog (#1940) #11713

# Builds the pyrit environment and runs all tests and pre-commit hooks
name: build_and_test
env:
PRE_COMMIT_PYTHON_VERSION: '3.11'
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
- "release/**"
merge_group:
workflow_dispatch:
concurrency:
# This ensures after each commit the old jobs are cancelled and the new ones
# run instead.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
pre-commit:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
permissions:
contents: read
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
# Full history is required so pre-commit hooks (notably
# enforce_alembic_revision_immutability) can compute merge-bases and
# diff ranges against origin/main.
fetch-depth: 0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ env.PRE_COMMIT_PYTHON_VERSION }}
- name: Cache pre-commit environments
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-${{ runner.os }}-
- name: Install uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
# Install a specific version of uv.
version: "0.9.17"
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
- name: Install dev extras
run: uv sync --extra all
- name: disk space
shell: bash
run: df -all -h
- name: Run pre-commit (all files)
# Always lint the ENTIRE repository on every event (pull_request,
# merge_group, push to main, workflow_dispatch). Running --all-files on
# PRs -- rather than only the files changed since origin/main -- ensures
# latent violations in untouched files, including the tests/integration,
# tests/partner_integration, and tests/end_to_end tiers, are caught before
# merge instead of only on the post-merge run against main.
run: |
git fetch origin main
uv run pre-commit run --all-files
# Main job runs only if pre-commit succeeded
main-job:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
package_name: ["pyrit"]
package_extras: ["dev", "dev_all"]
runs-on: ${{ matrix.os }}
# EnricoMi/publish-unit-test-result-action@v2 requires the following permissions
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
# Set up Python
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ matrix.python }}
- name: Install uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
# Install a specific version of uv.
version: "0.9.17"
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
# Install PyRIT with optional extras
- name: Install PyRIT with uv
# If the matrix extras is 'dev_all', then we install all extras
# otherwise just install the default dependencies
shell: bash
run: |
if [ "${{ matrix.package_extras }}" = "dev_all" ]; then
uv sync --extra all
else
uv sync
fi
- name: Run unit tests
run: make unit-test-junit
- name: Publish Pytest Results
uses: EnricoMi/publish-unit-test-result-action@d0a4676d0e0b938bc201470d88276b7c74c712b3 # v2.24.0
if: runner.os == 'ubuntu-latest'
with:
files: '**/test-*.xml'