@@ -29,7 +29,10 @@ func PinActions(inputYaml string, exemptedActions []string, pinToImmutable bool,
2929 for _ , step := range job .Steps {
3030 if len (step .Uses ) > 0 {
3131 localUpdated := false
32- out , localUpdated = PinAction (step .Uses , out , exemptedActions , pinToImmutable , actionCommitMap )
32+ out , localUpdated , err = PinAction (step .Uses , out , exemptedActions , pinToImmutable , actionCommitMap )
33+ if err != nil {
34+ return out , updated , err
35+ }
3336 updated = updated || localUpdated
3437 }
3538 }
@@ -38,29 +41,33 @@ func PinActions(inputYaml string, exemptedActions []string, pinToImmutable bool,
3841 return out , updated , nil
3942}
4043
41- func PinAction (action , inputYaml string , exemptedActions []string , pinToImmutable bool , actionCommitMap map [string ]string ) (string , bool ) {
44+ func PinAction (action , inputYaml string , exemptedActions []string , pinToImmutable bool , actionCommitMap map [string ]string ) (string , bool , error ) {
4245
4346 updated := false
4447 if ! strings .Contains (action , "@" ) || strings .HasPrefix (action , "docker://" ) {
45- return inputYaml , updated // Cannot pin local actions and docker actions
48+ return inputYaml , updated , nil // Cannot pin local actions and docker actions
4649 }
4750
4851 if isAbsolute (action ) || (pinToImmutable && IsImmutableAction (action )) {
49- return inputYaml , updated
52+ return inputYaml , updated , nil
5053 }
5154 leftOfAt := strings .Split (action , "@" )
5255 tagOrBranch := leftOfAt [1 ]
5356
5457 // skip pinning for exempted actions
5558 if ActionExists (leftOfAt [0 ], exemptedActions ) {
56- return inputYaml , updated
59+ return inputYaml , updated , nil
5760 }
5861
5962 splitOnSlash := strings .Split (leftOfAt [0 ], "/" )
6063 owner := splitOnSlash [0 ]
6164 repo := splitOnSlash [1 ]
6265
63- PAT := os .Getenv ("PAT" )
66+ // use secure repo token
67+ PAT := os .Getenv ("SECURE_REPO_PAT" )
68+ if PAT == "" {
69+ PAT = os .Getenv ("PAT" )
70+ }
6471
6572 ctx := context .Background ()
6673 ts := oauth2 .StaticTokenSource (
@@ -81,7 +88,7 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
8188 if ! semanticTagRegex .MatchString (tagOrBranch ) {
8289 tagOrBranch , err = getSemanticVersion (client , owner , repo , tagOrBranch , commitSHA )
8390 if err != nil {
84- return inputYaml , updated
91+ return inputYaml , updated , err
8592 }
8693 }
8794 break
@@ -92,11 +99,11 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
9299 if commitSHA == "" {
93100 commitSHA , _ , err = client .Repositories .GetCommitSHA1 (ctx , owner , repo , tagOrBranch , "" )
94101 if err != nil {
95- return inputYaml , updated
102+ return inputYaml , updated , err
96103 }
97104 tagOrBranch , err = getSemanticVersion (client , owner , repo , tagOrBranch , commitSHA )
98105 if err != nil {
99- return inputYaml , updated
106+ return inputYaml , updated , err
100107 }
101108
102109 }
@@ -130,7 +137,7 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
130137 inputYaml = actionRegex .ReplaceAllString (inputYaml , pinnedActionWithVersion + "$2" )
131138
132139 inputYaml , _ = removePreviousActionComments (pinnedActionWithVersion , inputYaml )
133- return inputYaml , ! strings .EqualFold (action , pinnedActionWithVersion )
140+ return inputYaml , ! strings .EqualFold (action , pinnedActionWithVersion ), nil
134141 }
135142
136143 updated = ! strings .EqualFold (action , fullPinned )
@@ -162,7 +169,7 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
162169 )
163170 inputYaml , _ = removePreviousActionComments (fullPinned , inputYaml )
164171
165- return inputYaml , updated
172+ return inputYaml , updated , nil
166173}
167174
168175// It may be that there was already a comment next to the action
0 commit comments