forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Update version comments for SHA-pinned GitHub Actions #1
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
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -65,17 +65,35 @@ def updated_workflow_file_content(file) | |
| gsub(/@.*+/, "@#{new_req.fetch(:source).fetch(:ref)}") | ||
|
|
||
| # Replace the old declaration that's preceded by a non-word character | ||
| # and followed by a whitespace character (comments) or EOL | ||
| # and followed by a whitespace character (comments) or EOL. | ||
| # If the declaration is followed by a comment, attempt to update | ||
| # any version comments associated with SHA source refs. | ||
| updated_content = | ||
| updated_content. | ||
| gsub( | ||
| /(?<=\W|"|')#{Regexp.escape(old_declaration)}(?=\s|"|'|$)/, | ||
| new_declaration | ||
| ) | ||
| /(?<=\W|"|')#{Regexp.escape(old_declaration)}(?<comment>\s+#.*)?(?=\s|"|'|$)/ | ||
| ) do |match| | ||
| comment = Regexp.last_match(:comment) | ||
|
||
| match.gsub!(old_declaration, new_declaration) | ||
| if comment && (updated_comment = updated_version_comment(comment, new_req)) | ||
| match.gsub!(comment, updated_comment) | ||
| end | ||
| match | ||
| end | ||
| end | ||
|
|
||
| updated_content | ||
| end | ||
|
|
||
| def updated_version_comment(comment, new_req) | ||
| raise "No comment!" unless comment | ||
| return unless dependency.previous_version && dependency.version | ||
|
|
||
| git_checker = Dependabot::GitCommitChecker.new(dependency: dependency, credentials: credentials) | ||
| return unless git_checker.ref_looks_like_commit_sha?(new_req.fetch(:source).fetch(:ref)) | ||
|
|
||
| comment.gsub(dependency.previous_version, dependency.version) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
github_actions/spec/fixtures/workflow_files/pinned_sources_version_comments.yml
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| on: [push] | ||
|
|
||
| name: Integration | ||
| jobs: | ||
| chore: | ||
| steps: | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # v2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # 2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # @v2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # pin @v2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # tag=v2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 # v2.1.0 | ||
| - uses: actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81 #v2.1.0 | ||
| - uses: actions/checkout@01aecc # v2.1.0 | ||
| integration: | ||
| - uses: actions/checkout@v2.1.0 # comments that include the version (v2.1.0) shouldn't be updated for non-SHA refs | ||
| - uses: actions/checkout@01aecc#v2.1.0 # this shouldn't be updated, because the version is part of the ref, not a comment. |
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.
you could use
updated_content.gsub!instead ofupdated_content = updated_content.gsub. The!mutates the originalupdated_content