I have usually found in books/lectures that the Dirac theory, given by
$$S=\int d^4x\bar\psi(i\gamma^\mu\partial_\mu-m)\psi, $$ is invariant under $U(1)$ global transformations (which is evident) but not invariant under $U(1)$ local (gauge) transformations, due to an extra term appearing in the Lagrangian of the form
$$\mathcal{L}\rightarrow\mathcal{L}’=\mathcal{L}-(\partial_\mu\theta)\bar{\psi}\gamma^\mu\psi.$$
Nevertheless, if one integrates this Lagrangian to obtain the new action, you find when integrating by parts that this extra term vanishes.
$$\int d^4x (\partial_\mu\theta)\bar\psi\gamma^\mu\psi=-\int d^4x \theta \partial_\mu(\bar\psi\gamma^\mu\psi)=0,$$ since $$\partial_\mu(\bar\psi\gamma^\mu\psi)=\partial_\mu\bar\psi\gamma^\mu\psi-im\bar\psi\psi=i(\partial_\mu\bar\psi\gamma^\mu\psi+m\bar\psi\psi)=0,$$ where I used the Dirac equation both for $\psi$ and for $\bar\psi$. So one concludes $S=S’$. Is then the Dirac theory invariant to gauge transformation with no need of introducing the covariant derivative?