mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-08 21:28:00 +00:00
Add a workflow to verify haystack.preview doesn't import non preview modules (#6053)
This commit is contained in:
parent
32e87d37c1
commit
c78e1a7eb3
55
.github/workflows/preview_imports.yml
vendored
Normal file
55
.github/workflows/preview_imports.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
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)
|
||||
Loading…
x
Reference in New Issue
Block a user