Merge branch 'Azure:main' into main #19
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
| # Builds the pyrit environment and runs all tests and pre-commit hooks | |
| name: build_and_test | |
| 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 job runs only once on Ubuntu | |
| pre-commit: | |
| runs-on: ubuntu-latest | |
| env: | |
| PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-python@v3 | |
| with: | |
| python-version: 3.11 | |
| - name: Cache pip packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ env.PIP_CACHE_DIR }} | |
| key: ${{ runner.os }}-pip-3.11-${{ hashFiles('pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-3.11- | |
| ${{ runner.os }}-pip- | |
| - 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: Upgrade pip and setuptools | |
| run: python -m pip install --upgrade pip setuptools packaging | |
| - name: Install dev extras | |
| run: pip install --cache-dir "$PIP_CACHE_DIR" .[dev,all] | |
| - name: Run pre-commit incrementally (on PR) | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| git fetch origin main | |
| pre-commit run --from-ref origin/main --to-ref HEAD | |
| - name: Run pre-commit fully (on main) | |
| if: github.ref == 'refs/heads/main' | |
| 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] | |
| python: ["3.10", "3.11", "3.12", "3.13"] | |
| package_name: ["pyrit"] | |
| package_extras: ["dev", "dev_all"] | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip | |
| # 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@v3 | |
| # Set up Python | |
| - uses: actions/setup-python@v3 | |
| with: | |
| python-version: ${{ matrix.python }} | |
| # Cache pip packages | |
| # GitHub automatically handles cache eviction after 7 days of inactivity (or 10GB) | |
| # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows | |
| - name: Cache pip packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ env.PIP_CACHE_DIR }} | |
| key: ${{ runner.os }}-pip-${{ matrix.python }}-${{ matrix.package_extras }}-${{ hashFiles('pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-${{ matrix.python }}-${{ matrix.package_extras }}- | |
| ${{ runner.os }}-pip-${{ matrix.python }}- | |
| ${{ runner.os }}-pip- | |
| - name: Install setuptools and pip | |
| run: python -m pip install --upgrade pip setuptools packaging | |
| # Install PyRIT with optional extras | |
| - name: Install PyRIT with pip | |
| # 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 | |
| extras="dev,all" | |
| else | |
| extras="${{ matrix.package_extras }}" | |
| fi | |
| pip install --cache-dir "$PIP_CACHE_DIR" ".[${extras}]" | |
| - 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/[email protected] | |
| 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' |