From b29bd094ebe116f2efff9999e716e609b0c43432 Mon Sep 17 00:00:00 2001 From: Shivasurya Date: Mon, 14 Oct 2024 23:00:39 -0400 Subject: [PATCH] added github output file support --- action.yml | 4 ++-- sourcecode-parser/cmd/ci.go | 5 +++++ sourcecode-parser/graph/util.go | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e22baf4..a60a61f 100644 --- a/action.yml +++ b/action.yml @@ -3,11 +3,11 @@ name: 'Code-Pathfinder OSS' description: 'Code-Pathfinder open-source alternative to CodeQL' inputs: command: - description: 'Command to run' + description: 'Command to run example: ci, query' required: true default: 'ci' project: - description: 'Source code to scan' + description: 'Source code to scan. eg: /path/to/project' required: true default: ${{ github.workspace }} ruleset: diff --git a/sourcecode-parser/cmd/ci.go b/sourcecode-parser/cmd/ci.go index 12e5766..83855af 100644 --- a/sourcecode-parser/cmd/ci.go +++ b/sourcecode-parser/cmd/ci.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph" "io" "net/http" "os" @@ -70,6 +71,10 @@ var ciCmd = &cobra.Command{ // TODO: Add sarif file support if output == "json" { if outputFile != "" { + if graph.IsGitHubActions() { + // append GITHUB_WORKSPACE to output file path + outputFile = os.Getenv("GITHUB_WORKSPACE") + "/" + outputFile + } file, err := os.Create(outputFile) if err != nil { fmt.Println("Error creating output file: ", err) diff --git a/sourcecode-parser/graph/util.go b/sourcecode-parser/graph/util.go index 129c7c5..1cb41aa 100644 --- a/sourcecode-parser/graph/util.go +++ b/sourcecode-parser/graph/util.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "log" + "os" ) var verboseFlag bool @@ -63,3 +64,7 @@ func Fmt(format string, args ...interface{}) { fmt.Printf(format, args...) } } + +func IsGitHubActions() bool { + return os.Getenv("GITHUB_ACTIONS") == "true" +}