Skip to content

Commit 6a62a1c

Browse files
add input for specifying --file-mode (#1509)
* add input for specifying --file-mode Signed-off-by: Spencer Schrock <sschrock@google.com> * bump scorecard to v5.1.1 fixes a data race in git file mode Signed-off-by: Spencer Schrock <sschrock@google.com> --------- Signed-off-by: Spencer Schrock <sschrock@google.com>
1 parent 2722664 commit 6a62a1c

File tree

9 files changed

+63
-7
lines changed

9 files changed

+63
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Keep this in sync with go.mod for ossf/scorecard.
2-
LDFLAGS=-X sigs.k8s.io/release-utils/version.gitVersion=v5.1.0 -X sigs.k8s.io/release-utils/version.gitCommit=b0143fc57d8d38748990027266de715052806f4b -w -extldflags \"-static\"
2+
LDFLAGS=-X sigs.k8s.io/release-utils/version.gitVersion=v5.1.1 -X sigs.k8s.io/release-utils/version.gitCommit=cd152cb6742c5b8f2f3d2b5193b41d9c50905198 -w -extldflags \"-static\"
33

44
build: ## Runs go build on repo
55
# Run go build and generate scorecard executable

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ First, [create a new file](https://docs.github.com/en/repositories/working-with-
135135

136136
| Name | Required | Description |
137137
| ----- | -------- | ----------- |
138-
| `result_file` | yes | The file that contains the results. |
139-
| `result_format` | yes | The format in which to store the results [json \| sarif]. For GitHub's scanning dashboard, select `sarif`. |
138+
| `results_file` | yes | The file that contains the results. |
139+
| `results_format` | yes | The format in which to store the results [json \| sarif]. For GitHub's scanning dashboard, select `sarif`. |
140140
| `repo_token` | no | PAT token with repository read access. Follow [these steps](/docs/authentication/fine-grained-auth-token.md) to create it. |
141141
| `publish_results` | recommended | This will allow you to display a badge on your repository to show off your hard work. See details [here](#publishing-results).|
142+
| `file_mode` | no | The method to fetch files from the repository: `archive` or `git` (default `archive`).
142143

143144
### Publishing Results
144145
The Scorecard team runs a weekly scan of public GitHub repositories in order to track

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ inputs:
3737
required: false
3838
default: false
3939

40+
file_mode:
41+
description: "INPUT: Method to fetch files from GitHub"
42+
required: false
43+
default: archive
44+
4045
internal_publish_base_url:
4146
description: "INPUT: Base URL for publishing results. Used for testing."
4247
required: false

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/caarlos0/env/v6 v6.10.1
77
github.com/google/go-cmp v0.6.0
88
github.com/google/go-github/v46 v46.0.0
9-
github.com/ossf/scorecard/v5 v5.1.0
9+
github.com/ossf/scorecard/v5 v5.1.1
1010
github.com/sigstore/cosign/v2 v2.4.2
1111
github.com/spf13/cobra v1.9.1
1212
golang.org/x/net v0.35.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ
642642
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
643643
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
644644
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
645-
github.com/ossf/scorecard/v5 v5.1.0 h1:onGMdLkflcsc2OOLiqpdY1Y4RGWicK3V9/q6qGWLqP4=
646-
github.com/ossf/scorecard/v5 v5.1.0/go.mod h1:LPrCMUyDZyEbJXgRDLWP6IKl9rPDooYY15T2FYMJxYY=
645+
github.com/ossf/scorecard/v5 v5.1.1 h1:PbEs+JznKjwXyk9N1voOOwFqVNuFKfr0URNt9TBjLeo=
646+
github.com/ossf/scorecard/v5 v5.1.1/go.mod h1:LPrCMUyDZyEbJXgRDLWP6IKl9rPDooYY15T2FYMJxYY=
647647
github.com/owenrumney/go-sarif v1.1.1/go.mod h1:dNDiPlF04ESR/6fHlPyq7gHKmrM0sHUvAGjsoh8ZH0U=
648648
github.com/owenrumney/go-sarif/v2 v2.3.3 h1:ubWDJcF5i3L/EIOER+ZyQ03IfplbSU1BLOE26uKQIIU=
649649
github.com/owenrumney/go-sarif/v2 v2.3.3/go.mod h1:MSqMMx9WqlBSY7pXoOZWgEsVB4FDNfhcaXDA1j6Sr+w=

internal/scorecard/scorecard.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"errors"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/ossf/scorecard-action/options"
2425
"github.com/ossf/scorecard/v5/clients"
@@ -35,7 +36,11 @@ func Run(opts *options.Options) (scorecard.Result, error) {
3536
return scorecard.Result{}, fmt.Errorf("unable to create repo: %w", err)
3637
}
3738

38-
result, err := scorecard.Run(context.Background(), repo)
39+
var scOpts []scorecard.Option
40+
if strings.EqualFold(opts.InputFileMode, "git") {
41+
scOpts = append(scOpts, scorecard.WithFileModeGit())
42+
}
43+
result, err := scorecard.Run(context.Background(), repo, scOpts...)
3944
if err != nil && !errors.Is(err, sce.ErrCheckRuntime) {
4045
return scorecard.Result{}, fmt.Errorf("scorecard had an error: %w", err)
4146
}

options/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
EnvInputResultsFile = "INPUT_RESULTS_FILE"
4444
EnvInputResultsFormat = "INPUT_RESULTS_FORMAT"
4545
EnvInputPublishResults = "INPUT_PUBLISH_RESULTS"
46+
EnvInputFileMode = "INPUT_FILE_MODE"
4647
EnvInputInternalPublishBaseURL = "INPUT_INTERNAL_PUBLISH_BASE_URL"
4748
)
4849

options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Options struct {
7777
// Input parameters
7878
InputResultsFile string `env:"INPUT_RESULTS_FILE"`
7979
InputResultsFormat string `env:"INPUT_RESULTS_FORMAT"`
80+
InputFileMode string `env:"INPUT_FILE_MODE"`
8081

8182
PublishResults bool
8283
}

options/options_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestNew(t *testing.T) {
4848
Local string
4949
ChecksToRun []string
5050
ShowDetails bool
51+
FileMode string
5152
}
5253
tests := []struct {
5354
name string
@@ -58,6 +59,7 @@ func TestNew(t *testing.T) {
5859
resultsFile string
5960
resultsFormat string
6061
publishResults string
62+
fileMode string
6163
want fields
6264
unsetResultsPath bool
6365
unsetToken bool
@@ -71,6 +73,7 @@ func TestNew(t *testing.T) {
7173
repo: testRepo,
7274
resultsFormat: "sarif",
7375
resultsFile: testResultsFile,
76+
fileMode: options.FileModeArchive,
7477
want: fields{
7578
EnableSarif: true,
7679
Format: formatSarif,
@@ -80,6 +83,7 @@ func TestNew(t *testing.T) {
8083
LogLevel: options.DefaultLogLevel,
8184
Repo: testRepo,
8285
ShowDetails: true,
86+
FileMode: options.FileModeArchive,
8387
},
8488
wantErr: false,
8589
},
@@ -91,6 +95,7 @@ func TestNew(t *testing.T) {
9195
repo: testRepo,
9296
resultsFormat: "json",
9397
resultsFile: testResultsFile,
98+
fileMode: options.FileModeArchive,
9499
want: fields{
95100
EnableSarif: true,
96101
Format: options.FormatJSON,
@@ -99,6 +104,29 @@ func TestNew(t *testing.T) {
99104
LogLevel: options.DefaultLogLevel,
100105
Repo: testRepo,
101106
ShowDetails: true,
107+
FileMode: options.FileModeArchive,
108+
},
109+
wantErr: false,
110+
},
111+
{
112+
name: "SuccessFileModeGit",
113+
githubEventPath: githubEventPathNonFork,
114+
githubEventName: pushEvent,
115+
githubRef: "refs/heads/main",
116+
repo: testRepo,
117+
resultsFormat: "sarif",
118+
resultsFile: testResultsFile,
119+
fileMode: options.FileModeGit,
120+
want: fields{
121+
EnableSarif: true,
122+
Format: formatSarif,
123+
PolicyFile: defaultScorecardPolicyFile,
124+
ResultsFile: testResultsFile,
125+
Commit: options.DefaultCommit,
126+
LogLevel: options.DefaultLogLevel,
127+
Repo: testRepo,
128+
ShowDetails: true,
129+
FileMode: options.FileModeGit,
102130
},
103131
wantErr: false,
104132
},
@@ -110,6 +138,7 @@ func TestNew(t *testing.T) {
110138
repo: testRepo,
111139
resultsFormat: "json",
112140
resultsFile: testResultsFile,
141+
fileMode: options.FileModeArchive,
113142
want: fields{
114143
EnableSarif: true,
115144
Format: options.FormatJSON,
@@ -118,6 +147,7 @@ func TestNew(t *testing.T) {
118147
LogLevel: options.DefaultLogLevel,
119148
Local: ".",
120149
ShowDetails: true,
150+
FileMode: options.FileModeArchive,
121151
},
122152
wantErr: false,
123153
},
@@ -129,6 +159,7 @@ func TestNew(t *testing.T) {
129159
repo: testRepo,
130160
resultsFormat: "json",
131161
resultsFile: testResultsFile,
162+
fileMode: options.FileModeArchive,
132163
want: fields{
133164
EnableSarif: true,
134165
Format: options.FormatJSON,
@@ -137,6 +168,7 @@ func TestNew(t *testing.T) {
137168
LogLevel: options.DefaultLogLevel,
138169
Repo: testRepo,
139170
ShowDetails: true,
171+
FileMode: options.FileModeArchive,
140172
},
141173
wantErr: false,
142174
},
@@ -148,6 +180,7 @@ func TestNew(t *testing.T) {
148180
repo: testRepo,
149181
resultsFormat: "sarif",
150182
resultsFile: testResultsFile,
183+
fileMode: options.FileModeArchive,
151184
want: fields{
152185
EnableSarif: true,
153186
Format: formatSarif,
@@ -157,6 +190,7 @@ func TestNew(t *testing.T) {
157190
LogLevel: options.DefaultLogLevel,
158191
Repo: testRepo,
159192
ShowDetails: true,
193+
FileMode: options.FileModeArchive,
160194
},
161195
unsetToken: true,
162196
wantErr: true,
@@ -166,13 +200,15 @@ func TestNew(t *testing.T) {
166200
githubEventPath: githubEventPathNonFork,
167201
githubEventName: pushEvent,
168202
githubRef: "refs/heads/main",
203+
fileMode: options.FileModeArchive,
169204
want: fields{
170205
EnableSarif: true,
171206
Format: formatSarif,
172207
PolicyFile: defaultScorecardPolicyFile,
173208
Commit: options.DefaultCommit,
174209
LogLevel: options.DefaultLogLevel,
175210
ShowDetails: true,
211+
FileMode: options.FileModeArchive,
176212
},
177213
unsetResultsPath: true,
178214
wantErr: true,
@@ -183,6 +219,7 @@ func TestNew(t *testing.T) {
183219
githubEventName: pushEvent,
184220
githubRef: "refs/heads/main",
185221
resultsFile: "",
222+
fileMode: options.FileModeArchive,
186223
want: fields{
187224
EnableSarif: true,
188225
Format: formatSarif,
@@ -191,6 +228,7 @@ func TestNew(t *testing.T) {
191228
Commit: options.DefaultCommit,
192229
LogLevel: options.DefaultLogLevel,
193230
ShowDetails: true,
231+
FileMode: options.FileModeArchive,
194232
},
195233
wantErr: true,
196234
},
@@ -202,6 +240,7 @@ func TestNew(t *testing.T) {
202240
repo: testRepo,
203241
resultsFormat: "sarif",
204242
resultsFile: testResultsFile,
243+
fileMode: options.FileModeArchive,
205244
want: fields{
206245
EnableSarif: true,
207246
Format: formatSarif,
@@ -211,6 +250,7 @@ func TestNew(t *testing.T) {
211250
LogLevel: options.DefaultLogLevel,
212251
Repo: testRepo,
213252
ShowDetails: true,
253+
FileMode: options.FileModeArchive,
214254
},
215255
wantErr: true,
216256
},
@@ -243,6 +283,8 @@ func TestNew(t *testing.T) {
243283
os.Setenv(EnvInputResultsFormat, tt.resultsFormat)
244284
defer os.Unsetenv(EnvInputResultsFormat)
245285

286+
t.Setenv(EnvInputFileMode, tt.fileMode)
287+
246288
if tt.unsetResultsPath {
247289
os.Unsetenv(EnvInputResultsFile)
248290
} else {
@@ -263,6 +305,7 @@ func TestNew(t *testing.T) {
263305
Local: scOpts.Local,
264306
ChecksToRun: scOpts.ChecksToRun,
265307
ShowDetails: scOpts.ShowDetails,
308+
FileMode: opts.InputFileMode,
266309
}
267310

268311
if err != nil {

0 commit comments

Comments
 (0)