mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-05 19:47:45 +00:00
56 lines
1.5 KiB
YAML
56 lines
1.5 KiB
YAML
name: Verify preview imports only preview
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- opened
|
|
- reopened
|
|
- synchronize
|
|
- ready_for_review
|
|
paths:
|
|
- "haystack/preview/**.py"
|
|
|
|
jobs:
|
|
verify-imports:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
# With the default value of 1, there are corner cases where tj-actions/changed-files
|
|
# fails with a `no merge base` error
|
|
fetch-depth: 0
|
|
|
|
- name: Get changed files
|
|
id: files
|
|
uses: tj-actions/changed-files@v39
|
|
with:
|
|
files: |
|
|
haystack/preview/**.py
|
|
|
|
- name: Check imports
|
|
shell: python
|
|
run: |
|
|
import re
|
|
regex = r"^(from haystack|import haystack)(?!\.preview| import preview)(.*)"
|
|
|
|
changed_files = "${{ steps.files.outputs.all_changed_files }}".split()
|
|
matches = {}
|
|
for path in changed_files:
|
|
with open(path, "r") as f:
|
|
file_matches = []
|
|
for line in f.readlines():
|
|
file_matches.extend(re.finditer(regex, line.strip()))
|
|
if file_matches:
|
|
matches[path] = file_matches
|
|
|
|
for path, match in matches.items():
|
|
print(f"Bad imports in file '{path}'")
|
|
for m in match:
|
|
print(m.group())
|
|
print()
|
|
|
|
if matches:
|
|
print("::error:: Imports in haystack.preview can only import from haystack.preview")
|
|
import sys; sys.exit(1)
|