ctran/annotate_models

How should I set up a CI job to ensure that annotations are up to date?

Closed this issue · 3 comments

I searched the --help output, README, and GitHub issues, but I'm struggling to find a good answer. I want to run annotate in a CI job, and fail the build if any model annotations are not up to date. I was hoping that there would be an exit status of 0 when the models are all up to date, and an exit status of 1 when any file is updated. Even better would be a --check flag (or --dry-run) to just return the exit status without making any changes.

Example:

$ bundle exec annotate && echo done
Nothing annotated.
done

$ bundle exec annotate && echo done
Annotated (1): APILog
done

Is there a way to return an exit status of 1 for the second case?

I can use this workaround for now:

bundle exec annotate | grep "Nothing annotated."

Is this the recommended way to do it?

You can use --frozen flag. If anything needs annotation, the command with return exit status 1, failing a pipeline.

Keep in mind that you will need a database connection for annotate to run.

You can use --frozen flag. If anything needs annotation, the command with return exit status 1, failing a pipeline.

Awesome, I was using annotate; git diff --exit-code before this. This is much cleaner.

Keep in mind that you will need a database connection for annotate to run.

This would be nice to mention in README.md to be honest. Additionally, the auto-generated rake task was only generated for Rails.env.development?, so not for Rails.env.test?, which took a while for me to figure out. Maybe a CI/setup paragraph would be nice?

Awesome that worked, thanks! I switched from rake annotate_models | grep 'Model files unchanged.' to bundle exec annotate --models --frozen.