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

New "vNext" update script using dependabot-core updater; aligns update behaviour more closely with the GitHub Dependabot service #1186

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
05decbd
Git ignore javascript build artifacts for extension project
Jul 3, 2024
3e04629
Move updater support scripts to lib directory
Jul 3, 2024
b64de41
Move WORKAROUND_CMD to final step before Dependabot is started and up…
Jul 3, 2024
facb671
Add documentation for Dependabot job environment variables
Jul 3, 2024
090e137
Add a basic developer guide for working with the updater project
Jul 3, 2024
7b5972a
Very rough proof-of-concept of update script with support for depende…
Jul 3, 2024
7d5f52d
Merge commit '4fc47639abc6509e749c1e4ddfca1cb6459ebf99' into feature/…
Jul 6, 2024
907abb3
Resolve merge conflicts
Jul 6, 2024
8d9274b
Fix spelling
Jul 6, 2024
b263be0
Fix linting
Jul 6, 2024
51b5847
Bump dependabot-omnibus from 0.263.0 to 0.264.0
Jul 7, 2024
acb1631
Remove default run scripts, they won't work and serve no purpose in t…
Jul 8, 2024
cc795aa
Update environment variables documentation
Jul 8, 2024
55a3875
Pull latest updater code from dependabot-core
Jul 8, 2024
d40e303
update_script_vnext checkpoint
Jul 8, 2024
dca27e1
Use new setup script in update_script.rb
Jul 8, 2024
c1acc4e
Merge commit '052bc005178a1f68b20f7262b914462dfaa006eb' into feature/…
Jul 8, 2024
1e7e4f9
Add documentation
Jul 8, 2024
cf50665
Checkpoint; PRs are now pushed to DevOps
Jul 8, 2024
d37b95d
Pull latest updater code from dependabot-core
Jul 8, 2024
b009293
Remove default run scripts, they won't work and serve no purpose in t…
Jul 8, 2024
0f6185d
Remove usused files
Jul 8, 2024
94080ea
Update Gemfile
Jul 9, 2024
92fa03f
Checkpoint
Jul 9, 2024
7f9f42d
Checkpoint
Jul 10, 2024
5601098
Checkpoint; Security advisories now working
Jul 10, 2024
245dccf
Checkpoint; Vulnerabilities fixed now working
Jul 10, 2024
7ab5bc7
Checkpoint
Jul 10, 2024
e2566be
Revert "Pull latest updater code from dependabot-core"
Jul 11, 2024
702899a
Pull latest updater code from dependabot-core
Jul 11, 2024
1d40270
Pull latest updater code from dependabot-core
Jul 11, 2024
979567c
Merge remote-tracking branch 'origin/HEAD' into feature/multi-directo…
Jul 11, 2024
81d12db
Merge branch 'feature/update-dependabot-core-updater' into feature/mu…
Jul 11, 2024
08e2c75
Fix linting
Jul 11, 2024
926dec9
Fix linting
Jul 11, 2024
42b9ce9
Remove redundant code
Jul 11, 2024
7469736
Checkpoint; Fix experiments and requirements update strategy options
Jul 11, 2024
59f82e4
Merge commit 'bd27951eba7307b5a5cd94224e96259123541763' into feature/…
Jul 11, 2024
45824ff
Revert changes
Jul 11, 2024
e16aa8a
Revert changes
Jul 11, 2024
62ea054
Revert changes
Jul 11, 2024
ded3029
Checkpoint; More environment variable updates
Jul 11, 2024
7d422af
Merge commit '424e9bc43cb9f2115b4b0b528ed9730d5b6690b3' into feature/…
Jul 11, 2024
ac379ee
Checkpoint; More environment variable updates; Existing pull requests…
Jul 12, 2024
a5ce016
Merge commit 'ef016ef67c22cf2a84230fe7dac52714144990b7' into feature/…
Jul 12, 2024
eb7f280
Fix linting
Jul 12, 2024
28456fe
Fix spelling
Jul 12, 2024
67cc0a3
Support for multiple directories
Jul 12, 2024
e63d890
Fix crash in error handling due to missing base_commit_sha definition
Jul 12, 2024
9929dc8
Support for updating existing pull requests
Jul 12, 2024
0ab4357
Merge commit '55350e9b94c015ee88d8a0d34d73bc5e3c629cec' into feature/…
Jul 12, 2024
4185ada
Supress linting
Jul 12, 2024
e26c04b
Bug fixes
Jul 12, 2024
6a088ff
Fix typo
Jul 12, 2024
7a40a19
Bug fix
Jul 12, 2024
608ef34
Add compatibility score badges
Jul 12, 2024
0279591
Fix directory parsing when "directories" is not specified
Jul 13, 2024
98e50d6
Checkpoint
Jul 13, 2024
b8f36ea
Fix closing PRs when dependency has been removed via 'allow' or 'igno…
Jul 13, 2024
191f04e
Fix linting
Jul 13, 2024
591f7c1
Fix updating PRs that aren't in conflict status; Update documentation
Jul 14, 2024
9056d7a
Code clean up and linting
Jul 14, 2024
9fdcfb4
Fix typos
Jul 14, 2024
935cb6e
Merge commit '5d401931364a4b1735b09e35de4f3c564bd6828a' into feature/…
Jul 14, 2024
8925973
Merge commit '182d606ea4b604becdaa741a0ca541950d9a5412' into feature/…
Jul 15, 2024
7087338
Fix auto-complete PR commit message length exceeded error; Improve er…
Jul 16, 2024
9076adf
Fix "NotImplemented" error when doing security updates only
Jul 16, 2024
3c5d031
Fix for "vulnerabilities fix" showing vulnerabilties that are uncd re…
Jul 16, 2024
7783160
Fix linting
Jul 16, 2024
b59f155
Fix for dependency group updates not correctly detecting existing gro…
Jul 16, 2024
d53c700
Restore fetch_files.rb and update_files.rb, used by the server component
Jul 16, 2024
ba696f4
Fix dependency group mapping from dependabot.yml config structure
Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 56 additions & 74 deletions docs/updater.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions updater/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.bundle/
/spec/examples.txt
/tmp/
/job/
40 changes: 40 additions & 0 deletions updater/bin/fetch_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# typed: strict
# frozen_string_literal: true

