Yosef Karo, Translation:Shulchan Aruch — Orach Chaim 329…
“ Paragraph 6 - Regarding non-Jews who besiege Jewish cities: if they come for money, we do not desecrate the Shabbat [to protect ourselves] , but if they came to kill or come with no presented reason, we go out with weapons and desecrate the Shabbat. In a city that is near the border, even if they just come for straw or hay, we desecrate the Shabbat. ”
