Skip to content

Commit

Permalink
fix result file path issues (#1428)
Browse files Browse the repository at this point in the history
There were two issues at play that prevented the binary from reading the
correct results file:

1. The paths were not joined with a separator. This led to file not
   found errors, as the file was saved in the wrong place with the wrong
   name.
2. The signing code tried to read the file from the current working
   directory instead of the GitHub workspace directory.

Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock authored Aug 12, 2024
1 parent ab97293 commit fdeb02d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/scorecard/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/ossf/scorecard-action/options"
Expand All @@ -45,7 +46,7 @@ func Format(result *scorecard.Result, opts *options.Options) error {
}

// write results to both stdout and result file
resultFile, err := os.Create(opts.GithubWorkspace + opts.InputResultsFile)
resultFile, err := os.Create(filepath.Join(opts.GithubWorkspace, opts.InputResultsFile))
if err != nil {
return fmt.Errorf("creating result file: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"

"github.com/ossf/scorecard-action/internal/scorecard"
"github.com/ossf/scorecard-action/options"
Expand Down Expand Up @@ -61,7 +62,8 @@ func main() {
}
}

jsonPayload, err := os.ReadFile(opts.InputResultsFile)
resultFile := filepath.Join(opts.GithubWorkspace, opts.InputResultsFile)
jsonPayload, err := os.ReadFile(resultFile)
if err != nil {
log.Fatalf("reading json scorecard results: %v", err)
}
Expand All @@ -74,7 +76,7 @@ func main() {
log.Fatalf("error SigningNew: %v", err)
}
// TODO: does it matter if this is hardcoded as results.json or not?
if err = s.SignScorecardResult(opts.InputResultsFile); err != nil {
if err = s.SignScorecardResult(resultFile); err != nil {
log.Fatalf("error signing scorecard json results: %v", err)
}

Expand Down

0 comments on commit fdeb02d

Please sign in to comment.