Skip to content

Commit 9d2129d

Browse files
committed
script + simplify
1 parent d136e51 commit 9d2129d

4 files changed

Lines changed: 72 additions & 65 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Script to copy a generated markdown file to the Haystack API reference (integrations-api).
3+
4+
Assumes that Haystack Docs Website is available in the working directory.
5+
Copies the file to the main API reference and the versioned API references.
6+
7+
Usage:
8+
python copy_file_to_api_reference.py <generated_markdown_file>
9+
"""
10+
11+
import argparse
12+
import os
13+
import shutil
14+
15+
def copy_file_to_api_reference(generated_markdown_file: str):
16+
shutil.copy(generated_markdown_file, "docs-website/reference/integrations-api/")
17+
for version_dir in os.scandir("docs-website/reference_versioned_docs"):
18+
if version_dir.is_dir():
19+
# example: docs-website/reference_versioned_docs/version-2.17/integrations-api
20+
integrations_api_ref_dir = os.path.join(version_dir.path, "integrations-api")
21+
shutil.copy(generated_markdown_file, integrations_api_ref_dir)
22+
23+
if __name__ == "__main__":
24+
parser = argparse.ArgumentParser()
25+
parser.add_argument("generated_markdown_file", type=str, help="Path to the generated markdown file")
26+
args = parser.parse_args()
27+
copy_file_to_api_reference(args.generated_markdown_file)

.github/utils/pyproject_to_requirements.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import argparse
2-
import sys
32
from pathlib import Path
43
import toml
54

.github/workflows/CI_check_api_ref.yml

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88

99
jobs:
1010
detect-changes:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-slim
1212
outputs:
1313
integrations: ${{ steps.changed.outputs.integrations }}
1414
steps:
1515
- uses: actions/checkout@v6
1616
with:
1717
fetch-depth: 0
1818

19-
- name: Set up Python 3.13
19+
- name: Set up Python
2020
uses: actions/setup-python@v6
2121
with:
2222
python-version: "3.13"
@@ -26,7 +26,6 @@ jobs:
2626
shell: python
2727
env:
2828
BASE_SHA: ${{ github.event.pull_request.base.sha }}
29-
RUNNER_TEMP: ${{ runner.temp }}
3029
run: |
3130
import json
3231
import os
@@ -44,45 +43,50 @@ jobs:
4443
result = subprocess.run(["git", *args], capture_output=True, text=True)
4544
return result.stdout.strip(), result.returncode
4645
47-
# Find integrations with changed .py or config files
48-
diff_output, _ = git("diff", "--name-only", f"{base_sha}...HEAD",
49-
"--", "integrations/**/*.py", "integrations/**/config_docusaurus.yml")
50-
candidates = sorted({Path(p).parts[1] for p in diff_output.splitlines() if p.startswith("integrations/")})
46+
# Get all changed files
47+
diff_output, _ = git(
48+
"diff", "--name-only", f"{base_sha}...HEAD", "--", "integrations"
49+
)
50+
changed_files = set(diff_output.splitlines())
51+
52+
# Extract integration names
53+
candidates = sorted({
54+
Path(p).parts[1]
55+
for p in changed_files
56+
if p.startswith("integrations/") and len(Path(p).parts) > 1
57+
})
5158
52-
# Create base worktree once for docstring comparison
59+
# Create base worktree for docstring comparison
5360
base_worktree = os.path.join(runner_temp, "base")
54-
_, rc = git("worktree", "add", base_worktree, base_sha)
55-
has_worktree = rc == 0
61+
_, return_code = git("worktree", "add", base_worktree, base_sha)
62+
has_worktree = return_code == 0
5663
57-
result = []
64+
changed_integrations = []
65+
5866
for integration in candidates:
5967
# If pydoc config changed, always include
60-
config_diff, _ = git("diff", "--name-only", f"{base_sha}...HEAD",
61-
"--", f"integrations/{integration}/pydoc/config_docusaurus.yml")
62-
if config_diff:
63-
result.append(integration)
68+
if f"integrations/{integration}/pydoc/config_docusaurus.yml" in changed_files:
69+
changed_integrations.append(integration)
6470
continue
6571
6672
# Otherwise, check if docstrings changed
67-
pr_checksum = docstrings_checksum(Path(".").glob(f"integrations/{integration}/**/*.py"))
73+
pr_docstrings_checksum = docstrings_checksum(Path(".").glob(f"integrations/{integration}/**/*.py"))
74+
base_docstrings_checksum = ""
6875
if has_worktree:
69-
base_checksum = docstrings_checksum(Path(base_worktree).glob(f"integrations/{integration}/**/*.py"))
70-
else:
71-
# Integration doesn't exist on the base branch (new integration)
72-
base_checksum = ""
76+
base_docstrings_checksum = docstrings_checksum(Path(base_worktree).glob(f"integrations/{integration}/**/*.py"))
7377
74-
if base_checksum != pr_checksum:
75-
result.append(integration)
78+
if base_docstrings_checksum != pr_docstrings_checksum:
79+
changed_integrations.append(integration)
7680
7781
if has_worktree:
7882
git("worktree", "remove", base_worktree)
7983
80-
print(f"Integrations with API reference changes: {json.dumps(result)}")
84+
print(f"Integrations with API reference changes: {json.dumps(changed_integrations)}")
8185
8286
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
83-
f.write(f"integrations={json.dumps(result)}\n")
87+
f.write(f"integrations={json.dumps(changed_integrations)}\n")
8488
85-
generate-docs:
89+
test-api-reference-build:
8690
needs: detect-changes
8791
if: needs.detect-changes.outputs.integrations != '[]'
8892
runs-on: ubuntu-latest
@@ -107,34 +111,18 @@ jobs:
107111
hatch run docs
108112
# Save the generated file before the Haystack checkout overwrites the working tree
109113
cp ${{ matrix.integration }}.md "${{ runner.temp }}/${{ matrix.integration }}.md"
114+
# Also copy the Copy script to the temp directory
115+
cp .github/utils/copy_file_to_api_reference.py "${{ runner.temp }}/copy_file_to_api_reference.py"
110116
111-
- name: Checkout Haystack repo
117+
- name: Checkout Haystack Docs Website
112118
uses: actions/checkout@v6
113119
with:
114120
repository: deepset-ai/haystack
115121
ref: main
116122
sparse-checkout: docs-website
117123

118-
- name: Sync API reference
119-
shell: python
120-
env:
121-
INTEGRATION_API_REFERENCE: ${{ runner.temp }}/${{ matrix.integration }}.md
122-
run: |
123-
import os
124-
import shutil
125-
126-
api_ref_file = os.environ['INTEGRATION_API_REFERENCE']
127-
128-
# Copy to main API reference
129-
shutil.copy(api_ref_file, "docs-website/reference/integrations-api/")
130-
131-
# Copy to versioned API reference
132-
for version_dir in os.scandir("docs-website/reference_versioned_docs"):
133-
if version_dir.is_dir():
134-
# example: docs-website/reference_versioned_docs/version-2.17/integrations-api
135-
integrations_api_ref_dir = os.path.join(version_dir.path, "integrations-api")
136-
shutil.copy(api_ref_file, integrations_api_ref_dir)
137-
124+
- name: Copy file to API reference
125+
run: python ${{ runner.temp }}/copy_file_to_api_reference.py ${{ runner.temp }}/${{ matrix.integration }}.md
138126
- name: Install Node.js
139127
uses: actions/setup-node@v6
140128
with:

.github/workflows/CI_docusaurus_sync.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,30 @@ jobs:
7272
ref: main
7373
token: ${{ secrets.HAYSTACK_BOT_TOKEN }}
7474

75+
- name: Checkout this repo for the script
76+
uses: actions/checkout@v6
77+
with:
78+
path: core-integrations
79+
sparse-checkout: |
80+
.github/utils/copy_file_to_api_reference.py
81+
7582
- name: Set up Python
7683
uses: actions/setup-python@v6
7784
with:
78-
python-version: "3.10"
85+
python-version: "3.10"
7986

8087
- name: Download API reference artifact
8188
uses: actions/download-artifact@v7
8289
with:
8390
name: ${{ needs.generate-api-reference.outputs.integration_name }}
8491

8592
- name: Sync API reference
86-
shell: python
8793
env:
8894
INTEGRATION_NAME: ${{ needs.generate-api-reference.outputs.integration_name }}
8995
run: |
90-
import os
91-
import shutil
92-
93-
artifact_filename = os.environ['INTEGRATION_NAME']+'.md'
94-
95-
# Copy to main API reference
96-
shutil.copy(artifact_filename, "docs-website/reference/integrations-api/")
97-
98-
# Copy to versioned API reference
99-
for version_dir in os.scandir("docs-website/reference_versioned_docs"):
100-
if version_dir.is_dir():
101-
# example: docs-website/reference_versioned_docs/version-2.17/integrations-api
102-
integrations_api_ref_dir = os.path.join(version_dir.path, "integrations-api")
103-
shutil.copy(artifact_filename, integrations_api_ref_dir)
104-
105-
os.remove(artifact_filename)
96+
artifact_filename="${INTEGRATION_NAME}.md"
97+
python core-integrations/.github/utils/copy_file_to_api_reference.py "$artifact_filename"
98+
rm "$artifact_filename"
10699
107100
- name: Create Pull Request
108101
uses: peter-evans/create-pull-request@v8

0 commit comments

Comments
 (0)