The classical Yang-Mills action is of the form
$$S=\frac{1}{2g^2}\int_{\mathcal{M}}\text{tr}\left[F\wedge\star F\right]\\ =\frac{1}{4g^2}\int\mathrm{d}^dx\sqrt{g}\,\text{tr}\left[F^{\mu\nu}F_{\mu\nu}\right],$$
where $F=dA+A\wedge A$ is the Yang-Mills field strength $2$-form and $g$ is a coupling constant that is irrelevant in the classical description.
Now, the classical Einstein-Hilbert action takes the form
$$S=\frac{1}{2\kappa}\int_{\mathcal{M}}\star\mathcal{R}=\frac{1}{2\kappa}\int\mathrm{d}^dx\sqrt{g}\,\mathcal{R},$$
where $\mathcal{R}=\text{tr}_g(\text{tr}(R))=R^{\mu\nu}_{\,\,\,\,\mu\nu}$ is the Ricci scalar curvature of the manifold and $R$ represents the Riemann curvature tensor, and $\kappa=8\pi G$ is again a coupling constant.
My question is this: why is the Einstein-Hilbert action linear in the curvature tensor while the Yang-Mills action is quadratic in the gauge-field curvature tensor? Both theories are required to be invariant under a specific set of transformations (Gauge transformations for Yang-Mills and diffeomorphisms for Einstein gravity), so it seems like their actions should be of a similar form (I know that gravity isn't exactly the gauge theory of diffeomorphisms, but this still seems odd to me). For instance, is there an a priori reason why we don't write down
$$S=\frac{1}{2\kappa'}\int\text{tr}\left[R\wedge\star R\right]=\frac{1}{4\kappa'}\int\mathrm{d}^dx\sqrt{g}\,g^{\alpha\mu}g^{\beta\nu}R^{\rho}_{\,\,\alpha\sigma\beta}R^{\sigma}_{\,\,\mu\rho\nu}$$
instead of the obvious reason that it doesn't give the Einstein equations?
Any insight into this would be excellent. Thanks!
Note: This question is essentially the last part of Is GR the Gauge Theory of Diffeomorphisms? Why is the EH action linear in the Curvature?. However, this question was never answered and was closed since the first few parts were essentially duplicates.