@@ -14,7 +14,7 @@ import (
1414 "gopkg.in/yaml.v3"
1515)
1616
17- func PinActions (inputYaml string , exemptedActions []string , pinToImmutable bool ) (string , bool , error ) {
17+ func PinActions (inputYaml string , exemptedActions []string , pinToImmutable bool , actionCommitMap map [ string ] string ) (string , bool , error ) {
1818 workflow := metadata.Workflow {}
1919 updated := false
2020 err := yaml .Unmarshal ([]byte (inputYaml ), & workflow )
@@ -29,7 +29,7 @@ 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 )
32+ out , localUpdated = PinAction (step .Uses , out , exemptedActions , pinToImmutable , actionCommitMap )
3333 updated = updated || localUpdated
3434 }
3535 }
@@ -38,7 +38,7 @@ func PinActions(inputYaml string, exemptedActions []string, pinToImmutable bool)
3838 return out , updated , nil
3939}
4040
41- func PinAction (action , inputYaml string , exemptedActions []string , pinToImmutable bool ) (string , bool ) {
41+ func PinAction (action , inputYaml string , exemptedActions []string , pinToImmutable bool , actionCommitMap map [ string ] string ) (string , bool ) {
4242
4343 updated := false
4444 if ! strings .Contains (action , "@" ) || strings .HasPrefix (action , "docker://" ) {
@@ -69,15 +69,36 @@ func PinAction(action, inputYaml string, exemptedActions []string, pinToImmutabl
6969 tc := oauth2 .NewClient (ctx , ts )
7070
7171 client := github .NewClient (tc )
72-
73- commitSHA , _ , err := client .Repositories .GetCommitSHA1 (ctx , owner , repo , tagOrBranch , "" )
74- if err != nil {
75- return inputYaml , updated
72+ var commitSHA string
73+ var err error
74+
75+ if actionCommitMap != nil {
76+ // Check case-insensitively by iterating through the map
77+ for mapAction , actionWithCommit := range actionCommitMap {
78+ if strings .EqualFold (action , mapAction ) && actionWithCommit != "" {
79+ commitSHA = strings .Split (actionWithCommit , "@" )[1 ]
80+
81+ if ! semanticTagRegex .MatchString (tagOrBranch ) {
82+ tagOrBranch , err = getSemanticVersion (client , owner , repo , tagOrBranch , commitSHA )
83+ if err != nil {
84+ return inputYaml , updated
85+ }
86+ }
87+ break
88+ }
89+ }
7690 }
7791
78- tagOrBranch , err = getSemanticVersion (client , owner , repo , tagOrBranch , commitSHA )
79- if err != nil {
80- return inputYaml , updated
92+ if commitSHA == "" {
93+ commitSHA , _ , err = client .Repositories .GetCommitSHA1 (ctx , owner , repo , tagOrBranch , "" )
94+ if err != nil {
95+ return inputYaml , updated
96+ }
97+ tagOrBranch , err = getSemanticVersion (client , owner , repo , tagOrBranch , commitSHA )
98+ if err != nil {
99+ return inputYaml , updated
100+ }
101+
81102 }
82103
83104 // pinnedAction := fmt.Sprintf("%s@%s # %s", leftOfAt[0], commitSHA, tagOrBranch)
0 commit comments