Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add Markdownlint cleanup job #16036

Merged
merged 2 commits into from
Sep 7, 2022
Merged

Conversation

nschonni
Copy link
Contributor

GitHub Action to create daily PR fixes for auto-fixable Markdownlint issues

@nschonni nschonni requested review from a team and fiji-flo and removed request for a team May 15, 2022 01:06
.github/workflows/markdown-lint-fix.yml Outdated Show resolved Hide resolved
branch: daily-markdownlint-fix
title: "Daily Markdownlint auto-cleanup"
body: |
Auto-fix cleanup PR using Markdown CLI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we append unfixable issues to the body?
Like:

./files/en-us/web/index.md:2 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "### Title"]

Is it possible to pipe the output to a lint.log file and attach file contents to the PR body.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good compromise would be to link to the run that triggered the PR: https://github.com/mdn/content/actions/runs/${GITHUB_RUN_ID}

@nschonni
Copy link
Contributor Author

I've been cleaning these up for awhile, there were only ~40 changed files when I tested it on my repo nschonni#105

@nschonni
Copy link
Contributor Author

#16075 are the only outstanding issues currently

@OnkarRuikar
Copy link
Contributor

You are right. I accidentally ran it with default config and got ~700 files updated. 😬
As per the current https://github.com/mdn/content/blob/main/.markdownlint.json config all the files are clean.

Also the processing all the files didn't take much time. Looks like it keeps track of modified files and directories.
So, using the filter "**/*.md" is ok.

We need to include issues, in PR body, that the linter couldn't fix and need manual work.

$ logs=$(markdownlint "**/*.md" --fix)

# append the $logs to the PR body

@OnkarRuikar OnkarRuikar mentioned this pull request May 17, 2022
1 task
@nschonni
Copy link
Contributor Author

BTW, I have been looking at the "append log to body", but it hasn't been simple and I don't know if I'll be able to resolve it

@nschonni nschonni force-pushed the markdownlint-autofix branch 2 times, most recently from 9ca981a to 47abd2f Compare June 16, 2022 19:46
@LeoMcA
Copy link
Member

LeoMcA commented Jul 20, 2022

Once #12316 is merged, should this be updated to use the yarn fix:md command instead of markdownlint-cli directly?

@nschonni
Copy link
Contributor Author

Yes, I think using the script would make sense. If the other one lands, I'll adjust this one, but I didn't want either to block the other

@Josh-Cena Josh-Cena added the infra Infrastructure issues (npm, GitHub Actions, linting) for this repo label Aug 13, 2022
@nschonni nschonni requested a review from a team as a code owner August 23, 2022 14:28
@nschonni nschonni requested review from teoli2003 and removed request for fiji-flo August 23, 2022 14:57
Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I would like a dev review before merging this as I'm not an expert in these workflows, but we definitively would like to make a try with this one.

Comment on lines 31 to 38
commit-message: "chore: auto-fix Markdownlint issues"
branch: daily-markdownlint-fix
title: "Daily Markdownlint auto-cleanup"
body: |
No unfixable issues found
Copy link
Member

@Josh-Cena Josh-Cena Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use @mdn-bot as committer + author instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's more of a question of "should" instead of "can" 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be nice to have a bot as the author, it makes clear that it is an automatic process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest user who creates the schedule trigger is the author by default. [ref]

To make @mdn-bot the author see #16036 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to use @mdn-bot as author (though committer is not quite correct), but the default (GitHub <[email protected]>) wouldn't hurt either.

@OnkarRuikar
Copy link
Contributor

OnkarRuikar commented Aug 24, 2022

This is an interesting workflow. I have a few queries about how this is going to work:

  • At what time will it trigger? Midnight UTC-8 Los Angeles time?

  • Do we want auto merge on this like dependabot PRs? Or we are going to merge manually?

  • In their example they've said:

    When you merge the pull request make sure to choose the Rebase and merge option. This will make the fork's commits match the commits on the upstream.

    Which option are we suppose to use for this one?

  • What should happen the next day if we fail to merge the PR within 24 hours? Create a brand new PR? or Append to the existing one?

  • Do we want to reuse the daily-markdownlint-fix branch everyday? Or Delete and create a brand new branch everyday?

