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

Do not run the 'dependency-submission' job in CI for forked repositories #720

Merged
merged 3 commits into from
Sep 5, 2024

Conversation

danicheg
Copy link
Member

This tries to fix the following issue in forked repositories:

[error] Unexpected status 404 Not Found with body:
[error] {"message":"The Dependency graph is disabled for this repository. Please enable it before submitting snapshots.","documentation_url":"https://docs.github.com/rest/dependency-graph/dependency-submission#create-a-snapshot-of-dependencies-for-a-repository","status":"404"}

Example: https://github.com/danicheg/cats/actions/runs/10027887278/job/27714122616#step:10:554

@danicheg
Copy link
Member Author

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks!

This is something I've thought about doing before. We have a similar problem not just with dependency submission but also with publishing: forks also attempt to publish even though their credentials are not setup correctly. So we should also consider fixing that in a similar way.

Although this solution works well for CI, the reason I've hesitated to implement it before is because it requires that the developer's local git repository is correctly configured with the upstream remote. Unfortunately, this does not happen automatically: if you fork a repo on GitHub and then git clone it locally, the upstream will not be configured and until you do so you will not be able to properly generate workflows.

Thoughts?

Comment on lines 148 to 149
"github.event_name != 'pull_request'"
)(repo => s"github.repository == '$repo' && github.event_name != 'pull_request'")
Copy link
Member

Choose a reason for hiding this comment

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

Let's move the event_name condition into a constant so we don't have to duplicate it?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, it makes sense 👍🏻

@danicheg
Copy link
Member Author

it requires that the developer's local git repository is correctly configured with the upstream remote. Unfortunately, this does not happen automatically: if you fork a repo on GitHub and then git clone it locally, the upstream will not be configured and until you do so you will not be able to properly generate workflows.

Oh, I see. Several thoughts:

  1. Because we have a CI check, the issue with the wrong Github Repository Owner will be clearly detected. So, a user might manually fix the issue (it's a one-time action) or configure the git repository properly to meet our requirements.
  2. We can have a distinct tlGitHubRepoOwner SBT setting. Users will have the ability to explicitly set it. Or it will be filled in via GitHelper#extractGitHubUserRepo.

@armanbilge
Copy link
Member

Thanks for thinking about it!

So, a user might manually fix the issue (it's a one-time action) or configure the git repository properly to meet our requirements.

Is this trade-off worth it?

I guess the question I'm wondering is, what is the harm of this failed CI job on forked repositories? We already have failed CI for publishing as well.

Also, if it really bothers users, why don't they take the "one-time action" to enable Dependency Graph for their repository? Wouldn't that solve the problem?

@danicheg
Copy link
Member Author

Also, if it really bothers users, why don't they take the "one-time action" to enable Dependency Graph for their repository? Wouldn't that solve the problem?

There seems to be some confusion when we talk about 'users.' From my perspective, a typical user of sbt-typelevel is a maintainer of an affiliate project. In 99% of cases, these users are the ones who set up CI workflows in their projects. We can reasonably expect them to have decent skills in a wide range of areas, such as setting up a local git repository. On the other hand, there are users of these affiliate projects. These users are more likely to focus on new features, bug fixing, and enhancing documentation in their typical contributions, rather than adjusting the CI workflow. However, these users might encounter confusion in their forks when running CI workflows. To sum up:
This work aims to improve the DX of contributors (by reducing the confusion caused by failing CI in their forks) of affiliate projects, rather than focusing on the maintainers of these projects. Let's be honest with ourselves, nowadays we can count them on one hand.

@armanbilge
Copy link
Member

armanbilge commented Jul 26, 2024

On the other hand, there are users of these affiliate projects. These users are more likely to focus on new features, bug fixing, and enhancing documentation in their typical contributions, rather than adjusting the CI workflow.

Ah yes, I see your point. I agree.

I do have one last idea, that would make workflow generation independent of the git repository configuration, by using a condition like this:

if: github.event.repository.fork == false

I think what we should do is serialize this as a setting e.g. tlCiForkCondition with that as the default value. In the unlikely situation that the primary repository is a fork (e.g. of some unmaintained upstream) then they can reconfigure it appropriately.

WDYT?

@danicheg
Copy link
Member Author

If you argue that this approach feels better, it's okay with me. I'd like to have that issue resolved, no matter the path we take.

@danicheg
Copy link
Member Author

@armanbilge by the way, If I understand things correctly, your suggested solution won't handle the case when the affiliate project is a fork. tlCiForkCondition is set to true, github.event.repository.fork would be computed as true for users' forks — and we'll get the run dependency-submission when it's unsolicited. Should we worry about this case? Perhaps you know better 🤷🏻 I'm not contributing to such projects within Typelevel.

@danicheg danicheg force-pushed the tweak-dependency-submission branch from 968d6ab to 6700973 Compare July 27, 2024 09:42
@mergify mergify bot added the docs label Jul 27, 2024
@armanbilge
Copy link
Member

armanbilge commented Jul 28, 2024

If I understand things correctly, your suggested solution won't handle the case when the affiliate project is a fork

By default, no, it would not handle that case. That is why I suggested we implement it as a configurable setting:

I think what we should do is serialize this as a setting e.g. tlCiForkCondition with that as the default value. In the unlikely situation that the primary repository is a fork (e.g. of some unmaintained upstream) then they can reconfigure it appropriately.

Repositories that are maintained as forks are very unusual/rare.

@danicheg
Copy link
Member Author

@armanbilge So, is there anything I need to address here to move on with this?

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Yes, sorry. I think your concern was legitimate, which is why I suggested we implement this as a setting #720 (comment).

@danicheg
Copy link
Member Author

Feeling dumb, but I altered the initial approach to align with your suggestions. So now we have a configurable setting with a reasonable default value 🤔

@armanbilge
Copy link
Member

So sorry, I think I didn't explain very well. What I mean is that we should have String setting tlCiForkCondition which has the default value github.event.repository.fork == false, but if necessary users can customize it to github.repository == '$repo'.

@danicheg
Copy link
Member Author

Returning to this...

What I mean is that we should have String setting tlCiForkCondition which has the default value github.event.repository.fork == false, but if necessary users can customize it to github.repository == '$repo'.

Wouldn't that tlCiForkCondition setting be somewhat of a leaky abstraction? I mean, it wouldn't just specify some behaviour of the underlying GitHub Action but would actually allow the injection of any YAML into the GitHub Action. I don't know if this is already the usual practice in the plugin, though.

@armanbilge
Copy link
Member

but would actually allow the injection of any YAML into the GitHub Action

Well, not any YAML, just a conditional expression. And we already accept an arbitrary string anyway.

Any plugin could always manipulate the gitHubWorkflowSteps setting and do arbitrary things to the conds.

@danicheg
Copy link
Member Author

Okay, as I said, any solution would work for me if it resolves the original request.

@danicheg danicheg changed the title Run the 'dependency-submission' job in CI only for the base repository Do not run the 'dependency-submission' job in CI for forked repositories Aug 24, 2024
@danicheg
Copy link
Member Author

@armanbilge hey Arman, what's up? Is there anything else I need to polish to move forward with this?

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Sorry, just got a bit behind :) this looks good, thanks for adjusting!

@armanbilge armanbilge merged commit b48f58e into typelevel:main Sep 5, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants