I need to stretch the second layer to the borders of the first. This needs to be done several times, so I want to create an action. How do I make Photoshop resize the previous layer and scale the next layer based on the content?
Transform can be used the distort the layer. You may be able to record the step relative to 100% the document canvas width and height. But if you want it to distort the layer to an other layer's bounds you would need a to use Photoshop scripting to do that distortion.