Merge pull request #33 from UKHD-NP/fix/williams-2018-missing-value-h… #205
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
| # python linting - pylint and flake8 | |
| # pytest | |
| name: Python application using pip | |
| on: | |
| push: | |
| branches: [ "main", "dev*", "dev/**" ] | |
| pull_request: | |
| branches: [ "main", "dev*", "dev/**" ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: ["3.10", "3.11"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| shell: bash | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pre-commit pytest | |
| if [ -f "requirements/requirements_ci-cd.txt" ]; then | |
| pip install -r requirements/requirements_ci-cd.txt | |
| fi | |
| - name: Install package | |
| shell: bash | |
| run: | | |
| pip install -e . | |
| - name: Compute diff range | |
| id: range | |
| shell: bash | |
| run: | | |
| # Pick initial from/to refs per event type. | |
| if [ -n "${{ github.event.pull_request.base.sha }}" ]; then | |
| FROM="${{ github.event.pull_request.base.sha }}" | |
| TO="${{ github.event.pull_request.head.sha }}" | |
| elif [ -n "${{ github.event.before }}" ] \ | |
| && [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then | |
| FROM="${{ github.event.before }}" | |
| TO="${{ github.sha }}" | |
| else | |
| FROM="HEAD~1" | |
| TO="HEAD" | |
| fi | |
| # Guard: after a force-push, `event.before` may point at an | |
| # orphaned commit no longer reachable in CI's fetched history. | |
| # Fall back to the merge-base with origin/main so lint covers | |
| # the branch's divergence (mirrors what a PR would lint). | |
| # For pushes to main itself, no divergence exists; use HEAD~1. | |
| if ! git cat-file -e "${FROM}^{commit}" 2>/dev/null; then | |
| if [ "${{ github.ref_name }}" = "main" ]; then | |
| echo "::warning::from-ref ${FROM} unreachable on main; falling back to HEAD~1..HEAD" | |
| FROM="HEAD~1" | |
| elif MB=$(git merge-base origin/main HEAD 2>/dev/null); then | |
| echo "::warning::from-ref ${FROM} unreachable (likely force-push); falling back to merge-base with origin/main ($MB)" | |
| FROM="$MB" | |
| else | |
| echo "::warning::from-ref ${FROM} unreachable and no merge-base with origin/main; falling back to HEAD~1..HEAD" | |
| FROM="HEAD~1" | |
| fi | |
| TO="HEAD" | |
| fi | |
| echo "from=$FROM" >> "$GITHUB_OUTPUT" | |
| echo "to=$TO" >> "$GITHUB_OUTPUT" | |
| - name: Cache pre-commit envs | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pre-commit | |
| key: pre-commit-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} | |
| - name: Lint via pre-commit (changed files only) | |
| shell: bash | |
| run: | | |
| pre-commit run \ | |
| --from-ref "${{ steps.range.outputs.from }}" \ | |
| --to-ref "${{ steps.range.outputs.to }}" \ | |
| --show-diff-on-failure | |
| - name: Get month | |
| id: date | |
| shell: bash | |
| run: echo "month=$(date +'%Y-%m')" >> "$GITHUB_OUTPUT" | |
| - name: Get pooch cache directory | |
| id: cache-dir | |
| shell: python | |
| run: | | |
| import pooch, os | |
| cache = str(pooch.os_cache("proteopy")) | |
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
| f.write(f"path={cache}\n") | |
| - name: Cache downloaded datasets | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.cache-dir.outputs.path }} | |
| key: proteopy-datasets-${{ runner.os }}-${{ steps.date.outputs.month }} | |
| - name: Test with pytest | |
| run: | | |
| pytest -v -s tests/ |