-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version comments for SHA-pinned GitHub Actions
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.
- Loading branch information
Showing
4 changed files
with
138 additions
and
4 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,101 @@ | |
expect(subject.content).not_to include "actions/[email protected]\n" | ||
end | ||
end | ||
|
||
context "with pinned SHA hash and version in comment" do | ||
let(:service_pack_url) do | ||
"https://github.com/actions/checkout.git/info/refs" \ | ||
"?service=git-upload-pack" | ||
end | ||
before do | ||
stub_request(:get, service_pack_url). | ||
to_return( | ||
status: 200, | ||
body: fixture("git", "upload_packs", "checkout"), | ||
headers: { | ||
"content-type" => "application/x-git-upload-pack-advertisement" | ||
} | ||
) | ||
end | ||
|
||
let(:workflow_file_body) do | ||
fixture("workflow_files", "pinned_sources_version_comments.yml") | ||
end | ||
let(:dependency) do | ||
Dependabot::Dependency.new( | ||
name: "actions/checkout", | ||
version: "2.2.0", | ||
package_manager: "github_actions", | ||
previous_version: "2.1.0", | ||
previous_requirements: [{ | ||
requirement: nil, | ||
groups: [], | ||
file: ".github/workflows/workflow.yml", | ||
source: { | ||
type: "git", | ||
url: "https://github.com/actions/checkout", | ||
ref: "01aecccf739ca6ff86c0539fbc67a7a5007bbc81", | ||
branch: nil | ||
}, | ||
metadata: { declaration_string: "actions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81" } | ||
}, { | ||
requirement: nil, | ||
groups: [], | ||
file: ".github/workflows/workflow.yml", | ||
source: { | ||
type: "git", | ||
url: "https://github.com/actions/checkout", | ||
ref: "v2.1.0", | ||
branch: nil | ||
}, | ||
metadata: { declaration_string: "actions/[email protected]" } | ||
}], | ||
requirements: [{ | ||
requirement: nil, | ||
groups: [], | ||
file: ".github/workflows/workflow.yml", | ||
source: { | ||
type: "git", | ||
url: "https://github.com/actions/checkout", | ||
ref: "aabbfeb2ce60b5bd82389903509092c4648a9713", | ||
branch: nil | ||
}, | ||
metadata: { declaration_string: "actions/checkout@aabbfeb2ce60b5bd82389903509092c4648a9713" } | ||
}, { | ||
requirement: nil, | ||
groups: [], | ||
file: ".github/workflows/workflow.yml", | ||
source: { | ||
type: "git", | ||
url: "https://github.com/actions/checkout", | ||
ref: "v2.2.0", | ||
branch: nil | ||
}, | ||
metadata: { declaration_string: "actions/[email protected]" } | ||
}] | ||
) | ||
end | ||
|
||
it "updates SHA version" do | ||
old_sha = dependency.previous_requirements.first.dig(:source, :ref) | ||
expect(subject.content).to include "#{dependency.name}@#{dependency.requirements.first.dig(:source, :ref)}" | ||
expect(subject.content).not_to match(/#{old_sha}\s+#.*#{dependency.previous_version}/) | ||
end | ||
it "updates version comment" do | ||
new_sha = dependency.requirements.first.dig(:source, :ref) | ||
expect(subject.content).not_to match(/@#{new_sha}\s+#.*#{dependency.previous_version}/) | ||
|
||
expect(subject.content).to include "# v#{dependency.version}" | ||
expect(subject.content).to include "# #{dependency.version}" | ||
expect(subject.content).to include "# @v#{dependency.version}" | ||
expect(subject.content).to include "# pin @v#{dependency.version}" | ||
expect(subject.content).to include "# tag=v#{dependency.version}" | ||
end | ||
it "doesn't update version comments when @ref is not a SHA" do | ||
old_version = dependency.previous_requirements[1].dig(:source, :ref) | ||
expect(subject.content).not_to match(/@#{old_version}\s+#.*#{dependency.version}/) | ||
end | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
github_actions/spec/fixtures/workflow_files/pinned_sources_version_comments.yml
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 |
---|---|---|
@@ -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/[email protected] # 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. |