According to Jeremy Crawford, lead rules designer for D&D:
Any bonus action that is conditional on a certain action (e.g. the Attack action) being taken can only occur after that action is completed.
For instance, for the Shield Master feat, you can't do the bonus action shove before the Attack action, because the bonus action shove is conditional upon you taking that action.
Jeremy Crawford addresses this situation on Twitter here:
Clarification about bonus actions: if a feature says you can do X as a bonus action if you do Y, you must do Y before you can do X. For Shield Master, that means the bonus action must come after the Attack action. You decide when it happens afterward that turn.
Here, he is apparently reiterating an earlier change of mind from 2017 regarding the timing of such bonus actions. This contradicts a previous ruling by him via Twitter, in which he stated that, "As with most bonus actions, you choose the timing, so the Shield Master shove can come before or after the Attack action." Crawford acknowledges this change here:
In 2017, I changed the ruling on bonus action timing because the old ruling was illogical. The original ruling failed to account for the fact that X relying on Y is a form of timing. The new ruling corrects that oversight.
And further explains his reasoning here:
The old ruling on bonus action timing didn't quiet questions on that timing. Instead, the illogical ruling fueled questions, and it even inadvertently led some fans to think our choice of words like "if" or "when" had super-precise meanings in bonus actions. They don't.
In addition, if you can make multiple attacks as part of the Attack action, you can not take the Shield Master bonus action - or any other bonus action - until after your Attack action (as well as any intervening movement, if desired) is complete, unless explicitly stated otherwise. Crawford confirms this here:
No general rule allows you to insert a bonus action between attacks in a single action. You can interrupt a multiple-attack action with a bonus action/reaction only if the trigger of the bonus action/reaction is an attack, rather than the action.