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

Add workflow job to deduplicate dependabot pull requests #14845

Closed
wants to merge 9 commits into from

Conversation

steverep
Copy link
Member

@steverep steverep commented Dec 20, 2022

Proposed change

Many dependabot pull request will fail the duplicates check in the CI workflow. This change automatically runs yarn dedupe on dependabot pull requests, makes a commit by the actions bot using the GITHUB_TOKEN for the workflow, and then continues the checks with the update.

Here are final successful test runs, and you can see the successful commits in the history of #14775.

Note that actions taken with the GITHUB_TOKEN never trigger new workflows, so this is designed as part of the current CI workflow and manually deals with the correct commit SHA to continue the CI. The alternative would be to make it a separate workflow that uses a PAT for the commit, but that obviously has security implications and also wastes resources because the CI will start and then be re-triggered shortly after.

Other minor changes:

  • Give jobs friendlier names for the UI
  • Use permissions: {} syntax for clarity
  • Remove unnecessary CI environment variable (this is automatically true for every workflow)

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@steverep steverep added the GitHub Actions Pull requests that update GitHub Actions code label Dec 20, 2022
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
@steverep
Copy link
Member Author

I assume the double CI checks that are pending are just a GitHub quirk that will correct itself after merging?

@steverep steverep added this to the 2023.2 milestone Jan 4, 2023
@steverep
Copy link
Member Author

@bramkragten what are your thoughts on this one? I've been committing the deduplications manually to keep the ball rolling, but would be nice to automate.

@ludeeus ludeeus self-requested a review January 23, 2023 19:13
@ludeeus ludeeus removed this from the 2023.2 milestone Jan 24, 2023
jobs:
dedupe:
Copy link
Member

Choose a reason for hiding this comment

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

Why is this even needed?
Why is this not solved by dependabot or even yarn?
I find it strange that every project that relies on dependabot would need some workaround like this?

This also breaks the auto rebase feature that dependabot does as it refuses to change a PR that someone else has messed with, which means that we would need to comment @dependabot recreate for all PRs.
This is not great from a resource perspective (we should also add concurrency with cancel to the CI workflow but that's a separate topic.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is this even needed? Why is this not solved by dependabot or even yarn?

Yarn certainly can't control what dependabot does, but yeah I totally agree dependabot should handle it. Hopefully this would be temporary. Here's the issue: dependabot/dependabot-core#5830

This also breaks the auto rebase feature that dependabot does as it refuses to change a PR that someone else has messed with, which means that we would need to comment @dependabot recreate for all PRs.

Yeah I agree, although not "all" PRs will need the deduplication step. Theoretically, there would be less and less commits required as dependencies are brought up to date.

This is not great from a resource perspective (we should also add concurrency with cancel to the CI workflow but that's a separate topic.)

I was going to add that but didn't want to go off-topic.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the direct need for it to run and push in this workflow at all.

We are trying to do all kinds of weird things to make this happen. IMHO we can just make this a maintenance task, or let a task run every day or week on a schedule to clean this up.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing CI checks for duplicates via yarn dedupe --check

Copy link
Member

Choose a reason for hiding this comment

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

If thats all that this is really for, we can just remove that check and do this as general maintenance and/or on a separate schedule?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that's wise. The check is run to minimize what packages get bundled and sent to the browser. Leaving duplicates can affect frontend results. It's not just maintenance.

Copy link
Member

Choose a reason for hiding this comment

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

If we make a separate action, that checks if a dedupe is needed and creates a PR if it is and run that daily, it might be an easier fix? Or even run it after a merge of a dependabot PR.

We can still have the dedupe check in CI for manual PRs and skip it for dependabot?

Copy link
Member Author

Choose a reason for hiding this comment

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

I personally wouldn't be a fan of that because you'd be degrading any validation and testing on the original bump, only to make more work for yourself on the subsequent deduplication. It would also be arguably more work than this change, especially to automate opening the PR.

I honestly didn't expect push back over "skipped" messages, but since this is getting no love, what's the problem with making a separate workflow (only to run on dependabot branches) and using a GitHub app to authenticate?

I could setup a new app and transfer ownership to HA (or use an existing bot?). Then use a 3rd party action like this one to authenticate and commit as the app. Someone above my pay grade just needs to add the credentials as secrets.

The only downside to that approach is that if the app commits, then CI runs twice and wastes resources.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's an example from a recent PR to support keeping the check (and moving it up before the others):

https://github.com/home-assistant/frontend/actions/runs/4022152029

The CI failed during the types check, but the actual problem was the imports getting mangled with a duplicate. Simply running the dedupe was the fix.

@steverep steverep marked this pull request as draft February 6, 2023 20:14
Comment on lines +32 to +33
app_id: ${{ secrets.HA_COMMITTER_APP_ID }}
private_key: ${{ secrets.HA_COMMITTER_PRIVATE_KEY }}
Copy link
Member Author

@steverep steverep Feb 6, 2023

Choose a reason for hiding this comment

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

@balloob I'm about to transfer ownership of a simple GH app with content permissions. Could you:

  1. Add a couple secrets for the App ID (not client ID) and private key with these names? You'll have to generate a new private key and delete the existing one.
  2. Install the app in the frontend repo?

@ludeeus ludeeus removed their request for review February 6, 2023 22:05
@steverep
Copy link
Member Author

steverep commented Feb 7, 2023

The revised version I pushed earlier now largely leaves the existing CI as is. It runs a separate workflow only on dependabot branches and only when dependabot pushes.

I have it as a draft until I can test the installed app authentication, but please feel free to review.

@@ -0,0 +1,54 @@
name: Deduplicate Dependabot
Copy link
Member

Choose a reason for hiding this comment

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

Even with this being split out in a separate workflow, I still do not think this is something we should add.

If this is an issue, that should be documented and reported to GitHub.
We should not add this level of workarounds, that to me, at least clearly show that something is wrong with how it works.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @ludeeus on this.

As an alternative could be: Don't use dependabot for this task.
An alternative could be, for example, Renovate. That is a competitor to dependabot that can actually dedupe (if configured as such).

../Frenck

Copy link
Member

Choose a reason for hiding this comment

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

Renovate seems like a nice option

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree Renovate is probably the better option for HA. In addition to being able to dedupe, it also handles monorepos much better, which has also been annoying from dependabot.

Closing this, but for posterity bringing it up to date and also added a simple change which addresses @ludeeus's concern about dependabot losing its rebase capability when committing the dedupe.

I'll submit a request to install Renovate and would be happy to work on the config PR.

@steverep steverep closed this Feb 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed GitHub Actions Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants