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

Added Cake support #1848

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"-v", "${localWorkspaceFolder}/bundler/Gemfile:/home/dependabot/dependabot-core/bundler/Gemfile",
"-v", "${localWorkspaceFolder}/bundler/lib:/home/dependabot/dependabot-core/bundler/lib",
"-v", "${localWorkspaceFolder}/bundler/spec:/home/dependabot/dependabot-core/bundler/spec",
"-v", "${localWorkspaceFolder}/cargo/dependabot-cargo.gemspec:/home/dependabot/dependabot-core/cargo/dependabot-cargo.gemspec",
"-v", "${localWorkspaceFolder}/cake/dependabot-cake.gemspec:/home/dependabot/dependabot-core/cake/dependabot-cake.gemspec",
"-v", "${localWorkspaceFolder}/cake/Gemfile:/home/dependabot/dependabot-core/cake/Gemfile",
"-v", "${localWorkspaceFolder}/cake/lib:/home/dependabot/dependabot-core/cake/lib",
"-v", "${localWorkspaceFolder}/cake/spec:/home/dependabot/dependabot-core/cake/spec",
"-v", "${localWorkspaceFolder}/cargo/dependabot-cargo.gemspec:/home/dependabot/dependabot-core/cargo/dependabot-core.gemspec",
"-v", "${localWorkspaceFolder}/cargo/Gemfile:/home/dependabot/dependabot-core/cargo/Gemfile",
"-v", "${localWorkspaceFolder}/cargo/lib:/home/dependabot/dependabot-core/cargo/lib",
"-v", "${localWorkspaceFolder}/cargo/spec:/home/dependabot/dependabot-core/cargo/spec",
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
suite:
- { path: bundler, name: bundler1 }
- { path: bundler, name: bundler2 }
- { path: cake, name: cake }
- { path: cargo, name: cargo }
- { path: common, name: common }
- { path: composer, name: composer }
Expand Down
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"description": "What type of package manager do you want to debug?",
"options": [
"bundler",
"cake",
"cargo",
"composer",
"dep",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY --chown=dependabot:dependabot docker ${CODE_DIR}/docker
COPY --chown=dependabot:dependabot nuget ${CODE_DIR}/nuget
COPY --chown=dependabot:dependabot maven ${CODE_DIR}/maven
COPY --chown=dependabot:dependabot gradle ${CODE_DIR}/gradle
COPY --chown=dependabot:dependabot cake ${CODE_DIR}/cake
COPY --chown=dependabot:dependabot cargo ${CODE_DIR}/cargo
COPY --chown=dependabot:dependabot composer ${CODE_DIR}/composer
COPY --chown=dependabot:dependabot go_modules ${CODE_DIR}/go_modules
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUN cd common \
&& bundle install

COPY --chown=dependabot:dependabot bundler/Gemfile bundler/dependabot-bundler.gemspec ${CODE_DIR}/bundler/
COPY --chown=dependabot:dependabot cake/Gemfile cake/dependabot-cake.gemspec ${CODE_DIR}/cake/
COPY --chown=dependabot:dependabot cargo/Gemfile cargo/dependabot-cargo.gemspec ${CODE_DIR}/cargo/
COPY --chown=dependabot:dependabot composer/Gemfile composer/dependabot-composer.gemspec ${CODE_DIR}/composer/
COPY --chown=dependabot:dependabot docker/Gemfile docker/dependabot-docker.gemspec ${CODE_DIR}/docker/
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GEMSPECS = %w(
git_submodules/dependabot-git_submodules.gemspec
github_actions/dependabot-github_actions.gemspec
nuget/dependabot-nuget.gemspec
cake/dependabot-cake.gemspec
gradle/dependabot-gradle.gemspec
maven/dependabot-maven.gemspec
bundler/dependabot-bundler.gemspec
Expand Down
6 changes: 4 additions & 2 deletions bin/docker-dev-shell
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ docker run --rm -ti \
-v "$(pwd)/nuget/dependabot-nuget.gemspec:$CODE_DIR/nuget/dependabot-nuget.gemspec" \
-v "$(pwd)/nuget/lib:$CODE_DIR/nuget/lib" \
-v "$(pwd)/nuget/spec:$CODE_DIR/nuget/spec" \
-v "$(pwd)/nuget/script:$CODE_DIR/nuget/script" \
-v "$(pwd)/maven/.rubocop.yml:$CODE_DIR/maven/.rubocop.yml" \
-v "$(pwd)/cake/Gemfile:$CODE_DIR/cake/Gemfile" \
-v "$(pwd)/cake/dependabot-cake.gemspec:$CODE_DIR/cake/dependabot-cake.gemspec" \
-v "$(pwd)/cake/lib:$CODE_DIR/cake/lib" \
-v "$(pwd)/cake/spec:$CODE_DIR/cake/spec" \
-v "$(pwd)/maven/Gemfile:$CODE_DIR/maven/Gemfile" \
-v "$(pwd)/maven/dependabot-maven.gemspec:$CODE_DIR/maven/dependabot-maven.gemspec" \
-v "$(pwd)/maven/lib:$CODE_DIR/maven/lib" \
Expand Down
3 changes: 3 additions & 0 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
# Package managers:
# - bundler
# - cake
# - pip (includes pipenv)
# - npm_and_yarn
# - maven
Expand Down Expand Up @@ -46,6 +47,7 @@
end

$LOAD_PATH << "./bundler/lib"
$LOAD_PATH << "./cake/lib"
$LOAD_PATH << "./cargo/lib"
$LOAD_PATH << "./common/lib"
$LOAD_PATH << "./composer/lib"
Expand Down Expand Up @@ -83,6 +85,7 @@
require "dependabot/config/file_fetcher"

require "dependabot/bundler"
require "dependabot/cake"
require "dependabot/cargo"
require "dependabot/composer"
require "dependabot/docker"
Expand Down
5 changes: 5 additions & 0 deletions cake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.bundle/
/.env
/tmp
/dependabot-*.gem
Gemfile.lock
8 changes: 8 additions & 0 deletions cake/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "dependabot-common", path: "../common"
gem "dependabot-nuget", path: "../nuget"

gemspec
17 changes: 17 additions & 0 deletions cake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## `dependabot-cake`

Cake support for [`dependabot-core`][core-repo].

### Running locally

1. Install Ruby dependencies
```
$ bundle install
```

2. Run tests
```
$ bundle exec rspec spec
```

[core-repo]: https://github.com/dependabot/dependabot-core
30 changes: 30 additions & 0 deletions cake/dependabot-cake.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
common_gemspec =
Bundler.load_gemspec_uncached("../common/dependabot-common.gemspec")

spec.name = "dependabot-cake"
spec.summary = ".NET (Cake) support for dependabot"
spec.version = common_gemspec.version
spec.description = common_gemspec.description

spec.author = common_gemspec.author
spec.email = common_gemspec.email
spec.homepage = common_gemspec.homepage
spec.license = common_gemspec.license

spec.require_path = "lib"
spec.files = Dir["lib/**/*"]

spec.add_dependency "inifile", "~> 3.0"

spec.required_ruby_version = common_gemspec.required_ruby_version
spec.required_rubygems_version = common_gemspec.required_ruby_version

spec.add_dependency "dependabot-common", Dependabot::VERSION

common_gemspec.development_dependencies.each do |dep|
spec.add_development_dependency dep.name, dep.requirement.to_s
end
end
18 changes: 18 additions & 0 deletions cake/lib/dependabot/cake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# These all need to be required so the various classes can be registered in a
# lookup table of package manager names to concrete classes.
require "dependabot/cake/file_fetcher"
require "dependabot/cake/file_parser"
require "dependabot/cake/update_checker"
require "dependabot/cake/file_updater"
require "dependabot/cake/metadata_finder"
require "dependabot/cake/version"
require "dependabot/cake/requirement"

require "dependabot/pull_request_creator/labeler"
Dependabot::PullRequestCreator::Labeler.
register_label_details("cake", name: "cake", colour: "7121c6")

require "dependabot/dependency"
Dependabot::Dependency.register_production_check("cake", ->(_) { true })
6 changes: 6 additions & 0 deletions cake/lib/dependabot/cake/directives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

require_relative "directives/addin_directive"
require_relative "directives/load_directive"
require_relative "directives/module_directive"
require_relative "directives/tool_directive"
27 changes: 27 additions & 0 deletions cake/lib/dependabot/cake/directives/addin_directive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative "directives"
require_relative "base_directive"

module Dependabot
module Cake
module Directives
class AddInDirective < Dependabot::Cake::Directives::BaseDirective
def initialize(line)
@type = "addin"
super(line)
end

private

def default_scheme
"nuget"
end
end
end
end
end

# rubocop:disable Layout/LineLength
Dependabot::Cake::Directives.register("addin", Dependabot::Cake::Directives::AddInDirective)
# rubocop:enable Layout/LineLength
57 changes: 57 additions & 0 deletions cake/lib/dependabot/cake/directives/base_directive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

require_relative "directives"

module Dependabot
module Cake
module Directives
class BaseDirective
SCHEME = /(?<scheme>[^:]{2,}:)/i.freeze
URL = /(?<url>[^?]+)?/.freeze
QUERY = /[?](?<query>.*)/.freeze
CONTEXT = /#{SCHEME}#{URL}#{QUERY}/.freeze

def initialize(line)
line = "#{default_scheme}:?path=#{line}" if line !~ SCHEME

parsed_from_line = CONTEXT.match(line).named_captures
@scheme = parsed_from_line.fetch("scheme").chomp(":")
@url = parsed_from_line.fetch("url")
@query = query_string_to_hash(parsed_from_line.fetch("query"))
end

def to_h
{
type: @type,
scheme: @scheme,
url: @url,
query: @query
}
end

attr_reader :type, :scheme, :url, :query

private

def default_scheme
raise NotImplementedError
end

def query_string_to_hash(query_string)
query_params = {}

# skip empty params
query_string&.split("&")&.each do |param|
next if param.empty?

name, value = param.split("=")
value ||= true

query_params[name.downcase.to_sym] = value
end
query_params
end
end
end
end
end
37 changes: 37 additions & 0 deletions cake/lib/dependabot/cake/directives/directives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module Dependabot
module Cake
module Directives
# Details of Cake preprocessor directives is at
# https://cakebuild.net/docs/fundamentals/preprocessor-directives
DIRECTIVE = /#(?<directive>addin|l|load|module|tool)/i.freeze
CONTEXT = /(?<context>[^"]+)/.freeze
DIRECTIVE_LINE = /^#{DIRECTIVE}\s+"?#{CONTEXT}"?/.freeze

@cake_directives = {}

def self.for_cake_directive(directive)
cake_directive = @cake_directives[directive.downcase]
return cake_directive if cake_directive

raise "Unsupported directive #{directive}"
end

def self.register(directive, cake_directive)
@cake_directives[directive.downcase] = cake_directive
end

def self.parse_cake_directive_from(line)
return nil unless Directives::DIRECTIVE_LINE.match?(line)

parsed_from_line = Directives::DIRECTIVE_LINE.match(line.chomp).
named_captures
directive = Directives.
for_cake_directive(parsed_from_line.fetch("directive")).
new(parsed_from_line.fetch("context"))
directive
end
end
end
end
28 changes: 28 additions & 0 deletions cake/lib/dependabot/cake/directives/load_directive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require_relative "directives"
require_relative "base_directive"

module Dependabot
module Cake
module Directives
class LoadDirective < Dependabot::Cake::Directives::BaseDirective
def initialize(line)
@type = "load"
super(line)
end

private

def default_scheme
"local"
end
end
end
end
end

# rubocop:disable Layout/LineLength
Dependabot::Cake::Directives.register("load", Dependabot::Cake::Directives::LoadDirective)
Dependabot::Cake::Directives.register("l", Dependabot::Cake::Directives::LoadDirective)
# rubocop:enable Layout/LineLength
27 changes: 27 additions & 0 deletions cake/lib/dependabot/cake/directives/module_directive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative "directives"
require_relative "base_directive"

module Dependabot
module Cake
module Directives
class ModuleDirective < Dependabot::Cake::Directives::BaseDirective
def initialize(line)
@type = "module"
super(line)
end

private

def default_scheme
"nuget"
end
end
end
end
end

# rubocop:disable Layout/LineLength
Dependabot::Cake::Directives.register("module", Dependabot::Cake::Directives::ModuleDirective)
# rubocop:enable Layout/LineLength
27 changes: 27 additions & 0 deletions cake/lib/dependabot/cake/directives/tool_directive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative "directives"
require_relative "base_directive"

module Dependabot
module Cake
module Directives
class ToolDirective < Dependabot::Cake::Directives::BaseDirective
def initialize(line)
@type = "tool"
super(line)
end

private

def default_scheme
"nuget"
end
end
end
end
end

# rubocop:disable Layout/LineLength
Dependabot::Cake::Directives.register("tool", Dependabot::Cake::Directives::ToolDirective)
# rubocop:enable Layout/LineLength
Loading