Solution (source code)

= Solution

Transform both fields geometrically, $g\mapsto\phi^*g$ and $A\mapsto\phi^*A$. Naturality gives
$$
R_{\phi^*g}=\phi^*R_g,\quad
\operatorname{vol}_{\phi^*g}=\phi^*\operatorname{vol}_g,\quad
d(\phi^*A)=\phi^*F,
$$
and
$$
*_{\phi^*g}(\phi^*F)=\phi^*(*_gF).
$$
Each Lagrangian four-form therefore transforms by pullback. Integration of a top-degree form is unchanged under an orientation-preserving <diffeomorphism>, so both the Einstein-Hilbert and Maxwell terms, and hence the full action, are invariant.