44 "context"
55 "fmt"
66 "os"
7+ "path/filepath"
78 "regexp"
89 "strings"
910
@@ -13,7 +14,7 @@ import (
1314 "gopkg.in/yaml.v3"
1415)
1516
16- func PinActions (inputYaml string ) (string , bool , error ) {
17+ func PinActions (inputYaml string , exemptedActions [] string ) (string , bool , error ) {
1718 workflow := metadata.Workflow {}
1819 updated := false
1920 err := yaml .Unmarshal ([]byte (inputYaml ), & workflow )
@@ -28,7 +29,7 @@ func PinActions(inputYaml string) (string, bool, error) {
2829 for _ , step := range job .Steps {
2930 if len (step .Uses ) > 0 {
3031 localUpdated := false
31- out , localUpdated = PinAction (step .Uses , out )
32+ out , localUpdated = PinAction (step .Uses , out , exemptedActions )
3233 updated = updated || localUpdated
3334 }
3435 }
@@ -37,7 +38,7 @@ func PinActions(inputYaml string) (string, bool, error) {
3738 return out , updated , nil
3839}
3940
40- func PinAction (action , inputYaml string ) (string , bool ) {
41+ func PinAction (action , inputYaml string , exemptedActions [] string ) (string , bool ) {
4142
4243 updated := false
4344 if ! strings .Contains (action , "@" ) || strings .HasPrefix (action , "docker://" ) {
@@ -50,6 +51,11 @@ func PinAction(action, inputYaml string) (string, bool) {
5051 leftOfAt := strings .Split (action , "@" )
5152 tagOrBranch := leftOfAt [1 ]
5253
54+ // skip pinning for exempted actions
55+ if actionExists (leftOfAt [0 ], exemptedActions ) {
56+ return inputYaml , updated
57+ }
58+
5359 splitOnSlash := strings .Split (leftOfAt [0 ], "/" )
5460 owner := splitOnSlash [0 ]
5561 repo := splitOnSlash [1 ]
@@ -188,3 +194,20 @@ func getSemanticVersion(client *github.Client, owner, repo, tagOrBranch, commitS
188194 }
189195 return tagOrBranch , nil
190196}
197+
198+ // Function to check if an action matches any pattern in the list
199+ func actionExists (actionName string , patterns []string ) bool {
200+ for _ , pattern := range patterns {
201+ // Use filepath.Match to match the pattern
202+ matched , err := filepath .Match (pattern , actionName )
203+ if err != nil {
204+ // Handle invalid patterns
205+ fmt .Printf ("Error matching pattern: %v\n " , err )
206+ continue
207+ }
208+ if matched {
209+ return true
210+ }
211+ }
212+ return false
213+ }
0 commit comments