-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(nav): rename group to 'Generated Package References' + add sync-templates.sh #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #!/usr/bin/env bash | ||
| # Sync canonical SDK auto-doc workflows from this repo's | ||
| # `automation/source-repo-templates/` into each SDK source repo's | ||
| # `.github/workflows/api-docs.yml`. Opens a sync PR per repo when a | ||
| # diff exists; reports up-to-date when not. | ||
| # | ||
| # Mapping is hard-coded (one entry per language) because there are | ||
| # only three SDKs and each has its own repo + default-branch quirk. | ||
| # | ||
| # Requirements: | ||
| # - gh CLI authenticated with repo:write on each target repo | ||
| # - git, mktemp | ||
| # | ||
| # Usage: | ||
| # automation/sync-templates.sh # sync all 3 | ||
| # automation/sync-templates.sh dotnet # sync just dotnet | ||
| # automation/sync-templates.sh dotnet python # sync subset | ||
| # | ||
| # Flags: | ||
| # --dry-run show diffs but don't open PRs | ||
| # --auto-merge open PRs with --auto so they merge after CI | ||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| TEMPLATE_DIR="${REPO_ROOT}/automation/source-repo-templates" | ||
|
|
||
| # language|template_filename|target_repo|default_branch | ||
| TARGETS=( | ||
| "typescript|api-docs.typescript.yml|resq-software/npm|master" | ||
| "python|api-docs.python.yml|resq-software/pypi|main" | ||
| "dotnet|api-docs.dotnet.yml|resq-software/dotnet-sdk|main" | ||
| ) | ||
|
|
||
| DRY_RUN=0 | ||
| AUTO_MERGE=0 | ||
| SELECTED_LANGS=() | ||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| --dry-run) DRY_RUN=1 ;; | ||
| --auto-merge) AUTO_MERGE=1 ;; | ||
| -*) echo "unknown flag: $arg" >&2; exit 2 ;; | ||
| *) SELECTED_LANGS+=("$arg") ;; | ||
| esac | ||
| done | ||
|
|
||
| selected() { | ||
| if [ ${#SELECTED_LANGS[@]} -eq 0 ]; then | ||
| return 0 | ||
| fi | ||
| for s in "${SELECTED_LANGS[@]}"; do | ||
| [ "$s" = "$1" ] && return 0 | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| sync_one() { | ||
| local lang="$1" template_file="$2" target_repo="$3" default_branch="$4" | ||
|
|
||
| if ! selected "$lang"; then | ||
| return 0 | ||
| fi | ||
|
|
||
| local template_path="${TEMPLATE_DIR}/${template_file}" | ||
| if [ ! -f "$template_path" ]; then | ||
| echo "[$lang] missing template: $template_path" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| echo "==> [$lang] checking $target_repo" | ||
| local work | ||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "$work"' RETURN | ||
|
|
||
| local clone_dir="${work}/clone" | ||
| if ! gh repo clone "$target_repo" "$clone_dir" -- \ | ||
| --depth=1 --branch="$default_branch" --quiet 2>/dev/null; then | ||
| echo "[$lang] clone failed for $target_repo" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| local target_workflow="${clone_dir}/.github/workflows/api-docs.yml" | ||
| mkdir -p "$(dirname "$target_workflow")" | ||
| cp "$template_path" "$target_workflow" | ||
|
|
||
| if git -C "$clone_dir" diff --quiet -- .github/workflows/api-docs.yml; then | ||
| echo "[$lang] up-to-date" | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "[$lang] diff:" | ||
| git -C "$clone_dir" --no-pager diff --stat -- .github/workflows/api-docs.yml | ||
|
|
||
| if [ "$DRY_RUN" -eq 1 ]; then | ||
| echo "[$lang] dry-run, skipping PR" | ||
| return 0 | ||
| fi | ||
|
|
||
| local branch="sync/api-docs-template" | ||
| local commit_msg | ||
| commit_msg="$(cat <<EOF | ||
| ci(api-docs): sync workflow from resq-software/docs | ||
|
|
||
| Sync .github/workflows/api-docs.yml from the canonical template at | ||
| automation/source-repo-templates/${template_file} in | ||
| resq-software/docs. | ||
|
|
||
| Generated by automation/sync-templates.sh. | ||
| EOF | ||
| )" | ||
|
|
||
| ( | ||
| cd "$clone_dir" | ||
| git checkout -b "$branch" | ||
| git add .github/workflows/api-docs.yml | ||
| git -c user.email=engineer@resq.software \ | ||
| -c user.name="resq-sw" \ | ||
| commit -m "$commit_msg" | ||
| git push -u origin "$branch" --force-with-lease | ||
| ) | ||
|
|
||
| local pr_url | ||
| pr_url="$(gh pr create \ | ||
| --repo "$target_repo" \ | ||
| --base "$default_branch" \ | ||
| --head "$branch" \ | ||
| --title "ci(api-docs): sync workflow from resq-software/docs" \ | ||
| --body "Sync from canonical template \`automation/source-repo-templates/${template_file}\`. Auto-generated by \`automation/sync-templates.sh\`." \ | ||
| 2>&1 | tail -1)" | ||
| echo "[$lang] $pr_url" | ||
|
Comment on lines
+98
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
for repo in resq-software/npm resq-software/pypi resq-software/dotnet-sdk; do
echo "==> $repo"
gh pr list \
--repo "$repo" \
--state open \
--head sync/api-docs-template \
--json number,url,headRefName,baseRefName \
--jq '.[] | "\(.number) \(.url) [\(.headRefName)->\(.baseRefName)]"'
doneRepository: resq-software/docs Length of output: 136 🌐 Web query:
💡 Result: When using GitHub CLI (gh) to create a PR, if the head branch and base branch resolve to the exact same ref within the same repository, gh pr create does NOT proceed; it errors out early. Specifically, gh/cli added an isSameRef check that returns true when head and base point to the same ref in the same repo, and createRun then returns: Citations:
🏁 Script executed: # Verify the gh pr list syntax and jq filter from the suggested fix
# Also check if gh pr create indeed fails on duplicate head/base
# Test: Simulate the suggested check command to verify syntax
gh pr list \
--repo "resq-software/npm" \
--state open \
--head "sync/api-docs-template" \
--base "main" \
--json url \
--jq '.[0].url' 2>&1 | head -20Repository: resq-software/docs Length of output: 63 Make PR creation idempotent when This always calls 🛠️ Suggested diff- local pr_url
- pr_url="$(gh pr create \
- --repo "$target_repo" \
- --base "$default_branch" \
- --head "$branch" \
- --title "ci(api-docs): sync workflow from resq-software/docs" \
- --body "Sync from canonical template \`automation/source-repo-templates/${template_file}\`. Auto-generated by \`automation/sync-templates.sh\`." \
- 2>&1 | tail -1)"
+ local pr_url
+ pr_url="$(gh pr list \
+ --repo "$target_repo" \
+ --state open \
+ --head "$branch" \
+ --base "$default_branch" \
+ --json url \
+ --jq '.[0].url')"
+ if [ -z "$pr_url" ]; then
+ pr_url="$(gh pr create \
+ --repo "$target_repo" \
+ --base "$default_branch" \
+ --head "$branch" \
+ --title "ci(api-docs): sync workflow from resq-software/docs" \
+ --body "Sync from canonical template \`automation/source-repo-templates/${template_file}\`. Auto-generated by \`automation/sync-templates.sh\`." )"
+ fi
echo "[$lang] $pr_url"🤖 Prompt for AI Agents |
||
|
|
||
| if [ "$AUTO_MERGE" -eq 1 ]; then | ||
| gh pr merge "$pr_url" --repo "$target_repo" --squash --auto --delete-branch || true | ||
| echo "[$lang] auto-merge enabled" | ||
| fi | ||
|
Comment on lines
+122
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current PR creation and merging logic has several issues:
The suggested refactor addresses these by using a safer capture method, adding a fallback for existing PRs, and ensuring non-zero exit codes on failure. if ! pr_url=$(gh pr create \
--repo "$target_repo" \
--base "$default_branch" \
--head "$branch" \
--title "ci(api-docs): sync workflow from resq-software/docs" \
--body "Sync from canonical template \`automation/source-repo-templates/${template_file}\`. Auto-generated by \`automation/sync-templates.sh\`." 2>/dev/null); then
# Fallback: if PR already exists, fetch its URL
pr_url=$(gh pr view "$branch" --repo "$target_repo" --json url -q .url 2>/dev/null || true)
fi
if [ -z "$pr_url" ]; then
echo "[$lang] failed to create or find PR" >&2
return 1
fi
echo "[$lang] $pr_url"
if [ "$AUTO_MERGE" -eq 1 ]; then
if ! gh pr merge "$pr_url" --repo "$target_repo" --squash --auto --delete-branch; then
echo "[$lang] auto-merge failed" >&2
return 1
fi
echo "[$lang] auto-merge enabled"
fi |
||
| } | ||
|
|
||
| failed=0 | ||
| for entry in "${TARGETS[@]}"; do | ||
| IFS='|' read -r lang template repo branch <<<"$entry" | ||
| if ! sync_one "$lang" "$template" "$repo" "$branch"; then | ||
| failed=$((failed + 1)) | ||
| fi | ||
| done | ||
|
|
||
| if [ "$failed" -gt 0 ]; then | ||
| echo "==> $failed sync target(s) failed" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "==> done" | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| """Splice each SDK's _pages.json into docs.json's `Generated API Reference` | ||||||
| """Splice each SDK's _pages.json into docs.json's `Generated Package References` | ||||||
| sub-group for that language. | ||||||
|
|
||||||
| Builds a hierarchical groups structure from page IDs of the form | ||||||
|
|
@@ -161,12 +161,12 @@ def main() -> int: | |||||
| readme_id = f"{prefix}/README" | ||||||
| new_subgroups.append(build_lang_group(label, prefix, pages_path, readme_id)) | ||||||
|
|
||||||
| # Find Generated API Reference under en > SDKs > groups | ||||||
| # Find Generated Package References under en > SDKs > groups | ||||||
| en = next(l for l in docs["navigation"]["languages"] if l["language"] == "en") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename the ambiguous generator variable to satisfy Ruff E741.
🧩 Suggested diff- en = next(l for l in docs["navigation"]["languages"] if l["language"] == "en")
+ en = next(lang_entry for lang_entry in docs["navigation"]["languages"] if lang_entry["language"] == "en")📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.12)[error] 165-165: Ambiguous variable name: (E741) 🤖 Prompt for AI Agents |
||||||
| sdks_tab = next(t for t in en["tabs"] if t["tab"] == "SDKs") | ||||||
| gen_group = next( | ||||||
| g for g in sdks_tab["groups"] | ||||||
| if g["group"] == "Generated API Reference" | ||||||
| if g["group"] == "Generated Package References" | ||||||
| ) | ||||||
| gen_group["pages"] = new_subgroups | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiding stderr from
gh repo cloneusing2>/dev/nullmakes it difficult to diagnose failures (e.g., authentication issues or repository permission errors). Removing the redirection will provide better visibility when a sync target fails to clone.