You have two options:
Train:
Train from Porto to Coimbra Departing 16:52 and arriving Coimbra 17:56.
Connect with the nightly Sud-Express Lisbon to Paris train.
This leaves Coimbra at :18:26 and arrives San Sebastian the next morning at 06:34
The bus company Internorte operates a coach service from Porto to Germany that passes through San Sebastian.
website: http://www.internorte.pt
Their downloadable timetable shows a departure daily at 20:30 from Porto Praça da Galiza arriving San Sebastian at 06:30 the next morning.
Unfortunately prices are not displayed on the respective web sites but I suspect that the coach will be the cheapest.
If you are heading in the area of San Sebastian, you should try to detour or day trip via Bilbao and visit the Guggenheim Museum.