In the Laws of Shabbos, Orach Chaim, Ch. 329. paragraph 6, it states: “When non-Jews besiege Jewish cities, if they come for money purposes, we do not desecrate the Shabbos because of them [by warring against them]. But if they come [with the intention] to take lives, or even if they come with no announced purpose, and there is reason to suspect that perhaps they are coming to take lives; then, even if they have as yet not come, but are making preparations to come, we go forth against them with weapons and desecrate the Shabbos because of them. When it involves a city close to the border, then, even if their intention to come is only for the purpose of [taking] straw and stubble, we should desecrate the Shabbos because of them; for [if we do not prevent their coming] they may conquer the city, and from there the [rest of the] land will be easy for them to conquer [since it is a city on the border]