Create benchmarks #1186
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 workflow runs the tests. | |
| # It is triggered automatically on pull requests and is also run weekly on the main branch. | |
| # Tests are run in a matrix of different Python versions. | |
| # This test also uploads coverage results to Codecov. | |
| # Note: We use the insecure pull_request_target to allow running workflows from forks. | |
| # However, we've added checks (see below) for safety. | |
| # In short, the 'safe to test' label must exist AND the workflow must be run by someone with write access. | |
| # See more details here: | |
| # - https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ | |
| # - https://michaelheap.com/access-secrets-from-forks/ | |
| name: Tests | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: ["*"] | |
| pull_request_target: | |
| branches: ["*"] | |
| schedule: | |
| - cron: "0 5 * * WED" | |
| workflow_dispatch: | |
| jobs: | |
| check_permissions: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Important checks to ensure that the user has the required permissions. See note above. | |
| # Step 1: If user has current permissions we're good! | |
| - name: Get User Permission | |
| id: checkAccess | |
| uses: actions-cool/check-user-permission@v2 | |
| with: | |
| require: write | |
| username: ${{ github.actor }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Otherwise, get triggering user's permissions | |
| - name: Get Triggering User Permission | |
| if: steps.checkAccess.outputs.require-result == 'false' | |
| id: checkTriggeringAccess | |
| uses: actions-cool/check-user-permission@v2 | |
| with: | |
| require: write | |
| username: ${{ github.triggering_actor }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # If neither has permissions and no 'safe to test' label and not dependabot throw error | |
| - name: Check User Permission | |
| if: steps.checkAccess.outputs.require-result == 'false' && steps.checkTriggeringAccess.outputs.require-result == 'false' && !contains(github.event.pull_request.labels.*.name, 'safe to test') && (github.actor != 'dependabot[bot]') | |
| shell: bash | |
| run: | | |
| echo "${{ github.triggering_actor }} does not have permissions on this repo." | |
| echo "Re-run the test yourself if you have write permissions. Alternatively, add the label 'safe to test' to the PR to give the user write permissions (only if you trust them)." | |
| exit 1 | |
| run: | |
| if: | | |
| (github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') || | |
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') || | |
| (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) || | |
| (github.event_name != 'pull_request_target' && github.event_name != 'pull_request') | |
| runs-on: ubuntu-latest | |
| needs: check_permissions | |
| continue-on-error: ${{ !matrix.latest }} | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| python-version: ["3.13"] | |
| latest: [true] | |
| include: | |
| - python-version: "3.9" | |
| latest: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }} | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: "pip" | |
| - name: Setup optimizers | |
| uses: ./.github/actions/setup_optimizers_linux | |
| with: | |
| GUROBI_WLS: ${{ secrets.GUROBI_WLS }} | |
| COPT_LICENSE_KEY: ${{ secrets.COPT_LICENSE_KEY }} | |
| COPT_LICENSE_DAT: ${{ secrets.COPT_LICENSE_DAT }} | |
| CHECK_LICENSE: true | |
| - name: Install dependencies | |
| run: pip install -e .[dev] | |
| - name: Run tests and collect coverage | |
| run: pytest --cov | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4-beta | |
| with: | |
| name: coverage-python-${{ matrix.python-version }} | |
| flags: smart-tests | |
| verbose: true | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |