File tree Expand file tree Collapse file tree 6 files changed +33
-6
lines changed Expand file tree Collapse file tree 6 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ inputs:
37
37
required : false
38
38
default : false
39
39
40
+ internal_default_token :
41
+ description : " INPUT: Default GitHub token. (Internal purpose only, not intended for developers to set. Used for pull requests configured with a PAT)."
42
+ required : false
43
+ default : ${{ github.token }}
44
+
40
45
branding :
41
46
icon : " mic"
42
47
color : " white"
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ set -euo pipefail
22
22
# GITHUB_EVENT_NAME contains the event name.
23
23
# GITHUB_ACTIONS is true in GitHub env.
24
24
25
+ if [[ -z " $INPUT_REPO_TOKEN " ]]; then
26
+ INPUT_REPO_TOKEN=" $INPUT_INTERNAL_DEFAULT_TOKEN "
27
+ if [[ -z " $INPUT_REPO_TOKEN " ]]; then
28
+ exit 2
29
+ fi
30
+ echo " The repo_token was empty so GITHUB_TOKEN is used instead"
31
+ fi
32
+
25
33
export GITHUB_AUTH_TOKEN=" $INPUT_REPO_TOKEN "
26
34
export ENABLE_SARIF=1
27
35
export ENABLE_LICENSE=1
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ require (
10
10
github.com/sigstore/cosign v1.9.0
11
11
github.com/sirupsen/logrus v1.8.1
12
12
github.com/spf13/cobra v1.5.0
13
+ golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
13
14
sigs.k8s.io/release-sdk v0.8.0
14
15
sigs.k8s.io/release-utils v0.6.1-0.20220405215325-d4a2a2f0e8fd
15
16
)
@@ -241,7 +242,6 @@ require (
241
242
gocloud.dev v0.25.0 // indirect
242
243
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
243
244
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
244
- golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
245
245
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
246
246
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
247
247
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Original file line number Diff line number Diff line change @@ -38,10 +38,11 @@ const (
38
38
39
39
// TODO(input): INPUT_ constants should be removed in a future release once
40
40
// they have replacements in upstream scorecard.
41
- EnvInputRepoToken = "INPUT_REPO_TOKEN" //nolint:gosec
42
- EnvInputResultsFile = "INPUT_RESULTS_FILE"
43
- EnvInputResultsFormat = "INPUT_RESULTS_FORMAT"
44
- EnvInputPublishResults = "INPUT_PUBLISH_RESULTS"
41
+ EnvInputRepoToken = "INPUT_REPO_TOKEN" //nolint:gosec
42
+ EnvInputInternalRepoToken = "INPUT_INTERNAL_DEFAULT_TOKEN" //nolint:gosec
43
+ EnvInputResultsFile = "INPUT_RESULTS_FILE"
44
+ EnvInputResultsFormat = "INPUT_RESULTS_FORMAT"
45
+ EnvInputPublishResults = "INPUT_PUBLISH_RESULTS"
45
46
)
46
47
47
48
// Errors
Original file line number Diff line number Diff line change @@ -105,8 +105,9 @@ func New() (*Options, error) {
105
105
106
106
// Validate validates the scorecard configuration.
107
107
func (o * Options ) Validate () error {
108
+ fmt .Println ("EnvGithubAuthToken:" , EnvGithubAuthToken , os .Getenv (EnvGithubAuthToken ))
108
109
if os .Getenv (EnvGithubAuthToken ) == "" {
109
- fmt .Printf ("The 'repo_token' variable is empty.\n " )
110
+ fmt .Printf ("%s variable is empty.\n " , EnvGithubAuthToken )
110
111
if o .IsForkStr == trueStr {
111
112
fmt .Printf ("We have detected you are running on a fork.\n " )
112
113
}
@@ -151,6 +152,14 @@ func (o *Options) Print() {
151
152
152
153
func (o * Options ) setScorecardOpts () {
153
154
o .ScorecardOpts = scopts .New ()
155
+ // Set GITHUB_AUTH_TOKEN
156
+ inputToken := os .Getenv (EnvInputRepoToken )
157
+ if inputToken == "" {
158
+ fmt .Printf ("The 'repo_token' variable is empty.\n " )
159
+ fmt .Printf ("Using the '%s' variable instead.\n " , EnvInputInternalRepoToken )
160
+ inputToken := os .Getenv (EnvInputInternalRepoToken )
161
+ os .Setenv (EnvGithubAuthToken , inputToken )
162
+ }
154
163
155
164
// --repo= | --local
156
165
// This section restores functionality that was removed in
Original file line number Diff line number Diff line change @@ -222,8 +222,12 @@ func TestNew(t *testing.T) {
222
222
os .Setenv (EnvGithubAuthToken , testToken )
223
223
defer os .Unsetenv (EnvGithubAuthToken )
224
224
225
+ os .Setenv (EnvInputRepoToken , "token-value-123456" )
226
+ defer os .Unsetenv (EnvInputRepoToken )
227
+
225
228
if tt .unsetToken {
226
229
os .Unsetenv (EnvGithubAuthToken )
230
+ os .Unsetenv (EnvInputRepoToken )
227
231
}
228
232
229
233
os .Setenv (EnvGithubEventPath , tt .githubEventPath )
You can’t perform that action at this time.
0 commit comments