add lint task to check for unfiltered posts past 2021-05-20
Why is this change being made?
Related to: https://gitlab.com/gitlab-com/marketing/inbound-marketing/global-content/content-marketing/-/issues/374 Related to: https://gitlab.com/gitlab-com/www-gitlab-com/-/issues/11763
This MR adds a lint task to our CI pipeline that does the following:
- It finds all the files in the blog directory
- It checks the date of each file name. If the file name exists before 2021-05-20 (we can configure this to a different date), we skip the check.
- If the file is named on or after 2021-05-20, we check the frontmatter to see if it uses
categories: unfiltered. - If it's a blog post with
categories: unfiltered, made on or after 2021-05-20, we fail the pipeline and provide an error message about it. - TODO: @skassabian - where in the handbook should I link? Do you have that in a separate MR, or do you want to add it to this one?
The date check also fails if an invalid date is provided, and logs an error. This forces people to provide ISO 8601 formatted dates in their posts, and to use valid dates. I had to change this post from 2013 which has a canonical path to the correct date, but its filename was listed as 2013-02-29, which is invalid since 2013 wasn't a leap year.
@laurenbarker - will you please check my rake task here? I mostly copied the categories linter
Limitations
Any maintainer of this repository can merge in any blog post they want. So if someone really wanted to publish to Unfiltered, and they had maintainer access, they could disable the lint check, modify the lint check, use a past date for their post, or just choose to publish outside of the unfiltered category. This MR just protects us against people who are contributing in good-faith but haven't seen the deprecation of unfiltered. That would be someone who appropriately dates their post with any date on or after 2021-05-20, and uses the unfiltered category. It doesn't offer us any actual security against a malicious actor, or someone trying to make trouble in some way.
QA
- Create a new blog post. Call it something like
sites/marketing/source/blog/blog-posts/2021-05-21-unfiltered-test.md - Use
categories: unfilteredin the frontmatter - Run
bundle exec rake lint:blog:unfilteredin your terminal. You should see the check fail. - Alternatively/additionally, you can push that blog post to the pipeline and watch CI fail as well.
- Remove that post and watch the linter pass.
Author Checklist
-
Provided a concise title for the MR -
Added a description to this MR explaining the reasons for the proposed change, per say-why-not-just-what -
Assign this change to the correct DRI