Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions cmd/gh-aw-wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"strings"
"syscall/js"

"github.com/github/gh-aw/pkg/parser"
Expand Down Expand Up @@ -87,9 +88,13 @@ func doCompile(markdown string, files map[string][]byte, filename string) (js.Va
defer parser.ClearVirtualFiles()
}

// Derive workflow identifier from filename for fuzzy cron schedule scattering
identifier := strings.TrimSuffix(filename, ".md")

compiler := workflow.NewCompiler(
workflow.WithNoEmit(true),
workflow.WithSkipValidation(true),
workflow.WithWorkflowIdentifier(identifier),
)

// Parse directly from string — no temp files needed
Expand Down
7 changes: 7 additions & 0 deletions pkg/parser/virtual_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ import "os"
// In wasm builds, this is overridden to read from a virtual filesystem
// populated by the browser via SetVirtualFiles.
var readFileFunc = os.ReadFile

// ReadFile reads a file using the parser's file reading function, which
// checks the virtual filesystem first in wasm builds. Use this instead of
// os.ReadFile when reading files that may be provided as virtual files.
func ReadFile(path string) ([]byte, error) {
return readFileFunc(path)
}
14 changes: 11 additions & 3 deletions pkg/workflow/compiler_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ func (c *Compiler) getReferencedCustomJobs(content string, customJobs map[string
func (c *Compiler) buildJobs(data *WorkflowData, markdownPath string) error {
compilerJobsLog.Printf("Building jobs for workflow: %s", markdownPath)

// Try to read frontmatter to determine event types for safe events check
// Try to read frontmatter to determine event types for safe events check.
// Use contentOverride first (set by ParseWorkflowString for wasm/string API mode),
// then fall back to reading from disk.
var frontmatter map[string]any
if content, err := os.ReadFile(markdownPath); err == nil {
if result, err := parser.ExtractFrontmatterFromContent(string(content)); err == nil {
var rawContent string
if c.contentOverride != "" {
rawContent = c.contentOverride
} else if diskContent, err := os.ReadFile(markdownPath); err == nil {
rawContent = string(diskContent)
}
if rawContent != "" {
if result, err := parser.ExtractFrontmatterFromContent(rawContent); err == nil {
frontmatter = result.Frontmatter
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflow/compiler_orchestrator_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (c *Compiler) setupEngineAndImports(result *parser.FrontmatterResult, clean
fmt.Fprintf(os.Stderr, "WARNING: Skipping security scan for unresolvable import '%s': %v\n", importedFile, resolveErr)
continue
}
importContent, readErr := os.ReadFile(fullPath)
importContent, readErr := parser.ReadFile(fullPath)
if readErr != nil {
orchestratorEngineLog.Printf("Skipping security scan for unreadable import: %s: %v", fullPath, readErr)
fmt.Fprintf(os.Stderr, "WARNING: Skipping security scan for unreadable import '%s' (resolved path: %s): %v\n", importedFile, fullPath, readErr)
Expand Down
6 changes: 4 additions & 2 deletions pkg/workflow/compiler_string_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
func (c *Compiler) CompileToYAML(workflowData *WorkflowData, markdownPath string) (string, error) {
c.markdownPath = markdownPath
c.skipHeader = true
// Clear contentOverride after compilation (set by ParseWorkflowString)
defer func() { c.contentOverride = "" }()

startTime := time.Now()
defer func() {
Expand Down Expand Up @@ -51,9 +53,9 @@ func (c *Compiler) ParseWorkflowString(content string, virtualPath string) (*Wor

cleanPath := filepath.Clean(virtualPath)

// Store content so downstream code can use it instead of reading from disk
// Store content so downstream code can use it instead of reading from disk.
// Cleared in CompileToYAML after compilation completes.
c.contentOverride = content
defer func() { c.contentOverride = "" }()

// Enable inline prompt mode for string-based compilation (Wasm/browser)
// since runtime-import macros cannot resolve without filesystem access
Expand Down
Loading
Loading