How to indentify which PCB revision at runtime?
If you have spare pins on a MCU/CPU, you could add pull-up and pull-down resistors on all these spare pins. Let's assume you have 4 of these revision pins.

Everytime you update the PCB,  update the BOM so the first revision would only have pull-downs yielding revision 0.

For the 2nd revision of the PCB, update the BOM so the second revision has one revision pin with a pull-up and all the other revision pins have pull-downs.

Etc., that way you could accommodate up to 16 PCB revisions with 4 pins, this should be enough. Only thing to remember is to update the BOM everytime you change the PCB.