require "sorbet-runtime"

$LOAD_PATH.unshift(T.must(__dir__) + "/../lib")

$stdout.sync = true

require "dependabot/api_client"
require "dependabot/environment"
require "dependabot/service"
require "dependabot/setup"
require "dependabot/file_fetcher_command"
require "debug" if ENV["DEBUG"]

class UpdaterKilledError < StandardError; end

trap("TERM") do
puts "Received SIGTERM"
error = UpdaterKilledError.new("Updater process killed with SIGTERM")
tags = { "gh.dependabot_api.update_job.id": ENV.fetch("DEPENDABOT_JOB_ID", nil) }

api_client =
Dependabot::ApiClient.new(
Dependabot::Environment.api_url,
Dependabot::Environment.job_id,
Dependabot::Environment.job_token
)
Dependabot::Service.new(client: api_client).capture_exception(error: error, tags: tags)
exit
end

begin
RubyVM::YJIT.enable if Dependabot::Environment.job_id.to_i.even?

Dependabot::FileFetcherCommand.new.run
rescue Dependabot::RunFailure
exit 1
end
18 changes: 10 additions & 8 deletions updater/bin/run.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/bin/bash
set -e

# This is a WORKAROUND for https://github.com/ruby/resolv/issues/23
# see also https://github.com/tinglesoftware/dependabot-azure-devops/pull/369
# see also https://github.com/tinglesoftware/dependabot-azure-devops/pull/834
if [ -n "$WORKAROUND_CMD" ]; then
eval "$WORKAROUND_CMD"
fi

command="$1"
if [ -z "$command" ]; then
echo "usage: run [update_script]"
echo "usage: run [fetch_files|update_files|update_script|update_script_vnext]"
exit 1
fi

Expand All @@ -20,4 +13,13 @@ export HEX_CACERTS_PATH=/etc/ssl/certs/ca-certificates.crt
# Tell python to use the system-wide CA bundle
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

