Skip to content

feat: add docs snippet sync pipeline and new documentation snippets#1437

Draft
8bitpal wants to merge 3 commits intohyperledger-labs:mainfrom
b9lab:is/add-new-docs-sync-scripts
Draft

feat: add docs snippet sync pipeline and new documentation snippets#1437
8bitpal wants to merge 3 commits intohyperledger-labs:mainfrom
b9lab:is/add-new-docs-sync-scripts

Conversation

@8bitpal
Copy link
Copy Markdown

@8bitpal 8bitpal commented Mar 10, 2026

Adds a GitHub Actions workflow, extraction script, and export config to automatically sync code snippets from this repo to the canton.network docs repo.

  1. .github/workflows/update-docs-snippets.yml — triggers on pushes to main that touch snippets/ or scripts/, runs extraction, uploads artifacts, and triggers an update workflow in the docs repo
  2. docs/scripts/generateOutputDocs.js — reads docs/config/exportConfig.json and extracts 78 snippets from source files into docs-output/*.mdx, supporting full-file, line-range, string-marker, regex-wrap, and JSON-index extraction modes
  3. docs/config/exportConfig.json — maps 78 snippet names to source file locations across snippets/, scripts/, and bash/ examples
  4. Three new tested snippets in docs/wallet-integration-guide/examples/snippets/:
    • submit-with-retry.ts — retry pattern with exponential backoff for ledger contention
    • query-active-contracts-by-party.ts — querying active contracts scoped to a party via the SDK
    • fetch-pending-transfer-instructions.ts — fetching pending transfer instructions using fetchPendingTransferInstructionView()

The new snippets follow the existing snippets.test.ts auto-discovery pattern.

Signed-off-by: Ibo Sy ibo@b9lab.com

coldice and others added 3 commits March 10, 2026 18:03
Three new snippet files covering patterns used in docs that had no
upstream source:

- submit-with-retry: retry pattern with exponential backoff for
  handling ABORTED errors from ledger contention
- query-active-contracts-by-party: demonstrates privacy model by
  querying contracts filtered by party
- fetch-pending-transfer-instructions: uses the correct
  fetchPendingTransferInstructionView() method (fixes incorrect
  listPendingTransferInstructions() in docs)

Also registers all three in docs/config/exportConfig.json.

Signed-off-by: 8bitpal <eliashaase@gmail.com>
@8bitpal 8bitpal requested review from a team as code owners March 10, 2026 20:44
Copy link
Copy Markdown
Contributor

@PHOL-DA PHOL-DA left a comment

Choose a reason for hiding this comment

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

Left a few comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this snippet needed ? the clients already have built in retry logic for all get and post ?

prepareSignExecuteAndWaitFor will hit this line:

.postWithRetry('/v2/interactive-submission/execute', request)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this snippet is the exact same as:

with the exception of template based filtering ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the exact same as:

//this returns a list of all transfer instructions, you can then accept or reject them

await sdk.tokenStandard!.fetchPendingTransferInstructionView()

// Each instruction can be accepted or rejected
return pending
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if you return the pending then the CI will fail, each run is compared against the output from last run (and since contract ids will be constant changing then this will break each run)

const fs = require('fs');
const path = require('path');

const REPO_ROOT = path.join(__dirname, '..', '..');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use the predefined functionality in the utils instead:

export const repoRoot = getRepoRoot()

process.exit(1);
}
} catch (error) {
console.error(`Fatal error: ${error.message}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use the loggings predefined in utils instead.


console.log(`✓ Successfully extracted snippet to: ${outputPath}`);
} catch (error) {
console.error(`✗ Error processing snippet "${snippet.snippetName}": ${error.message}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use the loggings predefined in utils instead.


fs.writeFileSync(outputPath, formattedContent, 'utf8');

console.log(`✓ Successfully extracted snippet to: ${outputPath}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use the loggings predefined in utils instead.


push:
branches:
- main
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we also have backport branches like:
backport/wallet-gateway-remote/v0.17.x

How do you plan to handle different version of the different components (we track it using release tags) ?


- name: Store Artifact output
id: store-artifact
uses: actions/upload-artifact@v4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we use actions/cache instead and have it as a hash of the output file ? this will save a lot of cost in the long run (instead of storing artifacts on every single run)

@8bitpal 8bitpal marked this pull request as draft March 11, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants