actions: Cleanup using context managers for lock

Signed-off-by: Joe MacMahon <joe.macmahon@cern.ch>
Better templates behaviour.

TODO:
- Write some tests which fail under previous behaviour.
- Fix
- Squash this commit