Skip to content

Merge branch 'main' of https://github.com/Azure/PyRIT into integratio… #3

Merge branch 'main' of https://github.com/Azure/PyRIT into integratio…

Merge branch 'main' of https://github.com/Azure/PyRIT into integratio… #3

# Builds the pyrit environment and runs all tests and pre-commit hooks

Check failure on line 1 in .github/workflows/build_and_test.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build_and_test.yml

Invalid workflow file

(Line: 157, Col: 9): Unexpected value 'Example', (Line: 160, Col: 5): Unexpected value 'uv-example', (Line: 160, Col: 5): There's not enough info to determine what you meant. Add one of these properties: cancel-timeout-minutes, container, continue-on-error, defaults, env, environment, outputs, runs-on, secrets, services, snapshot, steps, timeout-minutes, uses, with
name: build_and_test
env:
PRE_COMMIT_PYTHON_VERSION: '3.11'
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
- "release/**"
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-linux:
runs-on: ubuntu-latest
permissions:
contents: read
env:
UV_CACHE_DIR_CUSTOM: ${{ github.workspace }}\.cache\uv
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ env.PRE_COMMIT_PYTHON_VERSION }}
- name: Cache uv packages
uses: actions/cache@v3
with:
path: ${{ env.UV_CACHE_DIR_CUSTOM }}
key: ${{ runner.os }}-uv-${{ env.PRE_COMMIT_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-${{ env.PRE_COMMIT_PYTHON_VERSION }}-
${{ runner.os }}-uv-
- name: Cache pre-commit environments
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-${{ runner.os }}-
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
# Install a specific version of uv.
version: "0.9.17"
- name: Install uv
uses: astral-sh/setup-uv@v1 # Use the latest stable version
with:
version: 'latest' # Or a specific version like '0.1.0'
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
- name: Install dev extras
run: uv sync --extra dev --extra all --cache-dir ${{ env.UV_CACHE_DIR_CUSTOM }}
- name: disk space
run: df -all -h
- name: Run pre-commit incrementally (on PR)
if: github.event_name == 'pull_request'
env:
RUN_LONG_PRECOMMIT: true
run: |
git fetch origin main
uv run pre-commit run --from-ref origin/main --to-ref HEAD
- name: Run pre-commit fully (on main)
if: github.ref == 'refs/heads/main'
env:
RUN_LONG_PRECOMMIT: true
run: |
uv run pre-commit run --all-files
pre-commit-windows:
runs-on: windows-latest
permissions:
contents: read
env:
UV_CACHE_DIR_CUSTOM: ${{ github.workspace }}\.cache\uv
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ env.PRE_COMMIT_PYTHON_VERSION }}
- name: Cache uv packages
uses: actions/cache@v3
with:
path: ${{ env.UV_CACHE_DIR_CUSTOM }}
key: ${{ runner.os }}-uv-${{ env.PRE_COMMIT_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-${{ env.PRE_COMMIT_PYTHON_VERSION }}-
${{ runner.os }}-uv-
- name: Cache pre-commit environments
uses: actions/cache@v3
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@v1 # Use the latest stable version
with:
version: 'latest' # Or a specific version like '0.1.0'
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
- name: Install dev extras
run: uv sync --extra dev --extra all --cache-dir ${{ env.UV_CACHE_DIR_CUSTOM }}
- name: disk space
run: df -all -h
- name: Run pre-commit incrementally (on PR)
if: github.event_name == 'pull_request'
env:
RUN_LONG_PRECOMMIT: true
run: |
git fetch origin main
uv run pre-commit run --from-ref origin/main --to-ref HEAD
- name: Run pre-commit fully (on main)
if: github.ref == 'refs/heads/main'
env:
RUN_LONG_PRECOMMIT: true
run: |
uv run pre-commit run --all-files
name: Example
jobs:
uv-example:
name: python
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Run tests
# For example, using `pytest`
run: make unit-test-cov-xml
# Main job runs only if pre-commit succeeded
main-job:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
python: ["3.10", "3.11", "3.12", "3.13"]
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
env:
UV_CACHE_DIR_CUSTOM: ${{ github.workspace }}\.cache\uv
steps:
- uses: actions/checkout@v3
# Set up Python
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
- name: Install uv
uses: astral-sh/setup-uv@v1 # Use the latest stable version
with:
version: 'latest' # Or a specific version like '0.1.0'
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
# Cache uv packages
# GitHub automatically handles cache eviction after 7 days of inactivity (or 10GB)
# https://docs.github.com/en/actions/working-with-workflows/caching-dependencies-to-speed-up-workflows
- name: Cache uv packages
uses: actions/cache@v3
with:
path: ${{ env.UV_CACHE_DIR_CUSTOM }}
key: ${{ runner.os }}-uv-${{ matrix.python }}-${{ matrix.package_extras }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-${{ matrix.python }}-${{ matrix.package_extras }}-
${{ runner.os }}-uv-${{ matrix.python }}-
${{ runner.os }}-uv-
# Install PyRIT with optional extras
- name: Install PyRIT with uv
# If the matrix extras is 'dev_all', then we install '.[dev,all]'
# otherwise just install the literal extras from the matrix
shell: bash
run: |
if [ "${{ matrix.package_extras }}" = "dev_all" ]; then
uv sync --extra dev --extra all --cache-dir ${{ env.UV_CACHE_DIR_CUSTOM }}
else
uv sync --cache-dir ${{ env.UV_CACHE_DIR_CUSTOM }} --only-dev
fi
- name: Run unit tests with code coverage
run: make unit-test-cov-xml
- name: Publish Pytest Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: runner.os == 'ubuntu-latest'
with:
files: '**/test-*.xml'
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
if: runner.os == 'ubuntu-latest'
with:
filename: coverage.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'