@teoli2003
Copy link
Contributor

teoli2003 commented Aug 24, 2022

* At what time will it trigger? Midnight `UTC-8 Los Angeles` time?

This is not critical, but it looks like a good time. Night in the US, and about 10am Central European time.

* Do we want auto merge on this like dependabot PRs? Or we are going to merge manually?

I think we should start by merging them manually. If it goes well, we can later do what is done with the daily yari update and merge them automatically.

* In [their example](https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md) they've said:
  > When you merge the pull request make sure to choose the [`Rebase and merge`](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits) option. This will make the fork's commits match the commits on the upstream.

Squash and merge should be the default, like for any other PR on mdn/content.

  Which option are we suppose to use for this one?

* What should happen the next day if we fail to merge the PR within 24 hours? Create a brand new PR? or Append to the existing one?

I like what dependabot is doing: closing the old PR and opening a new one.

* Do we want to reuse the `daily-markdownlint-fix` branch everyday? Or Delete and create a brand new branch everyday?

I'm a bit afraid of reusing a branch: it could be in a strange state. What does dependabot does? It works pretty well and we should do the same.

.github/workflows/markdown-lint-fix.yml Show resolved Hide resolved
.github/workflows/markdown-lint-fix.yml Outdated Show resolved Hide resolved
.github/workflows/markdown-lint-fix.yml Show resolved Hide resolved
.github/workflows/markdown-lint-fix.yml Outdated Show resolved Hide resolved
.github/workflows/markdown-lint-fix.yml Show resolved Hide resolved
Comment on lines 31 to 38
commit-message: "chore: auto-fix Markdownlint issues"
branch: daily-markdownlint-fix
title: "Daily Markdownlint auto-cleanup"
body: |
No unfixable issues found
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to use @mdn-bot as author (though committer is not quite correct), but the default (GitHub <[email protected]>) wouldn't hurt either.

@caugner
Copy link
Contributor

caugner commented Aug 24, 2022

What should happen the next day if we fail to merge the PR within 24 hours? Create a brand new PR? or Append to the existing one?

Quote from https://github.com/peter-evans/create-pull-request#action-behaviour:

If a pull request already exists it will be updated if necessary. Local changes in the Actions workspace, or changes on the base branch, can cause an update. If no update is required the action exits silently.

@nschonni
Copy link
Contributor Author

I've added the MDN-bot as the committer rather than the author. That way the author of the PR will remain the bot if it's triggered by the cron job, but the user if it's manually triggered by a member to generate the PR ad-hoc

@nschonni nschonni requested a review from caugner August 24, 2022 18:45
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can play with this

@Josh-Cena Josh-Cena mentioned this pull request Aug 25, 2022
@teoli2003
Copy link
Contributor

Yes, let's try this.

@nschonni nschonni force-pushed the markdownlint-autofix branch 2 times, most recently from ca64f21 to c981724 Compare August 26, 2022 22:02
@nschonni
Copy link
Contributor Author

@caugner you still have a blocking review on this

@teoli2003
Copy link
Contributor

Is anything blocking this? (I would prefer to merge this near the beginning of the week rather than close to the weekend)

@Josh-Cena
Copy link
Member

None, just waiting on @caugner to re-review

yarn cache

chore: use mdn-bot as author

chore: update PR titles and branch
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one last suggestion to link directly to the log of the action run.

.github/workflows/markdown-lint-fix.yml Outdated Show resolved Hide resolved
@nschonni nschonni mentioned this pull request Sep 7, 2022
@teoli2003 teoli2003 merged commit ada64d8 into mdn:main Sep 7, 2022
@nschonni nschonni deleted the markdownlint-autofix branch September 7, 2022 03:36
himanshugarg pushed a commit to himanshugarg/content that referenced this pull request Sep 27, 2022
* chore: Add Markdownlint cleanup job

yarn cache

chore: use mdn-bot as author

chore: update PR titles and branch

* chore: add direct link to failing job

Co-authored-by: Claas Augner <[email protected]>

Co-authored-by: Claas Augner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra Infrastructure issues (npm, GitHub Actions, linting) for this repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants