publish: large refactor

generated from commit 3488bf8c0ac579632aed6ae86bc34a9f4fd4e206