@@ -10,6 +10,19 @@ export interface ExamplesSectionOptions extends SectionOptions {
1010 version ?: string ;
1111}
1212
13+ /**
14+ * Generates examples section for GitHub Actions documentation.
15+ *
16+ * Examples can be stored in multiple formats and locations:
17+ * - YAML files (.yml/.yaml): Pure code snippets containing workflow examples
18+ * - Markdown files (.md): Rich content with descriptions and/or code snippets
19+ * - Destination file: Existing examples in the documentation being generated (examples section)
20+ *
21+ * Detection strategies:
22+ * 1. Examples directory: Scans `examples/` folder for YAML and Markdown files
23+ * 2. GitHub examples: Checks `.github/examples/` directory for examples
24+ * 3. Destination file: Extracts existing examples from the target documentation file
25+ */
1326@injectable ( )
1427export class ExamplesSectionGenerator extends GitHubActionsSectionGeneratorAdapter implements SectionGeneratorAdapter < GitHubActionsManifest , ExamplesSectionOptions > {
1528 private version ?: string ;
@@ -95,13 +108,7 @@ export class ExamplesSectionGenerator extends GitHubActionsSectionGeneratorAdapt
95108 examples . push ( ...this . findExamplesFromDirectory ( githubExamplesDir , manifest , version ) ) ;
96109 }
97110
98- // Strategy 3: Look for example workflows in .github/workflows/
99- const workflowsDir = join ( rootDir , '.github' , 'workflows' ) ;
100- if ( existsSync ( workflowsDir ) && statSync ( workflowsDir ) . isDirectory ( ) ) {
101- examples . push ( ...this . findExampleWorkflows ( workflowsDir , manifest , version ) ) ;
102- }
103-
104- // Strategy 4: Look for examples in destination file (if it exists)
111+ // Strategy 3: Look for examples in destination file (if it exists)
105112 if ( destination && existsSync ( destination ) ) {
106113 examples . push ( ...this . findExamplesFromReadme ( destination , manifest , version ) ) ;
107114 }
@@ -149,45 +156,7 @@ export class ExamplesSectionGenerator extends GitHubActionsSectionGeneratorAdapt
149156 }
150157
151158 /**
152- * Find example workflows that use the current action
153- */
154- private findExampleWorkflows ( workflowsDir : string , manifest : GitHubActionsManifest , version ?: ManifestVersion ) : Example [ ] {
155- const examples : Example [ ] = [ ] ;
156-
157- try {
158- const files = readdirSync ( workflowsDir ) ;
159-
160- for ( const file of files ) {
161- if ( ! [ '.yml' , '.yaml' ] . includes ( extname ( file ) . toLowerCase ( ) ) ) {
162- continue ;
163- }
164-
165- const filePath = join ( workflowsDir , file ) ;
166- const content = readFileSync ( filePath , 'utf8' ) ;
167-
168- // Check if this workflow uses the current action
169- if ( content . includes ( manifest . usesName ) || content . includes ( 'uses: ./' ) ) {
170- examples . push ( {
171- type : ExampleType . Heading ,
172- content : `Example: ${ file . replace ( / \. ( y m l | y a m l ) $ / , '' ) } ` ,
173- level : 3
174- } ) ;
175- examples . push ( {
176- type : ExampleType . Code ,
177- content : content ,
178- language : 'yaml'
179- } ) ;
180- }
181- }
182- } catch ( error ) {
183- // Silently handle directory read errors
184- }
185-
186- return examples ;
187- }
188-
189- /**
190- * Extract examples from README.md
159+ * Extract examples from README.md or destination file
191160 */
192161 private findExamplesFromReadme ( readmePath : string , manifest : GitHubActionsManifest , version ?: ManifestVersion ) : Example [ ] {
193162 const examples : Example [ ] = [ ] ;
0 commit comments