Defend the Castle

Defend the Castle is a Minutemen main quest in Fallout 4.

Detailed walkthrough
This quests consists of "waves" where a limited number of attackers will spawn and attempt to take over The Castle.

Brotherhood of Steel
Waves consists of one vertibird and its occupants which put together, consists of a total of ten vertibirds and about thirty Brotherhood of Steel soldiers. The most efficient way to complete this quest is to use missile turrets. The turrets will make short work of the vertibirds and its occupants. Most of the men inside the ship will not be lootable with the exception of ragdolls falling out.

Institute
Waves of synths and coursers will spawn at various locations. Like the Brotherhood, a large magnitude will also be relayed to the castle, most often at the southern entrance. Several turrets on top of the walls and maybe even on the castle grounds for emergency are recommended as the synths and coursers pose a threat, especially at higher difficulties where they are more aggressive and likely have more legendary variants.

Raiders or Gunners
Waves of raiders and attack dogs or Gunners will attack from either the front side or the back.

Super Mutants
Waves of super mutants will spawn with behemoths.

Bugs

 * Many quests involving the railroad, such as the weathervane, and Randolph quests will automatically fail if not completed beforehand.
 * It is a possibility that Ronnie Shaw's proper dialogue will not appear to end the quest; the only options that will appear are trading and merchant dialogue, leaving the quest unbeatable. There is no known fix for this bug.(it is possible to instantly end the quest by typing the setstage console command: SetStage 000bdb04 450)
 * Sometimes, enemy waves will not move upon spawning or will move in the wrong direction in an attempt to fight other enemies in the area. If the quest appears to be stuck, try looking for the enemy wave nearby, and then drawing them back to the castle. Synths can also teleport into the player character-made structures, so make sure they are not hidden in or amongst any place that may appear inaccessible.
 * It is possible to glitch the quest during the Synth attack in such a way that all guns, energy weapons, and explosives including Minutemen artillery will cease dealing damage. From that point on, other characters and the player character may fire or throw grenades at each other to no effect, and only bashing or other melee attacks will deal damage.
 * A few seconds after being given the quest objective to speak to Preston Garvey after successfully defending the castle, all allies named "Settler" may turn hostile for no apparent reason.
 * The same bug may present at the beginning of the attack. Any visiting caravan will turn hostile in addition to the settlers.
 * It is possible Ronnie Shaw's proper dialogue will not appear (only option appearing will be trading dialogue) to end the "travel to the castle" stage and begin the next stage (either build defenses or defend) of the quest if you are wearing power armor. Exit the armor and her dialogue will appear.
 * If the enemy waves stopped coming, just fast-travel again to the Castle to "reload" the enemies.
 * This quest was meant to also be a repeatable/Radiant quest. However, much like with Defend Artillery quest, looping errors prevented this from occurring. This seems to have been fixed with official patch 1.3.