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

Fix GitHub actions updater crashing and cloning the wrong repository #6052

Merged
merged 4 commits into from
Nov 11, 2022

Conversation

deivid-rodriguez
Copy link
Contributor

This PR wants to fix two issues:

  • After Update version comments for SHA-pinned GitHub Actions #5951, we seem to have started using the GitCommitChecker#head_commit_for_current_branch method when dependency.version is an actual numbered version and not a ref. This is probably because with Update version comments for SHA-pinned GitHub Actions #5951 we have to deal with both numeric and ref versions in the same update. The current implementation of this method does not support this. I expect 90612fdda8a2471b66e78f341a649b013f6309a5 to fix this issue.

  • Even with the above fix, updates for pinned refs still don't work as expected and we either get a different crash or a downgrade. The reason for this seems to lie in Properly upgrade github actions pinned to specific commits #5576. In that PR, in order to be able to properly detect whether actions pinned to arbitrary references are out of date, we started cloning the whole repository. However, I think the implementation there was incorrect and it started cloning the repository being updated (the one that includes the workflow files), not the repository of the dependency being updated (the repository of the action itself). I expect 721bd2df6cdd8462ddb6b3ab0adfd76978487831 to fix this issue.

With this I get proper updates of repositories pinned to specific references.

Fixes #6014.
Fixes #6045.

@deivid-rodriguez
Copy link
Contributor Author

As a note, this does not happen in every repository with actions pinned to refs.

A classic situation when this does happen is:

  • Target repository has default branch named "master".
  • Action's repository has a default branch named "main", and also a branch named "master", more out of date. Due to the confusion in repo cloning explained above, Dependabot proposed to downgrade to the latest commit in the old "master" branch in this case.

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/fix-github-actions-crash branch 3 times, most recently from b0161a3 to dc66eea Compare November 4, 2022 16:08
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review November 4, 2022 16:26
@deivid-rodriguez deivid-rodriguez requested a review from a team as a code owner November 4, 2022 16:26
@deivid-rodriguez deivid-rodriguez marked this pull request as draft November 4, 2022 16:29
@deivid-rodriguez
Copy link
Contributor Author

I added some specs with VCR. My concern is whether these specs would start failing once more commits land in the sample repository, since these specs are actually cloning the repo to exercise the code changed here. I think no, because latest commit information is fetched from the git-upload-pack endpoint which is fixed as recorded by VCR. Cloning the repo is only to figure out the right branch to follow. But I'll fork the sample repo and try with my fork just to make sure.

Still these specs rely on cloning an external repo, which could get brittle. I'm not sure how to approach testing this otherwise. I thought of adding some smoke tests, but this particular situation needs the target repository and the repository where the updated action lives to be different repositories 🤔.

In general, I think this is good enough but I'm happy to hear more opinions.

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/fix-github-actions-crash branch from 2061651 to 95c6f95 Compare November 4, 2022 21:21
@deivid-rodriguez
Copy link
Contributor Author

I found and fixed one more issue where refs not tracking the default branch of an action were not being updated properly.

Also I added an optimization to not clone the action's repository if already pinned to the tip of a branch.

I think this should be good to go now.

@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review November 4, 2022 21:24
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/fix-github-actions-crash branch from 95c6f95 to 43a1234 Compare November 7, 2022 21:51
Since we're now able to bump both refs and versions (in comments) at the
same time, `dependency.version` may not always hold a ref now. So always
rely on metadata here.
After fixing the previous crash, I noticed that we were actually cloning
the _repository_ being updated (the one that includes the workflow
files), not the repository of the dependency being updated (the
repository of the action itself).

I have no idea how this somewhat seemed to work in some cases before.
The previous logic did not really work with shallow forks. In other for
all branches to be reachable, we need to clone the whole repository.
Also, unless we actually checkout the branches, we need to use `git
branch --remote --contains`.

There's still further work that could be done here, for example, to
disambiguate multiple branches including the commit by checking whether
one of them includes the others, and upgrade to the most recent in that
case. But that's for another time.
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/fix-github-actions-crash branch from 43a1234 to a17e9c9 Compare November 11, 2022 12:13
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review November 11, 2022 12:14
@deivid-rodriguez deivid-rodriguez merged commit 8cb8c55 into main Nov 11, 2022
@deivid-rodriguez deivid-rodriguez deleted the deivid-rodriguez/fix-github-actions-crash branch November 11, 2022 14:12
@pavera pavera mentioned this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants