-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db8d3b7
commit 6716983
Showing
6 changed files
with
286 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
require "English" | ||
require "net/http" | ||
require "uri" | ||
require "json" | ||
require "rubygems/package" | ||
require "bundler" | ||
# require "./common/lib/dependabot/version" | ||
require "yaml" | ||
|
||
# GEMSPECS = %w( | ||
# common/dependabot-common.gemspec | ||
# go_modules/dependabot-go_modules.gemspec | ||
# terraform/dependabot-terraform.gemspec | ||
# docker/dependabot-docker.gemspec | ||
# git_submodules/dependabot-git_submodules.gemspec | ||
# github_actions/dependabot-github_actions.gemspec | ||
# nuget/dependabot-nuget.gemspec | ||
# gradle/dependabot-gradle.gemspec | ||
# maven/dependabot-maven.gemspec | ||
# bundler/dependabot-bundler.gemspec | ||
# elm/dependabot-elm.gemspec | ||
# cargo/dependabot-cargo.gemspec | ||
# npm_and_yarn/dependabot-npm_and_yarn.gemspec | ||
# composer/dependabot-composer.gemspec | ||
# hex/dependabot-hex.gemspec | ||
# python/dependabot-python.gemspec | ||
# pub/dependabot-pub.gemspec | ||
# omnibus/dependabot-omnibus.gemspec | ||
# ).freeze | ||
GEMSPECS = [] | ||
|
||
def run_command(command) | ||
puts "> #{command}" | ||
exit 1 unless system(command) | ||
end | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
namespace :gems do | ||
task build: :clean do | ||
root_path = Dir.getwd | ||
pkg_path = File.join(root_path, "pkg") | ||
Dir.mkdir(pkg_path) unless File.directory?(pkg_path) | ||
|
||
GEMSPECS.each do |gemspec_path| | ||
puts "> Building #{gemspec_path}" | ||
Dir.chdir(File.dirname(gemspec_path)) do | ||
gemspec = Bundler.load_gemspec_uncached(File.basename(gemspec_path)) | ||
pkg = ::Gem::Package.build(gemspec) | ||
FileUtils.mv(pkg, File.join(pkg_path, pkg)) | ||
end | ||
end | ||
end | ||
|
||
task release: [:build] do | ||
guard_tag_match | ||
|
||
GEMSPECS.each do |gemspec_path| | ||
gem_name = File.basename(gemspec_path).sub(/\.gemspec$/, "") | ||
gem_path = "pkg/#{gem_name}-#{Dependabot::VERSION}.gem" | ||
|
||
attempts = 0 | ||
loop do | ||
if rubygems_release_exists?(gem_name, Dependabot::VERSION) | ||
puts "- Skipping #{gem_path} as it already exists on rubygems" | ||
break | ||
else | ||
puts "> Releasing #{gem_path}" | ||
attempts += 1 | ||
sleep(2) | ||
begin | ||
sh "gem push #{gem_path}" | ||
break | ||
rescue StandardError => e | ||
puts "! `gem push` failed with error: #{e}" | ||
raise if attempts >= 3 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
task :clean do | ||
FileUtils.rm(Dir["pkg/*.gem"]) | ||
end | ||
end | ||
|
||
class Hash | ||
def sort_by_key(recursive = false, &block) | ||
keys.sort(&block).each_with_object({}) do |key, seed| | ||
seed[key] = self[key] | ||
seed[key] = seed[key].sort_by_key(true, &block) if recursive && seed[key].is_a?(Hash) | ||
seed | ||
end | ||
end | ||
end | ||
|
||
namespace :rubocop do | ||
task :sort do | ||
File.write( | ||
".rubocop.yml", | ||
YAML.load_file(".rubocop.yml").sort_by_key(true).to_yaml | ||
) | ||
end | ||
end | ||
|
||
def guard_tag_match | ||
tag = "v#{Dependabot::VERSION}" | ||
tag_commit = `git rev-list -n 1 #{tag} 2> /dev/null`.strip | ||
abort "Can't release - tag #{tag} does not exist" unless $CHILD_STATUS == 0 | ||
|
||
head_commit = `git rev-parse HEAD`.strip | ||
return if tag_commit == head_commit | ||
|
||
abort "Can't release - HEAD (#{head_commit[0..9]}) does not match " \ | ||
"tag #{tag} (#{tag_commit[0..9]})" | ||
end | ||
|
||
def rubygems_release_exists?(name, version) | ||
uri = URI.parse("https://rubygems.org/api/v1/versions/#{name}.json") | ||
response = Net::HTTP.get_response(uri) | ||
abort "Gem #{name} doesn't exist on rubygems" if response.code != "200" | ||
|
||
body = JSON.parse(response.body) | ||
existing_versions = body.map { |b| b["number"] } | ||
existing_versions.include?(version) | ||
end | ||
# rubocop:enable Metrics/BlockLength |
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 was deleted.
Oops, something went wrong.
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,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/logger" | ||
require "dependabot/python" | ||
require "dependabot/terraform" | ||
require "dependabot/elm" | ||
require "dependabot/docker" | ||
require "dependabot/git_submodules" | ||
require "dependabot/github_actions" | ||
require "dependabot/composer" | ||
require "dependabot/nuget" | ||
require "dependabot/gradle" | ||
require "dependabot/maven" | ||
require "dependabot/hex" | ||
require "dependabot/cargo" | ||
require "dependabot/go_modules" | ||
require "dependabot/npm_and_yarn" | ||
require "dependabot/bundler" | ||
require "dependabot/pub" | ||
require "logger" | ||
require "vcr" | ||
require "webmock/rspec" | ||
|
||
# TODO: Stop rescuing StandardError in Dependabot::BaseJob#run | ||
# | ||
# For now we log errors as these can surface exceptions that currently get rescued | ||
# in integration tests. | ||
# | ||
# This includes missing VCR fixtures. | ||
Dependabot.logger = Logger.new($stdout, level: Logger::ERROR) | ||
|
||
WebMock.disable_net_connect! | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
config.filter_run_when_matching :focus | ||
config.example_status_persistence_file_path = "spec/examples.txt" | ||
config.disable_monkey_patching! | ||
config.default_formatter = "doc" if config.files_to_run.one? | ||
config.profile_examples = 10 | ||
config.order = :random | ||
|
||
Kernel.srand config.seed | ||
|
||
def fixture(path) | ||
File.read(File.join("spec", "fixtures", path)) | ||
end | ||
end | ||
|
||
VCR.configure do |config| | ||
config.cassette_library_dir = "spec/fixtures/vcr_cassettes" | ||
config.hook_into :webmock | ||
config.configure_rspec_metadata! | ||
config.allow_http_connections_when_no_cassette = false | ||
|
||
config.filter_sensitive_data("<AZURE_ACCESS_TOKEN>") do | ||
ENV.fetch("AZURE_ACCESS_TOKEN", nil) | ||
end | ||
|
||
config.filter_sensitive_data("<AWS_ACCESS_KEY_ID>") do | ||
ENV.fetch("AWS_ACCESS_KEY_ID", nil) | ||
end | ||
|
||
config.filter_sensitive_data("<AWS_SECRET_ACCESS_KEY>") do | ||
ENV.fetch("AWS_SECRET_ACCESS_KEY", nil) | ||
end | ||
|
||
config.filter_sensitive_data("<AUTHORIZATION>") do |interaction| | ||
interaction.request.headers["Authorization"]&.first | ||
end | ||
|
||
# Prevent access tokens being written to VCR cassettes | ||
unless ENV["DEPENDABOT_TEST_ACCESS_TOKEN"].nil? | ||
config.filter_sensitive_data("<TOKEN>") do | ||
ENV["DEPENDABOT_TEST_ACCESS_TOKEN"] | ||
end | ||
end | ||
|
||
# Let's you set default VCR mode with VCR=all for re-recording | ||
# episodes. :once is VCR default | ||
record_mode = ENV["VCR"] ? ENV["VCR"].to_sym : :none | ||
config.default_cassette_options = { | ||
record: record_mode, | ||
allow_unused_http_interactions: false | ||
} | ||
end | ||
|
||
def test_access_token | ||
ENV.fetch("DEPENDABOT_TEST_ACCESS_TOKEN", "missing-test-access-token") | ||
end |