I am creating a CI/CD Pipeline for my project. I am building the Images using GitHub Actions and storing them in the AWS ECR.
The whole pipeline works fine but there is a problem with updating the image tags, and whenever I run the pipeline the subsequent runs fail saying the Image Tag already exists in the registry.
I tried multiple times but had no luck.
I tried to fetch the tags from the remote, but it shows the previous version as below

When there is already a new Image tag exists in the registry

It seems like, the latest tag is not getting updated.
I am using a bash script to read and update the tag while building the image.
Can someone please explain how I can update the tags automatically?