Skip to content

ci: optimize pr-check-secondary-examples workflow (#1949)#2292

Open
Mounil2005 wants to merge 8 commits into
hiero-ledger:mainfrom
Mounil2005:optimize-examples-workflow
Open

ci: optimize pr-check-secondary-examples workflow (#1949)#2292
Mounil2005 wants to merge 8 commits into
hiero-ledger:mainfrom
Mounil2005:optimize-examples-workflow

Conversation

@Mounil2005
Copy link
Copy Markdown
Contributor

Description:

Optimize the pr-check-secondary-examples workflow to eliminate unnecessary CI runs
and reduce resource consumption, addressing the 16,000+ minutes/month reported in #1949.
Builds on the Node.js approach from exploreriii's prior work in #2073.

  • Restrict push trigger to main and add paths filter (examples/**, src/**,
    workflow file) so the job skips documentation-only and unrelated changes
  • Add concurrency group with cancel-in-progress: true to cancel stale runs
    on force-push or rapid commits
  • Replace inline bash loop with a two-phase Node.js script: Phase 1 runs only
    examples changed in the PR (fast feedback); Phase 2 runs the rest as a full
    regression check, only if Phase 1 passes
  • Use spawnSync with an argument array instead of shell string interpolation
    when invoking uv run -m, eliminating the Codacy command-injection warning
  • Reuse git ls-files examples pattern from pr-check-test-files.js for
    consistent file discovery across CI scripts
  • Add Jest test suite (18 scenarios) covering toModule, getAllExamples,
    getChangedExamples, computeExecutionPlan, runExample, and runAll;
    runs in workflow before Solo network spins up so failures surface early
  • Add jest.config.js scoping Jest to __tests__/ — pre-existing scripts
    use Node's built-in node:test runner and are incompatible with Jest
  • Add timeout-minutes: 30 to prevent hung runs from blocking CI indefinitely

Related issue(s):

Fixes #1949

Notes for reviewer:

This builds directly on exploreriii's draft PR #2073 (ci: guard examples and optimise on diff), which was closed due to inactivity. The two-phase execution
strategy and Node.js script structure are preserved; the following gaps from
that PR are addressed here:

  • Codacy command-injection warning: fixed via spawnSync with arg array
  • Jest scoping: jest.config.js added so pre-existing node:test files are
    not accidentally picked up by Jest
  • Additional test scenarios added to reach full coverage of the script's
    exported functions

The workflow change is backwards-compatible — workflow_dispatch is retained
so the job can still be triggered manually for any branch.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Copilot AI review requested due to automatic review settings May 15, 2026 13:00
@Mounil2005 Mounil2005 requested review from a team as code owners May 15, 2026 13:00
@github-actions github-actions Bot added scope: CI/CD involves continuous integration or delivery skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples labels May 15, 2026
@Mounil2005 Mounil2005 marked this pull request as draft May 15, 2026 13:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes the pr-check-secondary-examples workflow to reduce CI minutes by adding path/branch trigger filters, concurrency cancellation, a two-phase Node.js runner (changed examples first, full set second), a timeout, and a Jest-based test suite for the runner script. Also drops the pinned soloVersion, mirrorNodeVersion, and hieroVersion parameters from the hiero-solo-action step (unrelated to the optimization).

Changes:

  • Restrict push/pull_request triggers via branch+paths filters; add concurrency with cancel-in-progress and a 30-minute job timeout.
  • Replace the inline bash example loop with a Node.js script using spawnSync and a two-phase changed/remaining execution plan.
  • Add package.json, package-lock.json, jest.config.js, and a Jest unit test suite for the runner; ignore node_modules and .claude/.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
.github/workflows/pr-check-secondary-examples.yml Adds triggers/paths filter, concurrency, timeout, Node setup, npm test step, invokes new JS runner; also unpins solo/mirror/hiero versions.
.github/scripts/pr-check-secondary-examples.js New two-phase runner using git ls-files, git diff, and spawnSync("uv", ...).
.github/scripts/tests/pr-check-secondary-examples.test.js Jest tests covering toModule, getAllExamples, getChangedExamples, computeExecutionPlan, runExample, runAll.
.github/scripts/jest.config.js Scopes Jest to __tests__/ to avoid picking up existing node:test scripts.
.github/scripts/package.json / package-lock.json Adds Jest as a dev dependency for the CI script tests.
.gitignore Ignores .github/scripts/node_modules/ and .claude/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/pr-check-secondary-examples.yml
Comment thread .github/workflows/pr-check-secondary-examples.yml
Comment thread .github/workflows/pr-check-secondary-examples.yml Outdated
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/workflows/pr-check-secondary-examples.yml
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
@Mounil2005 Mounil2005 force-pushed the optimize-examples-workflow branch from d1a2836 to f8040cd Compare May 15, 2026 13:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Node.js script discovers tracked Python example files, computes changed vs remaining modules against the PR base ref, runs changed examples first then remaining examples using uv run -m (fail-fast), adds Jest tests for these helpers, and updates the GitHub Actions workflow to run the script and limit triggers to relevant paths.

Changes

Example Checking Workflow Optimization

Layer / File(s) Summary
Core execution script with discovery and orchestration
.github/scripts/pr-check-secondary-examples.js
Discovers tracked examples/**/*.py via git ls-files, excludes __init__.py, fetches GITHUB_BASE_REF and diffs to find changed examples, converts paths to Python module names, computes {changed, remaining}, runs examples with uv run -m in phase 1 (changed) then phase 2 (remaining) with fail-fast behavior, and exports helpers for testing.
Jest test suite for execution script
.github/scripts/__tests__/pr-check-secondary-examples.test.js
Mocks child_process to test toModule, getAllExamples, getChangedExamples, computeExecutionPlan, runExample, and runAll, covering env handling, git fetch/diff errors, filtering of __init__.py, and fail-fast execution semantics.
Node.js package and Jest configuration
.github/scripts/package.json, .github/scripts/jest.config.js
Adds minimal package.json for CI scripts with test -> jest and devDependency jest@^29.7.0, plus Jest config restricting test discovery to **/__tests__/**/*.test.js.
Workflow trigger filtering and orchestrated execution
.github/workflows/pr-check-secondary-examples.yml
Restricts push/pull_request triggers to changes under examples/**, src/**, and .github/scripts/**, updates concurrency grouping, sets up Node 20, installs .github/scripts deps and runs tests, and replaces the prior bash/UV per-file loop with node .github/scripts/pr-check-secondary-examples.js.

Sequence Diagram(s)

sequenceDiagram
  participant Script as pr-check-secondary-examples.js
  participant Git as git
  participant UV as uv run -m

  Script->>Git: git ls-files examples
  Git-->>Script: tracked example files
  Script->>Script: filter out __init__.py

  Script->>Git: git fetch origin (GITHUB_BASE_REF)
  Script->>Git: git rev-parse --verify remoteRef
  Script->>Git: git diff --name-only remoteRef...HEAD
  Git-->>Script: changed example files

  Script->>Script: computeExecutionPlan(all, changed) -> {changed, remaining}

  alt changed non-empty
    Script->>UV: Phase 1: runAll(changed)
    UV-->>Script: exit 0/1
  end

  alt remaining non-empty and Phase 1 succeeded
    Script->>UV: Phase 2: runAll(remaining)
    UV-->>Script: exit 0/1
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main optimization: improving the pr-check-secondary-examples workflow to reduce resource consumption (referenced issue #1949).
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about optimizations, design decisions, implementation details, and acknowledgment of prior work.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #1949's acceptance criteria: restricts triggers with path filters, reduces resource consumption via two-phase execution, includes Jest tests, maintains backwards compatibility, and documents changes.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to optimizing the pr-check-secondary-examples workflow and its supporting infrastructure (script, tests, config) as specified in issue #1949.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #1949

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 04deb248-27d4-4536-809f-b1687e071612

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5600c and d1a2836.

⛔ Files ignored due to path filters (1)
  • .github/scripts/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .github/scripts/__tests__/pr-check-secondary-examples.test.js
  • .github/scripts/jest.config.js
  • .github/scripts/package.json
  • .github/scripts/pr-check-secondary-examples.js
  • .github/workflows/pr-check-secondary-examples.yml
  • .gitignore

Comment thread .github/scripts/pr-check-secondary-examples.js
@Mounil2005 Mounil2005 force-pushed the optimize-examples-workflow branch from 86e5ea9 to 8d37e7c Compare May 16, 2026 09:29
@Mounil2005 Mounil2005 marked this pull request as ready for review May 16, 2026 09:53
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 77680d90-8268-4db4-b853-167786f966e6

📥 Commits

Reviewing files that changed from the base of the PR and between d1a2836 and 8d37e7c.

⛔ Files ignored due to path filters (1)
  • .github/scripts/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .github/scripts/__tests__/pr-check-secondary-examples.test.js
  • .github/scripts/jest.config.js
  • .github/scripts/package.json
  • .github/scripts/pr-check-secondary-examples.js
  • .github/workflows/pr-check-secondary-examples.yml

Comment thread .github/scripts/__tests__/pr-check-secondary-examples.test.js
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/workflows/pr-check-secondary-examples.yml Outdated
@github-actions github-actions Bot added open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review labels May 16, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
.github/scripts/pr-check-secondary-examples.js (1)

89-90: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the filtered phase-1 list from computeExecutionPlan in main orchestration.

Line 90 computes filtered changed but discards it, and Line 97/Line 99 still execute the raw changed list. This can reintroduce failures on deleted/renamed examples that are not runnable.

Proposed fix
 if (require.main === module) {
     const all = getAllExamples();
     const changed = getChangedExamples();
-    const { remaining } = computeExecutionPlan(all, changed);
+    const { changed: runnableChanged, remaining } = computeExecutionPlan(all, changed);

     console.log("\n=== Example Execution Plan ===");
-    console.log("Changed:", changed.length ? changed : "(none)");
+    console.log("Changed:", runnableChanged.length ? runnableChanged : "(none)");
     console.log("Remaining:", remaining.length);
     console.log("");

-    if (changed.length > 0) {
+    if (runnableChanged.length > 0) {
         console.log("🚀 Phase 1: Running CHANGED examples...");
-        runAll(changed);
+        runAll(runnableChanged);
     } else {
         console.log("ℹ️ No changed examples detected");
     }

Also applies to: 93-100


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 636ee56a-61ac-41d0-b5d5-fd27408778c2

📥 Commits

Reviewing files that changed from the base of the PR and between 8d37e7c and ed61aa8.

📒 Files selected for processing (3)
  • .github/scripts/__tests__/pr-check-secondary-examples.test.js
  • .github/scripts/pr-check-secondary-examples.js
  • .github/workflows/pr-check-secondary-examples.yml

@Mounil2005 Mounil2005 force-pushed the optimize-examples-workflow branch from ed61aa8 to 7672ed4 Compare May 18, 2026 09:38
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2bbc188a-e011-44ad-bb03-1c206bd426a7

📥 Commits

Reviewing files that changed from the base of the PR and between ed61aa8 and 7672ed4.

⛔ Files ignored due to path filters (1)
  • .github/scripts/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .github/scripts/__tests__/pr-check-secondary-examples.test.js
  • .github/scripts/jest.config.js
  • .github/scripts/package.json
  • .github/scripts/pr-check-secondary-examples.js
  • .github/workflows/pr-check-secondary-examples.yml

Comment thread .github/scripts/pr-check-secondary-examples.js
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/workflows/pr-check-secondary-examples.yml
Copy link
Copy Markdown
Contributor

@aceppaluni aceppaluni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mounil2005 Did you test this?

@Mounil2005 Mounil2005 marked this pull request as draft May 19, 2026 15:25
@github-actions
Copy link
Copy Markdown

Hello, this is the OfficeHourBot.

This is a reminder that the Hiero Python SDK Office Hours will begin in approximately 3 hours (14:00 UTC).

This session provides an opportunity to ask questions regarding this Pull Request.

Details:

Disclaimer: This is an automated reminder. Please verify the schedule here for any changes.

From,
The Python SDK Team

@aceppaluni aceppaluni added the status: Needs Developer Revision Author needs to apply suggested changes/improvements label May 20, 2026
@Mounil2005 Mounil2005 force-pushed the optimize-examples-workflow branch from 6b87f1f to 350cd15 Compare May 21, 2026 21:23
@Mounil2005
Copy link
Copy Markdown
Contributor Author

The changes are covered by a Jest unit test suite (21 scenarios) that runs as part of the workflow itself before the Solo network spins up. Tests cover:

  • Example file discovery (getAllExamples, getChangedExamples)
  • Path filtering (init.py exclusion, non-.py exclusion, deleted/renamed file exclusion)
  • Execution plan building (computeExecutionPlan)
  • Single example execution with fail-fast (runExample, runAll)
  • Edge cases: empty diff, fetch failure, fork PR fallback
    The workflow has also been triggered on this PR itself, pr-check-secondary-examples.yml ran successfully (visible in the CI checks).

@Mounil2005 Mounil2005 marked this pull request as ready for review May 21, 2026 21:40
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 29e4dd88-016f-4890-808d-ec373c02a73d

📥 Commits

Reviewing files that changed from the base of the PR and between 7672ed4 and 350cd15.

⛔ Files ignored due to path filters (1)
  • .github/scripts/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .github/scripts/__tests__/pr-check-secondary-examples.test.js
  • .github/scripts/jest.config.js
  • .github/scripts/package.json
  • .github/scripts/pr-check-secondary-examples.js
  • .github/workflows/pr-check-secondary-examples.yml

Comment thread .github/scripts/__tests__/pr-check-secondary-examples.test.js
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/scripts/pr-check-secondary-examples.js Outdated
Comment thread .github/scripts/__tests__/pr-check-secondary-examples.test.js
- Restrict push trigger to main; add paths filter for examples/**, src/**, and the workflow file itself
- Add concurrency group to cancel stale runs
- Replace inline bash with two-phase Node.js script (changed examples first, then rest)
- Use spawnSync with arg array for uv run -m (fixes Codacy command injection warning)
- Reuse git ls-files pattern from pr-check-test-files.js
- Add Jest with 18 test scenarios; runs before Solo network spins up
- Add timeout-minutes: 30

Signed-off-by: IGwork <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
@Mounil2005 Mounil2005 force-pushed the optimize-examples-workflow branch from ef82f6e to 2e1d55d Compare May 23, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review scope: CI/CD involves continuous integration or delivery skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples status: Needs Developer Revision Author needs to apply suggested changes/improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Advanced]: Optimize .github/workflows/pr-check-examples.yml

3 participants