A few days, at best
If you want to detect a supernova as quickly as possible, you need a neutrino detector. Supernovae produce substantial amounts of neutrinos - which actually carry away much of the explosion's energy. Even though these particles are hard to detect, they are detectable, and can give our unfortunate civilization a slight head start.
Late stages of stellar evolution
At the end of a massive star's life, its core begins fusing heavier and heavier elements. Each stage of burning, however, is quicker than the last. For instance, while hydrogen and helium burning in a $25M_{\odot}$ star may take a few million and a few hundred thousand years, respectively, the final two stages (oxygen and silicon fusion) should last only a week.
It turns out (Asakura et al. 2016) that in the final few periods of a massive star's life - starting with carbon fusion - the star cools primarily through the production of neutrino-antineutrino pairs when an electron and a positron annihilate:
$$e^+e^-\to\nu\bar{\nu}$$
These neutrinos have low energies ($\sim2\text{MeV}$) when compared to the neutrinos produced during a supernova (see below), but they should still be detectable through several interaction processes:
- Inverse beta decay
- Coherent neutrino scattering
- Neutrino-electron scattering
Inverse beta decay (IBD) is the most promising interaction because the process has a high cross section and little background noise. Some of our current neutrino detectors (the authors focus on KamLAND) should be able to see IBD from a $25M_{\odot}$ star at distances up to 700 parsecs hours or maybe even a few days before the supernova, as the star fuses oxygen and then silicon. The detection may not be definitive, but the signal will be there.
During the supernova
As I alluded to above, supernovae do produce neutrinos. They interact only weakly with matter, meaning that they - not photons - are the first signs of a supernova about to happen. In some cases, they can be messengers of the impending disaster; in others, not so much.
Traditional core collapse. In stars with masses $\sim8\text{-}100M_{\odot}$, fusion of heavy elements will take place, eventually stopping when iron is produced (Iron fusion is possible, but it consumes more energy than it releases, so it does not take place in significant rates prior to a supernova). There is no outwards pressure - a star is in hydrostatic equilibrium, where the pressure from fusion balances the force of gravity - so the star begins to collapse.
Electron degeneracy pressure starts to slow the collapse, but it is not enough. The core continues to collapse in on itself. Photodisintegration produces high-energy gamma rays, and inverse beta decay produces neutrinos. The core continues to collapse, while outer layers are pushed outwards in a "bounce" that is not yet fully understood. From here on, the mass of the star determines whether or not its core will become a neutron star or a black hole.
The two main ways to detect a supernova of this sort are to detect the light from it or the neutrinos produced. The neutrinos typically arrive shortly before the light does, but the difference is not significant, often on the order of a few hours. By the time the neutrinos or the light reach the planet, its occupants will be toast.
For excellent related analyses, see Lieb & Yau (1987) and Heger et al. (2002), which also discusses the type of supernova explored in the next section: a pair-instability supernova.
Pair-instability. For stars with masses great than $\sim100M_{\odot}$ solar masses, gamma rays provide additional pressure against the massive outer layers. However, certain compressions can cause an increase in pair production, the creation of electrons and positrons from gamma rays. This reduces core pressure, leading to a total collapse. The star is virtually destroyed.
Pair-instability supernova typically give no warning ahead of time. In fact, they are difficult to differentiate from normal core collapse supernovae. Careful analysis after the fact is the only way to make a constructive argument to this effect, often dependent on the amount of energy produced (see Smith (2007)).
For more information on supernova detection, see What technologies and sciences are needed to detect a star going supernova?.