|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths-ignore: |
| 6 | + - 'docs/**' |
| 7 | + branches: |
| 8 | + - main |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + paths-ignore: |
| 13 | + - 'docs/**' |
| 14 | + types: [opened, synchronize] |
| 15 | + |
| 16 | + # Allows workflows to be manually triggered |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.ref }} |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + code-quality: |
| 25 | + name: code-quality |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: repository checkout step |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: python environment step |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: "3.11" |
| 35 | + |
| 36 | + - name: install pre-commit |
| 37 | + run: python3 -m pip install pre-commit |
| 38 | + |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: Get changed files |
| 45 | + id: changed-files |
| 46 | + run: | |
| 47 | + CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ') |
| 48 | + echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + - name: Print changed files |
| 51 | + run: | |
| 52 | + echo "Changed files: $CHANGED_FILES" |
| 53 | +
|
| 54 | + - name: Run pre-commit on changed files |
| 55 | + run: | |
| 56 | + if [ -n "$CHANGED_FILES" ]; then |
| 57 | + pre-commit run --color always --files $CHANGED_FILES --show-diff-on-failure |
| 58 | + else |
| 59 | + echo "No changed files to check." |
| 60 | + fi |
| 61 | +
|
| 62 | + run-tests-no-extras: |
| 63 | + needs: code-quality |
| 64 | + strategy: |
| 65 | + fail-fast: false |
| 66 | + matrix: |
| 67 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 68 | + os: [ubuntu-latest, windows-latest, macOS-latest] |
| 69 | + runs-on: ${{ matrix.os }} |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - run: git remote set-branches origin 'main' |
| 74 | + |
| 75 | + - run: git fetch --depth 1 |
| 76 | + |
| 77 | + - name: Set up Python |
| 78 | + uses: actions/setup-python@v5 |
| 79 | + with: |
| 80 | + python-version: ${{ matrix.python-version }} |
| 81 | + |
| 82 | + - name: Display Python version |
| 83 | + run: python -c "import sys; print(sys.version)" |
| 84 | + |
| 85 | + - name: Install package and dependencies |
| 86 | + run: | |
| 87 | + python -m pip install .[dev] --no-cache-dir |
| 88 | +
|
| 89 | + - name: Show dependencies |
| 90 | + run: python -m pip list |
| 91 | + |
| 92 | + - name: Show available branches |
| 93 | + run: git branch -a |
| 94 | + |
| 95 | + - name: Run tests |
| 96 | + run: | |
| 97 | + python -m pytest pyaptamer -p no:warnings |
0 commit comments