@@ -153,6 +153,11 @@ func (rc *RunContext) startJobContainer() common.Executor {
153153 return true
154154 })
155155
156+ username , password , err := rc .handleCredentials ()
157+ if err != nil {
158+ return fmt .Errorf ("failed to handle credentials: %s" , err )
159+ }
160+
156161 common .Logger (ctx ).Infof ("\U0001f680 Start image=%s" , image )
157162 name := rc .jobContainerName ()
158163
@@ -169,8 +174,8 @@ func (rc *RunContext) startJobContainer() common.Executor {
169174 Entrypoint : []string {"/usr/bin/tail" , "-f" , "/dev/null" },
170175 WorkingDir : rc .Config .ContainerWorkdir (),
171176 Image : image ,
172- Username : rc . Config . Secrets [ "DOCKER_USERNAME" ] ,
173- Password : rc . Config . Secrets [ "DOCKER_PASSWORD" ] ,
177+ Username : username ,
178+ Password : password ,
174179 Name : name ,
175180 Env : envList ,
176181 Mounts : mounts ,
@@ -836,3 +841,37 @@ func (rc *RunContext) localCheckoutPath() (string, bool) {
836841 }
837842 return "" , false
838843}
844+
845+ func (rc * RunContext ) handleCredentials () (username , password string , err error ) {
846+ // TODO: remove below 2 lines when we can release act with breaking changes
847+ username = rc .Config .Secrets ["DOCKER_USERNAME" ]
848+ password = rc .Config .Secrets ["DOCKER_PASSWORD" ]
849+
850+ container := rc .Run .Job ().Container ()
851+ if container == nil || container .Credentials == nil {
852+ return
853+ }
854+
855+ if container .Credentials != nil && len (container .Credentials ) != 2 {
856+ err = fmt .Errorf ("invalid property count for key 'credentials:'" )
857+ return
858+ }
859+
860+ ee := rc .NewExpressionEvaluator ()
861+ var ok bool
862+ if username , ok = ee .InterpolateWithStringCheck (container .Credentials ["username" ]); ! ok {
863+ err = fmt .Errorf ("failed to interpolate container.credentials.username" )
864+ return
865+ }
866+ if password , ok = ee .InterpolateWithStringCheck (container .Credentials ["password" ]); ! ok {
867+ err = fmt .Errorf ("failed to interpolate container.credentials.password" )
868+ return
869+ }
870+
871+ if container .Credentials ["username" ] == "" || container .Credentials ["password" ] == "" {
872+ err = fmt .Errorf ("container.credentials cannot be empty" )
873+ return
874+ }
875+
876+ return username , password , err
877+ }
0 commit comments