The propagation of electromagnetic waves in vacuum is often described within the geometrical optics approximation, which predicts that wave rays follow null geodesics. However, this model is valid only in the limit of infinitely high frequencies. At large but finite frequencies, diffraction can still be negligible, but the ray dynamics becomes affected by the evolution of the wave polarization. Hence, rays can deviate from null geodesics, which is known as the gravitational spin Hall effect of light. In the literature, this effect has been calculated ad hoc for a number of special cases, but no general description has been proposed. Here, we present a covariant Wentzel-Kramers-Brillouin analysis from first principles for the propagation of light in arbitrary curved spacetimes. We obtain polarization-dependent ray equations describing the gravitational spin Hall effect of light. We also present numerical examples of polarization-dependent ray dynamics in the Schwarzschild spacetime, and the magnitude of the effect is briefly discussed. The analysis reported here is analogous to that of the spin Hall effect of light in inhomogeneous media, which has been experimentally verified.