# This is a WORKAROUND for fixing various quirks that might exist within the container environment that we don't have much control over.
# see: https://github.com/ruby/resolv/issues/23 (Ruby)
# https://github.com/tinglesoftware/dependabot-azure-devops/pull/369 (Ruby)
# https://github.com/tinglesoftware/dependabot-azure-devops/pull/834 (Ruby)
# https://github.com/tinglesoftware/dependabot-azure-devops/issues/921#issuecomment-2162273558 (NuGet)
if [ -n "$WORKAROUND_CMD" ]; then
eval "$WORKAROUND_CMD"
fi

bundle exec ruby "bin/${command}.rb"
50 changes: 50 additions & 0 deletions updater/bin/update_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# typed: true
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__ + "/../lib")

$stdout.sync = true

require "dependabot/api_client"
require "dependabot/environment"
require "dependabot/service"
require "dependabot/setup"
require "dependabot/update_files_command"
require "debug" if ENV["DEBUG"]

flamegraph = ENV.fetch("FLAMEGRAPH", nil)
if flamegraph
require "stackprof"
require "flamegraph"
end

class UpdaterKilledError < StandardError; end

trap("TERM") do
puts "Received SIGTERM"
error = UpdaterKilledError.new("Updater process killed with SIGTERM")
tags = { "gh.dependabot_api.update_job.id": ENV.fetch("DEPENDABOT_JOB_ID", nil) }

api_client =
Dependabot::ApiClient.new(
Dependabot::Environment.api_url,
Dependabot::Environment.job_id,
Dependabot::Environment.job_token
)
Dependabot::Service.new(client: api_client).capture_exception(error: error, tags: tags)
exit
end

begin
RubyVM::YJIT.enable if Dependabot::Environment.job_id.to_i.even?

if flamegraph
Flamegraph.generate("/tmp/dependabot-flamegraph.html") do
Dependabot::UpdateFilesCommand.new.run
end
else
Dependabot::UpdateFilesCommand.new.run
end
rescue Dependabot::RunFailure
exit 1
end
4 changes: 2 additions & 2 deletions updater/bin/update_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def show_diff(original_file, updated_file)
)
user_id = azure_client.get_user_id
target_branch_name = $options[:branch] || azure_client.fetch_default_branch($source.repo)
active_pull_requests = azure_client.pull_requests_active(user_id, target_branch_name)
active_pull_requests = azure_client.pull_requests_active_for_user_and_targeting_branch(user_id, target_branch_name)

pull_requests_count = 0

Expand Down Expand Up @@ -920,7 +920,7 @@ def show_diff(original_file, updated_file)
# look for pull requests that are no longer needed to be abandoned
if $options[:close_unwanted]
puts "Looking for pull requests that are no longer needed."
active_pull_requests = azure_client.pull_requests_active(user_id, target_branch_name)
active_pull_requests = azure_client.pull_requests_active_for_user_and_targeting_branch(user_id, target_branch_name)
active_pull_requests.each do |pr|
pr_id = pr["pullRequestId"]
title = pr["title"]
Expand Down
29 changes: 29 additions & 0 deletions updater/bin/update_script_vnext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# typed: strict
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__ + "/../lib")

# Ensure logs are output immediately. Useful when running in certain hosts like ContainerGroups
$stdout.sync = true

require "tinglesoftware/dependabot/setup"
require "tinglesoftware/dependabot/job"
require "tinglesoftware/dependabot/commands/update_all_dependencies_synchronous_command"

ENV["UPDATER_ONE_CONTAINER"] = "true" # The full end-to-end update will happen in a single container
ENV["UPDATER_DETERMINISTIC"] = "true" # The list of dependencies to update will be consistent across multiple runs

begin
TingleSoftware::Dependabot::Commands::UpdateAllDependenciesSynchronousCommand.new(
job: TingleSoftware::Dependabot::Job.new(
# Override Dependabot updater options (feature flags) required by this job
experiments: {
# Required for correctly detecting existing PRs when refreshing group dependency updates.
# Without this, Dependabot::DependencyGroup.matches_existing_pr? will always return false for group updates.
"dependency_has_directory" => true
}
)
).run
rescue ::Dependabot::RunFailure
exit 1
end
Loading