How to automatically resize animated GIFs used as Featured Images, without losing animation?

A gif should work as a featured image. Upload the gif as the featured image and display on the post page (single.php) for example, using the following for the original size:

the_post_thumbnail('full');

In the case of specific image sizes, i.e.

<?php the_post_thumbnail( 'custom-size' ); ?>

WP generates static images and in that case the gif wont work.

My suggestion would be to use conditionals to check if the attachment is a gif and use the full version in that case and rely on css to match.

$image_id = get_post_thumbnail_id($post->ID);
$type =  get_post_mime_type( $image_id );