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

Update version comments for SHA-pinned GitHub Actions #1

Closed
wants to merge 1 commit into from

Conversation

jproberts
Copy link
Owner

GitHub advocates pinning third-party GitHub Actions to a full length commit SHA. In practice, it's common for actions pinned by commit SHA to include a comment which includes the version associated with the commit. For example:

- uses: actions/checkout@01aecc # v2.1.0

This change updates the GitHub Actions manager to bump versions in comments that follow SHA-pinned actions, so the comment stays up-to-date with the SHA being updated.

The file_updater now searches the comment string for all references to the previous version and replaces them with the new version. To avoid changing unrelated comments, the comment updater only updates dependencies that pin SHA refs.

@jproberts jproberts force-pushed the github-actions-update-semver-comments branch 2 times, most recently from 3c9fb06 to 1c6c9da Compare October 21, 2022 12:10
Copy link

@hmcginnis hmcginnis left a comment

Choose a reason for hiding this comment

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

These are mostly style suggestions. But the next weirds me out. The if style might satisfy what you expect

# 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(

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 of updated_content = updated_content.gsub. The ! mutates the original updated_content

)
/(?<=\W|"|')#{Regexp.escape(old_declaration)}(?<comment>\s+#.*)?(?=\s|"|'|$)/
) do |s|
comment = Regexp.last_match(:comment)

Choose a reason for hiding this comment

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

Something like this might also work

s.gsub!(old_declaration, new_declaration)
if (comment = Regexp.last_match(:comment))
  if (updated_comment = updated_version_comment(comment, new_req))
    s.gsub!(comment, updated_comment)
  end
end

Copy link
Owner Author

Choose a reason for hiding this comment

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

I got this suggestion working and I like it much better. Thanks!

@jproberts jproberts force-pushed the github-actions-update-semver-comments branch 2 times, most recently from 56737a2 to 5b57517 Compare October 22, 2022 12:40
GitHub encourages pinning third-party GitHub Actions to a full
length commit SHA. It's common for actions pinned by commit SHA
to include a comment specifying the version associated with the
commit. For example:

    - uses: actions/checkout@01aecc # v2.1.0

This change updates the GitHub Actions manager to bump versions
in comments that follow SHA-pinned actions, so the comment stays
up-to-date with the SHA being updated.

The file_updater now searches the comment string for all references
to the previous version and replaces them with the new version. To
avoid changing unrelated comments, the comment updater only
updates dependencies that pin SHA refs.
@jproberts jproberts force-pushed the github-actions-update-semver-comments branch from 5b57517 to 96b107c Compare October 22, 2022 12:50
@jproberts
Copy link
Owner Author

Moved to dependabot#5951 🎉

@jproberts jproberts closed this Oct 22, 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
Development

Successfully merging this pull request may close these issues.

2 participants