How can I make egg-tempera that doesn't deteriorate?
Egg tempera is well-known to be quite stable under normal circumstances once it has dried.
However, the fresh tempera can easily go bad, especially in warmer conditions:

To prepare the tempera paint, dry pigment was mixed with water and egg
yolk. The problem of preserving the colours during the painting process
was handled with different methods. Egg tempera has a propensity to
putrefy rapidly, especially in warmer climates. Although egg yolk is a
perfect emulsion, when mixed with pigment and water, its natural
emulsifying property tends to break down.*

To counter this effect, different methods were used within different traditions:

The Italians added the sap of fig trees [fig tree clippings or latex, see source below] into the egg yolk paint binder, as recommended by Cennini.
In Germany, flat beer was sometimes added to preserve the paint.
Russian icon painters added kvass [&quot;a fermented beverage commonly made from rye bread&quot; ✝] to the yolk. Kvass was added in an amount equal to the egg yolk and in place of adding water.
Sometimes a little vinegar was added to the binder,
or gum tragacanth was mixed with the egg yolk.*

I know that vinegar is still commonly used to slow down the deterioration process.

It should be noted, however, that these retarders are not necessary for tempera to remain in good condition - works in pure tempera (i.e. only pigment and egg yolk) have survived in splendid condition, of which an alleged ultimate example would be the so-called Pozzolatico Panel by Jacopo del Casentino from the beginning of the fourteenth century:

(Click for full and larger version)
Apart from the wonderful state of the painting layer itself, it has a double-layered varnish in very good condition: one layer is egg white diluted in water, the second so-called vernice grassa, which is mastic diluted in turpentine, and results over time in a typical cool grey film.

Cennino tells us that tempera was made by using egg yolk as a binder
for the pigments, and then diluting the mixture in water. At the end,
the painter had to add a coating of a different type to protect the
painting from dust and moisture. Although virgin tempera is already
relatively strong, it is still tender. The painters of that time were
aware that vernice grassa should not penetrate the tempera because
it would spoil the light refraction. Therefore, between the tempera
and the final covering of vernice grassa, a thin covering of egg
white was added as soon as the painting was finished. ‡

The layer of egg white shields the underlying layer of tempera from moist, dust, and interactivity with other coatings, by making it impermeable.

Reversely, the condition of the tempera is naturally also dependent on the qualities and chemical compound of the ground layer. While egg tempera stabilizes quickly, it can still be influenced by these during the drying process.
Cennini goes into a lot of detail concerning the work on panel or ancona, specifically intended for gilding. Here are the steps in a simplified (but still maybe needlessly extensive) way:
The panels &quot;should be made of a wood which is known as whitewood or poplar, of good quality, or of linden, or willow&quot;. The wood has to be completely dry, and all defects (greasiness, knots, buds, nails) have to be dealt with thoroughly.
Then the panel needs to be glued before a layer of strips of linen and &quot;a size made of clippings of sheep parchments&quot; is applied to it. This has to dry for two days.
The entire panel will now be covered meticulously with layers of a mix of the size and &quot;gesso grosso, that is, plaster of Paris (originally: &quot;coarse plaster, of Volterra&quot;), which has been purified and sifted like flour&quot;.
After drying, another set of layers is applied of a mix of this size and &quot;a gesso which is called gesso sottile; and it is some of this same gesso, but it is purified for a whole month by being soaked in a bucket&quot;. This gesso is also used for making relief on the panels.
This again has to dry, the longer the better.
The final step in preparing the ground is to scrape it down until it &quot;comes out like ivory&quot;.
Preparatory sketches on this panel are made with charcoal, fixed with ink.
A somewhat different approach is that used in Russian iconography:

Icon panels were made from dried wood boards, typically linden or
alder wood, onto which a cross-hatch pattern was incised with a sharp
tool and a size made of animal skin or sturgeon fish was applied. Over
this a layer of linen cloth soaked in the size was laid down known as
pavoloka (паволока).
The composition of the levkas [a recipe for the ground] was usually gypsum, chalk or a combination of the two minerals mixed with animal skin glue diluted with water. To this mixture was frequently added a small amount of honey. [...] After the ground was thoroughly dry, it was moistened with water and polished with a pumice stone. *

An important conclusion we can draw from this, is that the surface the egg tempera will be applied to, should be thoroughly dry.

Lastly, having very little impact, the pigments themselves affect the quality of the paint, especially by influencing the drying process.

Although pigments do not have, in general, a large effect on
temper ageing, they can slightly accelerate the process of
degradation of proteins, and perturb their identification. It is known
that copper pigments interfere with the identification of tempers. ❧



Sources:
- Cennino Cennini - The Craftsman's Handbook - Dover Publications, New York, 1960. Transl. Daniel V. Thompson.   Here is an online version that is one page number behind on my edition.
‡ Del Serra, Alfio. “A Conversation on Painting Techniques.” The Burlington Magazine, vol. 127, no. 982, 1985, pp. 4–16. JSTOR (preview).
❧ Helena Valente Vargas - Study of the aging of binders in proteinaceous media by high performance liquid chromatography (p. 6 offers a very interesting table showing discolourment of the pigments over time).
♦ Antonella Casoli, Michela Berzioli, and Paolo Cremonesi - The Chemistry of Egg Binding Medium and Its Interactions with Organic Solvents and Water.
* Review of Medieval Italian and Russian Tempera Painting Technique.
✝ https://en.wikipedia.org/wiki/Kvass
° https://en.wiktionary.org/wiki/parget