Feature/tool catalog implementation #5
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
| 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 | |
| CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'tools/' \ | |
| | grep -oP 'tools/[^/]+/[^/]+/[^/]+/' \ | |
| | sort -u \ | |
| | 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 | |
| - name: Lint changed tools | |
| run: | | |
| DIRS='${{ needs.detect-changes.outputs.matrix }}' | |
| echo "$DIRS" | jq -r '.[]' | while read -r dir; do | |
| echo "::group::ruff $dir" | |
| /tmp/validate_venv/bin/python -m ruff check "$dir" | |
| echo "::endgroup::" | |
| 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 |