-
Notifications
You must be signed in to change notification settings - Fork 1k
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 updating GitHub actions to major tags that are branches #5963
Merged
deivid-rodriguez
merged 4 commits into
main
from
deivid-rodriguez/fix-bumping-actions-pinned-to-branches-that-look-like-tags
Nov 17, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02c35dc
Reuse `version_tag?` helper method
deivid-rodriguez 06debc9
Move some common logic around
deivid-rodriguez 57e1eac
Fix actions pinned to branches not being bumped
deivid-rodriguez 181abaf
Limit change in `GitCommitChecker#pinned?` to Actions
deivid-rodriguez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,15 @@ class GitCommitChecker | |
|
||
def initialize(dependency:, credentials:, | ||
ignored_versions: [], raise_on_ignored: false, | ||
requirement_class: nil, version_class: nil) | ||
requirement_class: nil, version_class: nil, | ||
consider_version_branches_pinned: false) | ||
@dependency = dependency | ||
@credentials = credentials | ||
@ignored_versions = ignored_versions | ||
@raise_on_ignored = raise_on_ignored | ||
@requirement_class = requirement_class | ||
@version_class = version_class | ||
@consider_version_branches_pinned = consider_version_branches_pinned | ||
end | ||
|
||
def git_dependency? | ||
|
@@ -52,17 +54,17 @@ def pinned? | |
# If the specified `ref` is actually a tag, we're pinned | ||
return true if local_upload_pack.match?(%r{ refs/tags/#{ref}$}) | ||
|
||
# If the specified `ref` is actually a branch, we're NOT pinned | ||
return false if local_upload_pack.match?(%r{ refs/heads/#{ref}$}) | ||
# Assume we're pinned unless the specified `ref` is actually a branch | ||
return true unless local_upload_pack.match?(%r{ refs/heads/#{ref}$}) | ||
|
||
# Otherwise, assume we're pinned | ||
true | ||
# TODO: Research whether considering branches that look like versions pinned makes sense for all ecosystems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||
@consider_version_branches_pinned && version_tag?(ref) | ||
end | ||
|
||
def pinned_ref_looks_like_version? | ||
return false unless pinned? | ||
|
||
dependency_source_details.fetch(:ref).match?(VERSION_REGEX) | ||
version_tag?(dependency_source_details.fetch(:ref)) | ||
end | ||
|
||
def pinned_ref_looks_like_commit_sha? | ||
|
@@ -101,47 +103,23 @@ def head_commit_for_local_branch(name) | |
end | ||
|
||
def local_tag_for_latest_version_matching_existing_precision | ||
max_tag = max_version_tag_for_current_precision(allowed_version_tags) | ||
|
||
return unless max_tag | ||
|
||
to_local_tag(max_tag) | ||
max_local_tag_for_current_precision(allowed_version_tags) | ||
end | ||
|
||
def local_tag_for_latest_version | ||
max_tag = max_version_tag(allowed_version_tags) | ||
|
||
return unless max_tag | ||
|
||
to_local_tag(max_tag) | ||
def local_ref_for_latest_version_matching_existing_precision | ||
max_local_tag_for_current_precision(allowed_version_refs) | ||
end | ||
|
||
def max_version_tag(tags) | ||
tags. | ||
max_by do |t| | ||
version_from_tag(t) | ||
end | ||
end | ||
|
||
def max_version_tag_for_current_precision(tags) | ||
current_precision = precision(dependency.version) | ||
|
||
# Find the latest version with the same precision as the pinned version. | ||
max_version_tag(tags.select { |tag| precision(scan_version(tag.name)) == current_precision }) | ||
def local_tag_for_latest_version | ||
max_local_tag(allowed_version_tags) | ||
end | ||
|
||
def allowed_version_tags | ||
tags = | ||
local_tags. | ||
select { |t| version_tag?(t.name) && matches_existing_prefix?(t.name) } | ||
filtered = tags. | ||
reject { |t| tag_included_in_ignore_requirements?(t) } | ||
if @raise_on_ignored && filter_lower_versions(filtered).empty? && filter_lower_versions(tags).any? | ||
raise Dependabot::AllVersionsIgnored | ||
end | ||
allowed_versions(local_tags) | ||
end | ||
|
||
filtered. | ||
reject { |t| tag_is_prerelease?(t) && !wants_prerelease? } | ||
def allowed_version_refs | ||
allowed_versions(local_refs) | ||
end | ||
|
||
def current_version | ||
|
@@ -184,10 +162,37 @@ def git_repo_reachable? | |
|
||
attr_reader :dependency, :credentials, :ignored_versions | ||
|
||
def max_local_tag_for_current_precision(tags) | ||
current_precision = precision(dependency.version) | ||
|
||
# Find the latest version with the same precision as the pinned version. | ||
max_local_tag(tags.select { |tag| precision(scan_version(tag.name)) == current_precision }) | ||
end | ||
|
||
def max_local_tag(tags) | ||
max_version_tag = tags.max_by { |t| version_from_tag(t) } | ||
|
||
to_local_tag(max_version_tag) | ||
end | ||
|
||
def precision(version) | ||
version.split(".").length | ||
end | ||
|
||
def allowed_versions(local_tags) | ||
tags = | ||
local_tags. | ||
select { |t| version_tag?(t.name) && matches_existing_prefix?(t.name) } | ||
filtered = tags. | ||
reject { |t| tag_included_in_ignore_requirements?(t) } | ||
if @raise_on_ignored && filter_lower_versions(filtered).empty? && filter_lower_versions(tags).any? | ||
raise Dependabot::AllVersionsIgnored | ||
end | ||
|
||
filtered. | ||
reject { |t| tag_is_prerelease?(t) && !wants_prerelease? } | ||
end | ||
|
||
def pinned_ref_in_release?(version) | ||
raise "Not a git dependency!" unless git_dependency? | ||
|
||
|
@@ -226,9 +231,15 @@ def local_upload_pack | |
local_repo_git_metadata_fetcher.upload_pack | ||
end | ||
|
||
def local_refs | ||
handle_tag_prefix(local_repo_git_metadata_fetcher.refs_for_upload_pack) | ||
end | ||
|
||
def local_tags | ||
tags = local_repo_git_metadata_fetcher.tags | ||
handle_tag_prefix(local_repo_git_metadata_fetcher.tags_for_upload_pack) | ||
end | ||
|
||
def handle_tag_prefix(tags) | ||
if dependency_source_details&.fetch(:ref, nil)&.start_with?("tags/") | ||
tags = tags.map do |tag| | ||
tag.dup.tap { |t| t.name = "tags/#{tag.name}" } | ||
|
@@ -332,12 +343,14 @@ def matches_existing_prefix?(tag) | |
end | ||
|
||
def to_local_tag(tag) | ||
return unless tag | ||
|
||
version = version_from_tag(tag) | ||
{ | ||
tag: tag.name, | ||
version: version, | ||
commit_sha: tag.commit_sha, | ||
tag_sha: tag.tag_sha | ||
tag_sha: tag.ref_sha | ||
} | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach of parameterising this rather than overriding it 🥇