-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (72 loc) · 2.74 KB
/
validate.yml
File metadata and controls
81 lines (72 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Validate Tools
on:
pull_request:
paths:
- 'tools/**'
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.detect.outputs.matrix }}
has_changes: ${{ steps.detect.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: detect
name: Detect changed tool directories
run: |
# Note: github.base_ref is only available on pull_request events
# Find all tool directories that changed in this PR, keeping only
# those that still exist (deleted tool dirs must not be linted/tested).
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'tools/' \
| grep -oP 'tools/[^/]+/[^/]+/[^/]+/' \
| sort -u \
| while read -r dir; do [ -d "$dir" ] && echo "$dir"; done \
| jq -R -s -c 'split("\n") | map(select(length > 0))')
if [ "$CHANGED" = "[]" ] || [ -z "$CHANGED" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "matrix=[]" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "matrix=$CHANGED" >> "$GITHUB_OUTPUT"
fi
validate:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Create shared venv and install dependencies
run: |
python -m venv /tmp/validate_venv
/tmp/validate_venv/bin/python -m pip install pyopenms numpy scipy click pytest ruff
DIRS='${{ needs.detect-changes.outputs.matrix }}'
echo "$DIRS" | jq -r '.[]' | while read -r dir; do
if [ -f "${dir}requirements.txt" ]; then
/tmp/validate_venv/bin/python -m pip install -r "${dir}requirements.txt"
fi
done
- name: Lint changed tools
run: |
DIRS='${{ needs.detect-changes.outputs.matrix }}'
echo "$DIRS" | jq -r '.[]' | while read -r dir; do
if [ -d "$dir" ]; then
echo "::group::ruff $dir"
/tmp/validate_venv/bin/python -m ruff check "$dir"
echo "::endgroup::"
fi
done
- name: Test changed tools
run: |
DIRS='${{ needs.detect-changes.outputs.matrix }}'
echo "$DIRS" | jq -r '.[]' | while read -r dir; do
if [ -d "${dir}tests/" ]; then
echo "::group::pytest $dir"
PYTHONPATH="$dir" /tmp/validate_venv/bin/python -m pytest "${dir}tests/" -v
echo "::endgroup::"
fi
done