Yes; "only + to-infinitive" is the idiom. The verb is usually "find", "discover", "learn", or something of that kind.
1. I did X, only to find that Y.
X is usually something "normal", "sensible", "reasonable". Y is an irony of circumstance, or something it would not have been reasonable to...