Topological actions via gauge variations of higher structures