Skip to content

Commit adc0bda

Browse files
authored
feat: api-reference works for forks (#1789)
* feat: api-reference works for forks * wip * wip * fix
1 parent 9df0993 commit adc0bda

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,20 @@ jobs:
247247
}}
248248
steps:
249249
- uses: actions/checkout@v4
250+
- name: Set git revision
251+
id: set-revision
252+
run: |
253+
if [ -n "${{ github.event.pull_request.number }}" ]; then
254+
echo "revision=pull/${{ github.ref_name }}" >> $GITHUB_OUTPUT
255+
else
256+
echo "revision=${{ github.ref_name }}" >> $GITHUB_OUTPUT
257+
fi
258+
echo "revision_name=${{ github.head_ref || github.ref_name }}" >> $GITHUB_OUTPUT
250259
- name: 📚 Generate and upload API reference
251260
uses: ./.github/share-actions/generate-and-save-api-reference
252261
with:
253-
source-flag: --git-revision ${{ github.head_ref || github.ref_name }}
262+
source-flag: --git-revision ${{ steps.set-revision.outputs.revision }}
263+
additional-flags: --git-revision-name ${{ steps.set-revision.outputs.revision_name }}
254264

255265
download-and-deploy-api-reference:
256266
name: Download and deploy API reference documentation

api-reference/generate.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,16 @@ def build_with_flag_for_evidently(evidently_ref: str) -> list[str]:
110110
return [flag, evidently_ref]
111111

112112

113-
def format_revision_name(revision: str) -> str:
114-
"""Format a git revision (branch, tag, or commit) into a clean directory name format."""
113+
def get_revision_info(revision: str) -> tuple[str, str]:
115114
# Check if it's a hash (hexadecimal string, typically 7-40 characters)
116-
if re.match(r"^[0-9a-f]{7,40}$", revision.lower()):
117-
prefix = "hash-"
118-
# Check if it's a branch (contains "/" which is common in branch names)
119-
elif "/" in revision:
120-
prefix = "branch-"
121-
else:
122-
# Leave as is (could be a tag or simple branch name)
123-
prefix = ""
115+
revision = revision.lower()
116+
if re.match(r"^[0-9a-f]{7,40}$", revision):
117+
return (revision, f"hash: {revision}")
118+
# Check if it's a semver version (e.g., v1.2.3, 1.2.3)
119+
elif re.match(r"^v?\d+\.\d+\.\d+$", revision):
120+
return (revision, revision)
124121

125-
formatted = revision.replace("/", "-").lower()
126-
return f"{prefix}{formatted}" if prefix else formatted
122+
return (revision.replace("/", "-"), f"branch: {revision}")
127123

128124

129125
def format_local_path(path: Path) -> str:
@@ -143,6 +139,7 @@ def generate_docs_by_git_revision(
143139
modules: list[str] | None = None,
144140
repo_url: str | None = None,
145141
api_reference_index_href: str = "/",
142+
git_revision_name: str | None = None,
146143
) -> None:
147144
"""Generate documentation from a git revision (branch, tag, or commit)."""
148145
github_repo_url = repo_url or GITHUB_REPO_URL
@@ -152,9 +149,11 @@ def generate_docs_by_git_revision(
152149
becho("Generating documentation for git revision...")
153150
yecho(revision)
154151

155-
version = format_revision_name(revision).replace("-", ": ", 1)
156-
github_blob_url = f"{github_blob_prefix}/{revision}/src/evidently/"
157-
output_path = OUTPUT_DIR_PATH / format_revision_name(revision)
152+
revision_name = git_revision_name if git_revision_name else revision
153+
154+
path_to_artifact, version = get_revision_info(revision_name)
155+
github_blob_url = f"{github_blob_prefix}/{revision_name}/src/evidently/"
156+
output_path = OUTPUT_DIR_PATH / path_to_artifact
158157

159158
modules_to_use = merge_additional_modules_with_defaults(modules)
160159

@@ -301,6 +300,11 @@ def generate_docs(
301300
api_reference_index_href: str = Option(
302301
"/", "--api-reference-index-href", help="Href path for the 'All versions' link (default: '/')"
303302
),
303+
git_revision_name: str = Option(
304+
None,
305+
"--git-revision-name",
306+
help="Custom name for output directory when using --git-revision (default: auto-formatted revision name)",
307+
),
304308
):
305309
"""Generate documentation for Evidently.
306310
@@ -341,6 +345,7 @@ def generate_docs(
341345
modules=modules_list,
342346
repo_url=repo_url,
343347
api_reference_index_href=api_reference_index_href,
348+
git_revision_name=git_revision_name,
344349
)
345350
elif local_source_code:
346351
generate_docs_from_local_source(

0 commit comments

Comments
 (0)