Skip to content
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

Allowing workflows in the root of workflows folder #20

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions projectBundler/projectBundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,27 @@ func (kw *KindeEnvironment) discover(ctx context.Context, absLocation string) {

files, _ := os.ReadDir(workflowsPath)
for _, file := range files {
fileName := strings.ToLower(file.Name())
if strings.HasSuffix(fileName, "workflow.ts") || strings.HasSuffix(fileName, "workflow.js") {
discoveredWorkflow := KindeWorkflow{
WorkflowRootDirectory: workflowsPath,
EntryPoints: []string{file.Name()},
}
discoveredWorkflow.bundleAndIntrospect(ctx)
kw.Workflows = append(kw.Workflows, discoveredWorkflow)

}
maybeAddWorkflow(ctx, file.Name(), workflowsPath, kw)
}

} else {
maybeAddWorkflow(ctx, workflow.Name(), workflowsPath, kw)
}
}
}

func maybeAddWorkflow(ctx context.Context, file string, rootDirectory string, kw *KindeEnvironment) {
fileName := strings.ToLower(file)
if strings.HasSuffix(fileName, "workflow.ts") || strings.HasSuffix(fileName, "workflow.js") {
discoveredWorkflow := KindeWorkflow{
WorkflowRootDirectory: rootDirectory,
EntryPoints: []string{file},
}
discoveredWorkflow.bundleAndIntrospect(ctx)
kw.Workflows = append(kw.Workflows, discoveredWorkflow)
}
}
evgenyk marked this conversation as resolved.
Show resolved Hide resolved

// Discover implements ProjectBundler.
func (p *projectBundler) Discover(ctx context.Context) (*KindeProject, error) {
result := &KindeProject{}
Expand Down
2 changes: 1 addition & 1 deletion projectBundler/projectBundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Test_ProjectBunler(t *testing.T) {
}
assert.Equal("2024-12-09", kindeProject.Configuration.Version)
assert.Equal("kindeSrc", kindeProject.Configuration.RootDir)
assert.Equal(2, len(kindeProject.Environment.Workflows))
assert.Equal(3, len(kindeProject.Environment.Workflows))
assert.Empty(kindeProject.Environment.Workflows[0].Bundle.Errors)
assert.Empty(kindeProject.Environment.Workflows[1].Bundle.Errors)
evgenyk marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
3 changes: 2 additions & 1 deletion runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ func Test_ProjectBunlerE2E(t *testing.T) {
}
assert.Equal("2024-12-09", kindeProject.Configuration.Version)
assert.Equal("kindeSrc", kindeProject.Configuration.RootDir)
assert.Equal(2, len(kindeProject.Environment.Workflows))
assert.Equal(3, len(kindeProject.Environment.Workflows))
assert.Empty(kindeProject.Environment.Workflows[0].Bundle.Errors)
assert.Empty(kindeProject.Environment.Workflows[1].Bundle.Errors)
assert.Empty(kindeProject.Environment.Workflows[2].Bundle.Errors)

for _, workflow := range kindeProject.Environment.Workflows {
t.Run(fmt.Sprintf("Test_ExecuteWorkflowWithGoja - %v", workflow.WorkflowRootDirectory), testExecution(workflow, assert))
Expand Down
40 changes: 40 additions & 0 deletions testData/kindeSrc/environment/workflows/rootWorkflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const workflowSettings = {
id: 'tokenGen',
trigger: 'onCustomEvent',
bindings:{
"console": {},
"url": {},
"util": {},
"kinde.fetch": {},
"kinde.idToken": {
resetClaims: true
},
"kinde.accessToken": {
resetClaims: true
}
}
};


export default async function handle (event: any) {
console.log('logging from root workflow')
const ps = new URLSearchParams({"aaa": "bbb", "ccc": "ddd"});
console.log('logging url search params', ps.toString());
if (ps.toString() !== 'aaa=bbb&ccc=ddd') {
throw new Error('URLSearchParams failed');
}

var txt = 'Congratulate %s on his %dth birthday!';
var result = util.format(txt, 'Ev', 42);
if (result !== 'Congratulate Ev on his 42th birthday!') {
throw new Error('util.format failed');
}
console.log('logging with util formatting', result);

kinde.idToken.setCustomClaim('random', 'test');
kinde.accessToken.setCustomClaim('test2', {'test2': 'hello'});
console.log('logging from action', {"balh": "blah"});
await kinde.fetch("http://google.com");
console.error('error log');
return 'testing return';
}
evgenyk marked this conversation as resolved.
Show resolved Hide resolved
Loading